From 7ddb3e7a70c901618f190809201eb413a5f177e8 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 14 Nov 2024 09:40:10 +0100 Subject: [PATCH] Add tests covering country code validation --- .../Model/RedirectRulesDataTest.php | 24 +++++++++++++++++++ .../test-api/Action/SetRedirectRulesTest.php | 14 +++++++++++ 2 files changed, 38 insertions(+) diff --git a/module/Core/test/RedirectRule/Model/RedirectRulesDataTest.php b/module/Core/test/RedirectRule/Model/RedirectRulesDataTest.php index e71140cb..d0186faa 100644 --- a/module/Core/test/RedirectRule/Model/RedirectRulesDataTest.php +++ b/module/Core/test/RedirectRule/Model/RedirectRulesDataTest.php @@ -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); diff --git a/module/Rest/test-api/Action/SetRedirectRulesTest.php b/module/Rest/test-api/Action/SetRedirectRulesTest.php index f096e411..6501ef13 100644 --- a/module/Rest/test-api/Action/SetRedirectRulesTest.php +++ b/module/Rest/test-api/Action/SetRedirectRulesTest.php @@ -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', [