mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-22 15:13:59 -06:00
Enhanced test covering list short URLs with invalid params
This commit is contained in:
parent
2abcaf02e2
commit
ff75b3cd1f
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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']];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user