diff --git a/tests/api/02-basic.ts b/tests/api/02-basic.ts index 1d33339..991f884 100644 --- a/tests/api/02-basic.ts +++ b/tests/api/02-basic.ts @@ -42,6 +42,37 @@ async function main() { log.detail('Source', response.source); }); + // Test 1.5: Validate storage path format + await runTest('Storage path format validation', async () => { + // Get uploaded image + const result = await api(`${endpoints.images}/${testContext.uploadedImageId}`); + const image = result.data.data; + + // Validate storageKey format: {orgSlug}/{projectSlug}/img/{uuid} + const keyRegex = /^[\w-]+\/[\w-]+\/img\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/; + if (!keyRegex.test(image.storageKey)) { + throw new Error(`Invalid storageKey format: ${image.storageKey}. Expected: {org}/{proj}/img/{uuid}`); + } + + // Validate storageUrl format: https://.../img/{uuid} + const urlRegex = /^https?:\/\/[^\/]+\/[\w-]+\/[\w-]+\/img\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/; + if (!urlRegex.test(image.storageUrl)) { + throw new Error(`Invalid storageUrl format: ${image.storageUrl}. Expected: https://.../img/{uuid}`); + } + + // Verify imageId matches the UUID in path + const pathParts = image.storageKey.split('/'); + const uuidFromPath = pathParts[3]; + if (uuidFromPath !== image.id) { + throw new Error(`storageKey UUID (${uuidFromPath}) doesn't match image.id (${image.id})`); + } + + log.detail('storageKey', image.storageKey); + log.detail('storageUrl', image.storageUrl); + log.detail('UUID in path = image.id', '✓'); + log.detail('Format', '{org}/{proj}/img/{uuid}'); + }); + // Test 2: Upload image without alias await runTest('Upload image without alias', async () => { const fixturePath = join(__dirname, config.fixturesDir, 'test-image.png'); diff --git a/tests/api/06-edge-cases.rest b/tests/api/06-edge-cases.rest index 28856f9..a4770bb 100644 --- a/tests/api/06-edge-cases.rest +++ b/tests/api/06-edge-cases.rest @@ -236,11 +236,12 @@ X-API-Key: {{apiKey}} ### Step 6.1: CDN image by path (if implemented) # @name cdnImage -GET {{base}}/api/v1/cdn/default/test-project/generated/2024-01/test.jpg +# New format: {org}/{project}/img/{uuid} +GET {{base}}/api/v1/cdn/default/test-project/img/00000000-0000-0000-0000-000000000000 X-API-Key: {{apiKey}} ### -# Note: Endpoint structure check only - actual paths depend on storage +# Note: Endpoint structure check only - uses placeholder UUID ### Step 6.2: Health check # @name healthCheck