Skip to content

Commit

Permalink
Added test for different varities of broken URL
Browse files Browse the repository at this point in the history
  • Loading branch information
shauns authored and alexanderMontague committed Feb 13, 2024
1 parent 5e2db99 commit d3daf82
Showing 1 changed file with 17 additions and 54 deletions.
71 changes: 17 additions & 54 deletions packages/app/src/cli/models/app/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 = {
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit d3daf82

Please sign in to comment.