Enhanced test covering list short URLs with invalid params

This commit is contained in:
Alejandro Celaya 2022-01-09 11:28:32 +01:00
parent 2abcaf02e2
commit ff75b3cd1f
2 changed files with 16 additions and 4 deletions

View File

@ -42,6 +42,9 @@ class ValidationException extends InvalidArgumentException implements ProblemDet
$e->invalidElements = $invalidData; $e->invalidElements = $invalidData;
$e->additional = ['invalidElements' => array_keys($invalidData)]; $e->additional = ['invalidElements' => array_keys($invalidData)];
// TODO Expose reasons for the validation to fail
// $e->additional = ['invalidElements' => array_keys($invalidData), 'reasons' => $invalidData];
return $e; return $e;
} }

View File

@ -242,20 +242,29 @@ class ListShortUrlsTest extends ApiTestCase
]; ];
} }
/** @test */ /**
public function errorIsReturnedWhenProvidingInvalidValues(): void * @test
* @dataProvider provideInvalidFiltering
*/
public function errorIsReturnedWhenProvidingInvalidValues(array $query, array $expectedInvalidElements): void
{ {
$query = ['tagsMode' => 'invalid'];
$resp = $this->callApiWithKey(self::METHOD_GET, '/short-urls', [RequestOptions::QUERY => $query]); $resp = $this->callApiWithKey(self::METHOD_GET, '/short-urls', [RequestOptions::QUERY => $query]);
$respPayload = $this->getJsonResponsePayload($resp); $respPayload = $this->getJsonResponsePayload($resp);
self::assertEquals(400, $resp->getStatusCode()); self::assertEquals(400, $resp->getStatusCode());
self::assertEquals([ self::assertEquals([
'invalidElements' => ['tagsMode'], 'invalidElements' => $expectedInvalidElements,
'title' => 'Invalid data', 'title' => 'Invalid data',
'type' => 'INVALID_ARGUMENT', 'type' => 'INVALID_ARGUMENT',
'status' => 400, 'status' => 400,
'detail' => 'Provided data is not valid', 'detail' => 'Provided data is not valid',
], $respPayload); ], $respPayload);
} }
public function provideInvalidFiltering(): iterable
{
yield [['tagsMode' => 'invalid'], ['tagsMode']];
yield [['orderBy' => 'invalid'], ['orderBy']];
yield [['orderBy' => 'invalid', 'tagsMode' => 'invalid'], ['tagsMode', 'orderBy']];
}
} }