Add tests covering country code validation

This commit is contained in:
Alejandro Celaya 2024-11-14 09:40:10 +01:00
parent fd34332e69
commit 7ddb3e7a70
2 changed files with 38 additions and 0 deletions

View File

@ -63,6 +63,18 @@ class RedirectRulesDataTest extends TestCase
],
],
]]])]
#[TestWith([['redirectRules' => [
[
'longUrl' => 'https://example.com',
'conditions' => [
[
'type' => 'geolocation-country-code',
'matchKey' => null,
'matchValue' => 'not an country code',
],
],
],
]]])]
public function throwsWhenProvidedDataIsInvalid(array $invalidData): void
{
$this->expectException(ValidationException::class);
@ -118,6 +130,18 @@ class RedirectRulesDataTest extends TestCase
],
],
]]], 'in-between IP wildcard pattern')]
#[TestWith([['redirectRules' => [
[
'longUrl' => 'https://example.com',
'conditions' => [
[
'type' => 'geolocation-country-code',
'matchKey' => null,
'matchValue' => 'US',
],
],
],
]]], 'country code')]
public function allowsValidDataToBeSet(array $validData): void
{
$result = RedirectRulesData::fromRawData($validData);

View File

@ -96,6 +96,20 @@ class SetRedirectRulesTest extends ApiTestCase
],
],
]], 'invalid IP address')]
#[TestWith([[
'redirectRules' => [
[
'longUrl' => 'https://example.com',
'conditions' => [
[
'type' => 'geolocation-country-code',
'matchKey' => null,
'matchValue' => 'not a country code',
],
],
],
],
]], 'invalid country code')]
public function errorIsReturnedWhenInvalidDataIsProvided(array $bodyPayload): void
{
$response = $this->callApiWithKey(self::METHOD_POST, '/short-urls/abc123/redirect-rules', [