From d3daf827681d2254ee318fd12411ff30b7d74b04 Mon Sep 17 00:00:00 2001 From: Shaun Stanworth Date: Fri, 9 Feb 2024 10:40:08 +0000 Subject: [PATCH] Added test for different varities of broken URL --- .../app/src/cli/models/app/loader.test.ts | 71 +++++-------------- 1 file changed, 17 insertions(+), 54 deletions(-) diff --git a/packages/app/src/cli/models/app/loader.test.ts b/packages/app/src/cli/models/app/loader.test.ts index 010b50df6e..2a9c4b602b 100644 --- a/packages/app/src/cli/models/app/loader.test.ts +++ b/packages/app/src/cli/models/app/loader.test.ts @@ -2339,26 +2339,6 @@ describe('parseConfigurationObject', () => { }) describe('WebhooksSchema', () => { - test('throws an error if uri is not an https uri', async () => { - const webhookConfig: WebhooksConfig = { - api_version: '2021-07', - subscriptions: [ - { - uri: 'http://example.com', - topics: ['products/create'], - }, - ], - } - const errorObj = { - code: zod.ZodIssueCode.custom, - message: 'Must be a valid https, pubsub, or ARN URI', - path: ['webhooks', 'subscriptions', 0, 'uri'], - } - - const {abortOrReport, expectedFormatted} = await setupParsing(errorObj, webhookConfig) - expect(abortOrReport).toHaveBeenCalledWith(expectedFormatted, {}, 'tmp', [errorObj]) - }) - test('removes trailing slashes on uri', async () => { const webhookConfig: WebhooksConfig = { api_version: '2021-07', @@ -2371,20 +2351,23 @@ describe('WebhooksSchema', () => { expect(parsedConfiguration.webhooks).toMatchObject(webhookConfig) }) - test('throws an error if uri is not a valid https URL, pubsub URI, or Eventbridge ARN', async () => { - const webhookConfig: WebhooksConfig = { - api_version: '2021-07', - subscriptions: [{uri: 'my::URI-thing::Shopify::123', topics: ['products/create']}], - } - const errorObj = { - code: zod.ZodIssueCode.custom, - message: 'Must be a valid https, pubsub, or ARN URI', - path: ['webhooks', 'subscriptions', 0, 'uri'], - } - - const {abortOrReport, expectedFormatted} = await setupParsing(errorObj, webhookConfig) - expect(abortOrReport).toHaveBeenCalledWith(expectedFormatted, {}, 'tmp', [errorObj]) - }) + test.each(['my::URI-thing::Shopify::123', 'no-leading-slash', 'http://not-using-https.com', 'https://broken-url'])( + 'throws an error for invalid URI %s', + async () => { + const webhookConfig: WebhooksConfig = { + api_version: '2021-07', + subscriptions: [{uri: 'my::URI-thing::Shopify::123', topics: ['products/create']}], + } + const errorObj = { + code: zod.ZodIssueCode.custom, + message: 'Must be a valid https, pubsub, or ARN URI', + path: ['webhooks', 'subscriptions', 0, 'uri'], + } + + const {abortOrReport, expectedFormatted} = await setupParsing(errorObj, webhookConfig) + expect(abortOrReport).toHaveBeenCalledWith(expectedFormatted, {}, 'tmp', [errorObj]) + }, + ) test('accepts an https uri', async () => { const webhookConfig: WebhooksConfig = { @@ -2538,26 +2521,6 @@ describe('WebhooksSchema', () => { expect(parsedConfiguration.webhooks).toMatchObject(webhookConfig) }) - test('throws an error if uri is not an https uri', async () => { - const webhookConfig: WebhooksConfig = { - api_version: '2021-07', - subscriptions: [ - { - topics: ['products/create'], - uri: 'http://example.com', - }, - ], - } - const errorObj = { - code: zod.ZodIssueCode.custom, - message: 'Must be a valid https, pubsub, or ARN URI', - path: ['webhooks', 'subscriptions', 0, 'uri'], - } - - const {abortOrReport, expectedFormatted} = await setupParsing(errorObj, webhookConfig) - expect(abortOrReport).toHaveBeenCalledWith(expectedFormatted, {}, 'tmp', [errorObj]) - }) - test('accepts a pub sub config with both project and topic', async () => { const webhookConfig: WebhooksConfig = { api_version: '2021-07',