diff --git a/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/base_payments_app_extension_schema.test.ts b/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/base_payments_app_extension_schema.test.ts index 08d90de2822..7e0fd15ef50 100644 --- a/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/base_payments_app_extension_schema.test.ts +++ b/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/base_payments_app_extension_schema.test.ts @@ -290,9 +290,43 @@ describe('SupportedBuyerContextSchema', async () => { ) }) + test('throws an error if an unexpected key is present', async () => { + expect(() => + SupportedBuyerContextsSchema.parse({ + supported_buyer_contexts: [{currency: 'USD', random: 123}], + }), + ).toThrowError( + new zod.ZodError([ + { + code: zod.ZodIssueCode.unrecognized_keys, + keys: ['random'], + path: ['supported_buyer_contexts', 0], + message: "Unrecognized key(s) in object: 'random'", + }, + ]), + ) + }) + + test('throws an error if a mixture of currency and currency plus countries provided', async () => { + expect(() => + SupportedBuyerContextsSchema.parse({ + supported_buyer_contexts: [{currency: 'USD'}, {currency: 'EUR', countries: ['DE']}], + }), + ).toThrowError( + new zod.ZodError([ + { + code: zod.ZodIssueCode.custom, + message: + 'Must all be defined with only a currency, or must all be defined with a currency plus countries -- a mixture of the two is not allowed', + path: ['supported_buyer_contexts'], + }, + ]), + ) + }) + test('is valid if countries are not provided', async () => { const {success} = SupportedBuyerContextsSchema.safeParse({ - supported_buyer_contexts: [{currency: 'USD'}], + supported_buyer_contexts: [{currency: 'USD'}, {currency: 'CAD'}], }) expect(success).toBe(true) @@ -300,7 +334,10 @@ describe('SupportedBuyerContextSchema', async () => { test('is valid if currrency and countries are provided', async () => { const {success} = SupportedBuyerContextsSchema.safeParse({ - supported_buyer_contexts: [{currency: 'USD', countries: ['US']}], + supported_buyer_contexts: [ + {currency: 'USD', countries: ['US']}, + {currency: 'EUR', countries: ['FR', 'DE']}, + ], }) expect(success).toBe(true) diff --git a/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/base_payments_app_extension_schema.ts b/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/base_payments_app_extension_schema.ts index ed2e19b3dfa..3394a210dd5 100644 --- a/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/base_payments_app_extension_schema.ts +++ b/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/base_payments_app_extension_schema.ts @@ -65,10 +65,23 @@ export const ConfirmationSchema = zod.object({ export const SupportedBuyerContextsSchema = zod.object({ supported_buyer_contexts: zod .array( - zod.object({ - currency: zod.string(), - countries: zod.array(zod.string()).nonempty().optional(), - }), + zod + .object({ + currency: zod.string(), + countries: zod.array(zod.string()).nonempty().optional(), + }) + .strict(), ) - .optional(), + .optional() + .refine( + (values) => { + return ( + values === undefined || values.every((value) => value.countries) || values.every((value) => !value.countries) + ) + }, + { + message: + 'Must all be defined with only a currency, or must all be defined with a currency plus countries -- a mixture of the two is not allowed', + }, + ), }) diff --git a/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/credit_card_payments_app_extension_schema.test.ts b/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/credit_card_payments_app_extension_schema.test.ts index 23531705dcc..b5f5e5867b3 100644 --- a/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/credit_card_payments_app_extension_schema.test.ts +++ b/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/credit_card_payments_app_extension_schema.test.ts @@ -20,11 +20,7 @@ const config: CreditCardPaymentsAppExtensionConfigType = { merchant_label: 'some-label', supported_countries: ['CA'], supported_payment_methods: ['PAYMENT_METHOD'], - supported_buyer_contexts: [ - {currency: 'USD'}, - {currency: 'CAD', countries: ['CA']}, - {currency: 'EUR', countries: ['DE', 'FR']}, - ], + supported_buyer_contexts: [{currency: 'USD'}, {currency: 'CAD'}], supports_3ds: false, test_mode_available: true, supports_deferred_payments: false, diff --git a/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/custom_credit_card_payments_app_extension_schema.test.ts b/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/custom_credit_card_payments_app_extension_schema.test.ts index e0931a71dcf..c74b3fa6a8f 100644 --- a/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/custom_credit_card_payments_app_extension_schema.test.ts +++ b/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/custom_credit_card_payments_app_extension_schema.test.ts @@ -21,7 +21,6 @@ const config: CustomCreditCardPaymentsAppExtensionConfigType = { supported_countries: ['CA'], supported_payment_methods: ['visa'], supported_buyer_contexts: [ - {currency: 'USD'}, {currency: 'CAD', countries: ['CA']}, {currency: 'EUR', countries: ['DE', 'FR']}, ], diff --git a/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/custom_onsite_payments_app_extension_schema.test.ts b/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/custom_onsite_payments_app_extension_schema.test.ts index ebe3d658113..d2c24ae617d 100644 --- a/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/custom_onsite_payments_app_extension_schema.test.ts +++ b/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/custom_onsite_payments_app_extension_schema.test.ts @@ -21,11 +21,7 @@ const config: CustomOnsitePaymentsAppExtensionConfigType = { merchant_label: 'some-label', supported_countries: ['CA'], supported_payment_methods: ['visa'], - supported_buyer_contexts: [ - {currency: 'USD'}, - {currency: 'CAD', countries: ['CA']}, - {currency: 'EUR', countries: ['DE', 'FR']}, - ], + supported_buyer_contexts: [{currency: 'EUR', countries: ['DE', 'FR']}], supports_oversell_protection: true, supports_3ds: true, supports_installments: true, diff --git a/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/offsite_payments_app_extension_schema.test.ts b/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/offsite_payments_app_extension_schema.test.ts index 5b11564afb4..9657924db19 100644 --- a/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/offsite_payments_app_extension_schema.test.ts +++ b/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/offsite_payments_app_extension_schema.test.ts @@ -17,11 +17,7 @@ const config: OffsitePaymentsAppExtensionConfigType = { merchant_label: 'some-label', supported_countries: ['CA'], supported_payment_methods: ['PAYMENT_METHOD'], - supported_buyer_contexts: [ - {currency: 'USD'}, - {currency: 'CAD', countries: ['CA']}, - {currency: 'EUR', countries: ['DE', 'FR']}, - ], + supported_buyer_contexts: [{currency: 'USD'}], supports_3ds: false, supports_oversell_protection: false, test_mode_available: true, diff --git a/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/redeemable_payments_app_extension_schema.test.ts b/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/redeemable_payments_app_extension_schema.test.ts index a923b042759..0901d9ee8ce 100644 --- a/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/redeemable_payments_app_extension_schema.test.ts +++ b/packages/app/src/cli/models/extensions/specifications/payments_app_extension_schemas/redeemable_payments_app_extension_schema.test.ts @@ -17,11 +17,7 @@ const config: RedeemablePaymentsAppExtensionConfigType = { merchant_label: 'some-label', supported_countries: ['CA'], supported_payment_methods: ['gift-card'], - supported_buyer_contexts: [ - {currency: 'USD'}, - {currency: 'CAD', countries: ['CA']}, - {currency: 'EUR', countries: ['DE', 'FR']}, - ], + supported_buyer_contexts: [{currency: 'CAD'}], test_mode_available: true, ui_extension_handle: 'sample-ui-extension', targeting: [{target: 'payments.redeemable.render'}],