Add more tests for apiKeyName short URLs filtering

This commit is contained in:
Alejandro Celaya
2025-10-22 08:28:45 +02:00
parent 7860225c25
commit 9c22c7fc9c
3 changed files with 41 additions and 0 deletions

View File

@@ -156,6 +156,15 @@
"schema": {
"type": "string"
}
},
{
"name": "apiKeyName",
"in": "query",
"description": "Only get short URLs created with this API key.<br />This value is **ignored** if the request is performed with a non-admin API key that does not match this name.",
"required": false,
"schema": {
"type": "string"
}
}
],
"security": [

View File

@@ -209,6 +209,7 @@ class ListShortUrlsCommandTest extends TestCase
string|null $endDate = null,
array $excludeTags = [],
string $excludeTagsMode = TagsMode::ANY->value,
string|null $apiKeyName = null,
): void {
$this->shortUrlService->expects($this->once())->method('listShortUrls')->with(ShortUrlsParams::fromRawData([
'page' => $page,
@@ -219,6 +220,7 @@ class ListShortUrlsCommandTest extends TestCase
'endDate' => $endDate !== null ? Chronos::parse($endDate)->toAtomString() : null,
'excludeTags' => $excludeTags,
'excludeTagsMode' => $excludeTagsMode,
'apiKeyName' => $apiKeyName,
]))->willReturn(new Paginator(new ArrayAdapter([])));
$this->commandTester->setInputs(['n']);
@@ -275,6 +277,18 @@ class ListShortUrlsCommandTest extends TestCase
['foo', 'bar'],
TagsMode::ALL->value,
];
yield [
['--api-key-name' => 'foo'],
1,
null,
[],
TagsMode::ANY->value,
null,
null,
[],
TagsMode::ANY->value,
'foo',
];
}
#[Test, DataProvider('provideOrderBy')]

View File

@@ -297,6 +297,24 @@ class ListShortUrlsTest extends ApiTestCase
self::SHORT_URL_DOCS,
]];
// Filter by API key name
yield [['apiKeyName' => 'author_api_key'], [
self::SHORT_URL_CUSTOM_SLUG,
self::SHORT_URL_META,
self::SHORT_URL_SHLINK_WITH_TITLE,
]];
yield [['apiKeyName' => 'invalid'], []];
yield [['apiKeyName' => 'valid_api_key'], [
// If the author_api_key is used, the `apiKeyName` param is ignored
self::SHORT_URL_CUSTOM_SLUG,
self::SHORT_URL_META,
self::SHORT_URL_SHLINK_WITH_TITLE,
], 'author_api_key'];
yield [['apiKeyName' => 'valid_api_key'], [
// If the domain_api_key is used, the `apiKeyName` param is ignored
self::SHORT_URL_CUSTOM_DOMAIN,
], 'domain_api_key'];
// Different API keys
yield [[], [
self::SHORT_URL_CUSTOM_SLUG,