diff --git a/packages/client/src/__tests__/__snapshots__/index.test.ts.snap b/packages/client/src/__tests__/__snapshots__/index.test.ts.snap index 524d5f1c0..5e2ff59ab 100644 --- a/packages/client/src/__tests__/__snapshots__/index.test.ts.snap +++ b/packages/client/src/__tests__/__snapshots__/index.test.ts.snap @@ -1139,6 +1139,7 @@ Object { "getOrderItemAvailableActivities": [Function], "getOrderReturnOptions": [Function], "getOrderShippingAddressChangeRequests": [Function], + "getPackagingOptions": [Function], "getPaymentIntent": [Function], "getPaymentIntentCharge": [Function], "getPaymentIntentInstrument": [Function], diff --git a/packages/client/src/checkout/__fixtures__/getPackagingOptions.fixtures.ts b/packages/client/src/checkout/__fixtures__/getPackagingOptions.fixtures.ts new file mode 100644 index 000000000..c6f3a6644 --- /dev/null +++ b/packages/client/src/checkout/__fixtures__/getPackagingOptions.fixtures.ts @@ -0,0 +1,17 @@ +import { rest, type RestHandler } from 'msw'; +import type { PackagingOption } from '../types/index.js'; + +const path = '/api/checkout/v1/packagingOptions'; + +const fixtures = { + success: (response: PackagingOption[]): RestHandler => + rest.get(path, (_req, res, ctx) => + res(ctx.status(200), ctx.json(response)), + ), + failure: (): RestHandler => + rest.get(path, (_req, res, ctx) => + res(ctx.status(404), ctx.json({ message: 'stub error' })), + ), +}; + +export default fixtures; diff --git a/packages/client/src/checkout/__tests__/__snapshots__/getPackagingOptions.test.ts.snap b/packages/client/src/checkout/__tests__/__snapshots__/getPackagingOptions.test.ts.snap new file mode 100644 index 000000000..021d3fc14 --- /dev/null +++ b/packages/client/src/checkout/__tests__/__snapshots__/getPackagingOptions.test.ts.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`checkout client getPackagingOptions should receive a client request error 1`] = ` +Object { + "code": "-1", + "message": "stub error", + "name": "AxiosError", + "status": 404, + "transportLayerErrorCode": "ERR_BAD_REQUEST", +} +`; diff --git a/packages/client/src/checkout/__tests__/getCheckoutOrderDetails.test.ts b/packages/client/src/checkout/__tests__/getCheckoutOrderDetails.test.ts index 5554abf01..142c923bf 100644 --- a/packages/client/src/checkout/__tests__/getCheckoutOrderDetails.test.ts +++ b/packages/client/src/checkout/__tests__/getCheckoutOrderDetails.test.ts @@ -350,6 +350,7 @@ describe('checkout client', () => { hadUnavailableItems: true, isGuestUser: true, shippingMode: ShippingMode.ByMerchant, + customerId: 123, }, shippingOptions: [ { diff --git a/packages/client/src/checkout/__tests__/getPackagingOptions.test.ts b/packages/client/src/checkout/__tests__/getPackagingOptions.test.ts new file mode 100644 index 000000000..04a45bcb0 --- /dev/null +++ b/packages/client/src/checkout/__tests__/getPackagingOptions.test.ts @@ -0,0 +1,38 @@ +import * as checkoutClient from '../index.js'; +import { mockPackagingOptionsResponse } from 'tests/__fixtures__/checkout/packagingOptions.fixtures.mjs'; +import { type PackagingOption } from '../types/index.js'; +import client from '../../helpers/client/index.js'; +import fixtures from '../__fixtures__/getPackagingOptions.fixtures.js'; +import mswServer from '../../../tests/mswServer.js'; + +describe('checkout client', () => { + const expectedConfig = undefined; + + beforeEach(() => jest.clearAllMocks()); + + describe('getPackagingOptions', () => { + const spy = jest.spyOn(client, 'get'); + const query = { channelCode: 'code' }; + const urlToBeCalled = `/checkout/v1/packagingOptions?channelCode=${query.channelCode}`; + + it('should handle a client request successfully', async () => { + const response: PackagingOption[] = mockPackagingOptionsResponse; + + mswServer.use(fixtures.success(response)); + + await expect( + checkoutClient.getPackagingOptions(query), + ).resolves.toStrictEqual(response); + expect(spy).toHaveBeenCalledWith(urlToBeCalled, expectedConfig); + }); + + it('should receive a client request error', async () => { + mswServer.use(fixtures.failure()); + + await expect( + checkoutClient.getPackagingOptions(query), + ).rejects.toMatchSnapshot(); + expect(spy).toHaveBeenCalledWith(urlToBeCalled, expectedConfig); + }); + }); +}); diff --git a/packages/client/src/checkout/getPackagingOptions.ts b/packages/client/src/checkout/getPackagingOptions.ts new file mode 100644 index 000000000..2f3187165 --- /dev/null +++ b/packages/client/src/checkout/getPackagingOptions.ts @@ -0,0 +1,22 @@ +import { adaptError } from '../helpers/client/formatError.js'; +import client from '../helpers/client/index.js'; +import join from 'proper-url-join'; +import type { GetPackagingOptions } from './types/index.js'; + +/** + * Method responsible for loading the packaging options. + * + * @param query - Query params. + * @param config - Custom configurations to send to the client instance (axios). + * + * @returns Promise that will resolve when the call to the endpoint finishes. + */ +const getPackagingOptions: GetPackagingOptions = (query, config) => + client + .get(join('/checkout/v1/packagingOptions', { query }), config) + .then(response => response.data) + .catch(error => { + throw adaptError(error); + }); + +export default getPackagingOptions; diff --git a/packages/client/src/checkout/index.ts b/packages/client/src/checkout/index.ts index be32ee7f2..2ee91f2b1 100644 --- a/packages/client/src/checkout/index.ts +++ b/packages/client/src/checkout/index.ts @@ -20,6 +20,7 @@ export { default as getCheckoutSession } from './getCheckoutSession.js'; export { default as getCheckoutSessionCharge } from './getCheckoutSessionCharge.js'; export { default as getCheckoutSessionTags } from './getCheckoutSessionTags.js'; export { default as getCollectPoints } from './getCollectPoints.js'; +export { default as getPackagingOptions } from './getPackagingOptions.js'; export { default as patchCheckoutOrder } from './patchCheckoutOrder.js'; export { default as patchCheckoutOrderDeliveryBundles } from './patchCheckoutOrderDeliveryBundles.js'; export { default as patchCheckoutOrderDeliveryBundleUpgrades } from './patchCheckoutOrderDeliveryBundleUpgrades.js'; diff --git a/packages/client/src/checkout/types/checkoutOrder.types.ts b/packages/client/src/checkout/types/checkoutOrder.types.ts index bf701aae4..54d3f64fd 100644 --- a/packages/client/src/checkout/types/checkoutOrder.types.ts +++ b/packages/client/src/checkout/types/checkoutOrder.types.ts @@ -5,6 +5,7 @@ import type { import type { CheckoutOrderItem, CheckoutOrderMerchant } from './index.js'; import type { CustomerTypeLegacy } from '../../orders/types/order.types.js'; import type { MerchantLocation } from '../../merchantsLocations/types/merchantLocation.types.js'; +import type { Metadata } from '../../types/index.js'; import type { PaymentIntent } from '../../payments/index.js'; import type { PromotionEvaluationId } from '../../promotionEvaluations/index.js'; @@ -78,4 +79,6 @@ export type CheckoutOrder = { shippingMode: ShippingMode; paymentIntentId?: PaymentIntent['id']; promotionEvaluationId?: PromotionEvaluationId; + customerId: number; + metadata?: Metadata; }; diff --git a/packages/client/src/checkout/types/checkoutOrderItem.types.ts b/packages/client/src/checkout/types/checkoutOrderItem.types.ts index c17e57913..b65085572 100644 --- a/packages/client/src/checkout/types/checkoutOrderItem.types.ts +++ b/packages/client/src/checkout/types/checkoutOrderItem.types.ts @@ -2,6 +2,7 @@ import type { Brand, CheckoutOrderItemStatus, Color, + Metadata, OrderItemCreationChannelLegacy, Price, Product, @@ -77,4 +78,5 @@ export type CheckoutOrderItem = { subTotalOriginalAmount: number; }; selectedSaleIntent?: SaleIntent & string; + metadata?: Metadata; }; diff --git a/packages/client/src/checkout/types/getPackagingOptions.types.ts b/packages/client/src/checkout/types/getPackagingOptions.types.ts new file mode 100644 index 000000000..e0ca1e0d3 --- /dev/null +++ b/packages/client/src/checkout/types/getPackagingOptions.types.ts @@ -0,0 +1,11 @@ +import type { Config } from '../../types/index.js'; +import type { PackagingOption } from './index.js'; + +export type GetPackagingOptionsQuery = { + channelCode: string; +}; + +export type GetPackagingOptions = ( + query?: GetPackagingOptionsQuery, + config?: Config, +) => Promise; diff --git a/packages/client/src/checkout/types/index.ts b/packages/client/src/checkout/types/index.ts index f0effd78e..67cc92a29 100644 --- a/packages/client/src/checkout/types/index.ts +++ b/packages/client/src/checkout/types/index.ts @@ -31,7 +31,9 @@ export * from './getCheckoutSession.types.js'; export * from './getCheckoutSessionCharge.types.js'; export * from './getCheckoutSessionTags.types.js'; export * from './getCollectPoints.types.js'; +export * from './getPackagingOptions.types.js'; export * from './itemDeliveryProvisioning.types.js'; +export * from './packagingOption.types.js'; export * from './patchCheckoutOrder.types.js'; export * from './patchCheckoutOrderDeliveryBundles.types.js'; export * from './patchCheckoutOrderDeliveryBundleUpgrades.types.js'; diff --git a/packages/client/src/checkout/types/packagingOption.types.ts b/packages/client/src/checkout/types/packagingOption.types.ts new file mode 100644 index 000000000..a47619c7d --- /dev/null +++ b/packages/client/src/checkout/types/packagingOption.types.ts @@ -0,0 +1 @@ +export type PackagingOption = string; diff --git a/packages/client/src/checkout/types/patchCheckoutOrder.types.ts b/packages/client/src/checkout/types/patchCheckoutOrder.types.ts index f84caa924..3eb875644 100644 --- a/packages/client/src/checkout/types/patchCheckoutOrder.types.ts +++ b/packages/client/src/checkout/types/patchCheckoutOrder.types.ts @@ -1,4 +1,4 @@ -import type { CheckoutAddress, Config } from '../../types/index.js'; +import type { CheckoutAddress, Config, Metadata } from '../../types/index.js'; import type { CheckoutOrder, CheckoutOrderShippingOption, @@ -18,6 +18,7 @@ export type PatchCheckoutOrderData = { shippingOption?: CheckoutOrderShippingOption; deliveryBundleUpdate?: CheckoutOrderDeliveryBundleUpdate; email?: string; + metadata?: Metadata; }; export type PatchCheckoutOrder = ( diff --git a/packages/client/src/checkout/types/postCheckoutOrder.types.ts b/packages/client/src/checkout/types/postCheckoutOrder.types.ts index d323655cd..132a53bdc 100644 --- a/packages/client/src/checkout/types/postCheckoutOrder.types.ts +++ b/packages/client/src/checkout/types/postCheckoutOrder.types.ts @@ -1,5 +1,5 @@ import type { Bag } from '../../bags/index.js'; -import type { Config } from '../../types/index.js'; +import type { Config, Metadata } from '../../types/index.js'; import type { GetCheckoutOrderResponse, ShippingMode } from './index.js'; import type { Product } from '../../products/types/index.js'; @@ -22,11 +22,13 @@ export type PostCheckoutOrderItem = { export type PostCheckoutOrderDataWithItems = PostCheckoutOrderData & { items: PostCheckoutOrderItem[]; + metadata?: Metadata; }; export type PostCheckoutOrderDataWithBag = PostCheckoutOrderData & { bagId: Bag['id']; removePurchasedItemsFromBag?: boolean; + metadata?: Metadata; }; export type PostCheckoutOrderDataWithDraftOrder = { diff --git a/packages/redux/src/checkout/actions/__tests__/__snapshots__/createCheckoutOrder.test.ts.snap b/packages/redux/src/checkout/actions/__tests__/__snapshots__/createCheckoutOrder.test.ts.snap index cee9f82a3..8fc143b46 100644 --- a/packages/redux/src/checkout/actions/__tests__/__snapshots__/createCheckoutOrder.test.ts.snap +++ b/packages/redux/src/checkout/actions/__tests__/__snapshots__/createCheckoutOrder.test.ts.snap @@ -293,6 +293,7 @@ Object { }, ], "currency": "EUR", + "customerId": 123, "customerType": 0, "formattedGrandTotal": "102 €", "formattedSubTotalAmount": "100 €", @@ -310,6 +311,7 @@ Object { 30380051, ], "locale": "en-US", + "metadata": Object {}, "orderId": "D7XM6Y", "paymentIntentId": "123", "shippingAddress": Object { diff --git a/packages/redux/src/checkout/actions/__tests__/__snapshots__/fetchCheckoutOrder.test.ts.snap b/packages/redux/src/checkout/actions/__tests__/__snapshots__/fetchCheckoutOrder.test.ts.snap index 7fa9691af..a01a419d7 100644 --- a/packages/redux/src/checkout/actions/__tests__/__snapshots__/fetchCheckoutOrder.test.ts.snap +++ b/packages/redux/src/checkout/actions/__tests__/__snapshots__/fetchCheckoutOrder.test.ts.snap @@ -293,6 +293,7 @@ Object { }, ], "currency": "EUR", + "customerId": 123, "customerType": 0, "formattedGrandTotal": "102 €", "formattedSubTotalAmount": "100 €", @@ -310,6 +311,7 @@ Object { 30380051, ], "locale": "en-US", + "metadata": Object {}, "orderId": "D7XM6Y", "paymentIntentId": "123", "shippingAddress": Object { diff --git a/packages/redux/src/checkout/actions/__tests__/__snapshots__/removeCheckoutOrderPromocodes.test.ts.snap b/packages/redux/src/checkout/actions/__tests__/__snapshots__/removeCheckoutOrderPromocodes.test.ts.snap index b8f9a43b1..4df8fd4cf 100644 --- a/packages/redux/src/checkout/actions/__tests__/__snapshots__/removeCheckoutOrderPromocodes.test.ts.snap +++ b/packages/redux/src/checkout/actions/__tests__/__snapshots__/removeCheckoutOrderPromocodes.test.ts.snap @@ -293,6 +293,7 @@ Object { }, ], "currency": "EUR", + "customerId": 123, "customerType": 0, "formattedGrandTotal": "102 €", "formattedSubTotalAmount": "100 €", @@ -310,6 +311,7 @@ Object { 30380051, ], "locale": "en-US", + "metadata": Object {}, "orderId": "D7XM6Y", "paymentIntentId": "123", "shippingAddress": Object { diff --git a/packages/redux/src/checkout/actions/__tests__/__snapshots__/setCheckoutOrderItemTags.test.ts.snap b/packages/redux/src/checkout/actions/__tests__/__snapshots__/setCheckoutOrderItemTags.test.ts.snap index 6dc7a4a9f..9419aa061 100644 --- a/packages/redux/src/checkout/actions/__tests__/__snapshots__/setCheckoutOrderItemTags.test.ts.snap +++ b/packages/redux/src/checkout/actions/__tests__/__snapshots__/setCheckoutOrderItemTags.test.ts.snap @@ -293,6 +293,7 @@ Object { }, ], "currency": "EUR", + "customerId": 123, "customerType": 0, "formattedGrandTotal": "102 €", "formattedSubTotalAmount": "100 €", @@ -310,6 +311,7 @@ Object { 30380051, ], "locale": "en-US", + "metadata": Object {}, "orderId": "D7XM6Y", "paymentIntentId": "123", "shippingAddress": Object { diff --git a/packages/redux/src/checkout/actions/__tests__/__snapshots__/setCheckoutOrderPromocodes.test.ts.snap b/packages/redux/src/checkout/actions/__tests__/__snapshots__/setCheckoutOrderPromocodes.test.ts.snap index 2c18cb130..206aeceea 100644 --- a/packages/redux/src/checkout/actions/__tests__/__snapshots__/setCheckoutOrderPromocodes.test.ts.snap +++ b/packages/redux/src/checkout/actions/__tests__/__snapshots__/setCheckoutOrderPromocodes.test.ts.snap @@ -293,6 +293,7 @@ Object { }, ], "currency": "EUR", + "customerId": 123, "customerType": 0, "formattedGrandTotal": "102 €", "formattedSubTotalAmount": "100 €", @@ -310,6 +311,7 @@ Object { 30380051, ], "locale": "en-US", + "metadata": Object {}, "orderId": "D7XM6Y", "paymentIntentId": "123", "promocode": "123", diff --git a/packages/redux/src/checkout/actions/__tests__/__snapshots__/setCheckoutOrderTags.test.ts.snap b/packages/redux/src/checkout/actions/__tests__/__snapshots__/setCheckoutOrderTags.test.ts.snap index fddbc3e7d..51d365a51 100644 --- a/packages/redux/src/checkout/actions/__tests__/__snapshots__/setCheckoutOrderTags.test.ts.snap +++ b/packages/redux/src/checkout/actions/__tests__/__snapshots__/setCheckoutOrderTags.test.ts.snap @@ -293,6 +293,7 @@ Object { }, ], "currency": "EUR", + "customerId": 123, "customerType": 0, "formattedGrandTotal": "102 €", "formattedSubTotalAmount": "100 €", @@ -310,6 +311,7 @@ Object { 30380051, ], "locale": "en-US", + "metadata": Object {}, "orderId": "D7XM6Y", "paymentIntentId": "123", "shippingAddress": Object { diff --git a/packages/redux/src/checkout/actions/__tests__/__snapshots__/updateCheckoutOrder.test.ts.snap b/packages/redux/src/checkout/actions/__tests__/__snapshots__/updateCheckoutOrder.test.ts.snap index 930230998..7cd155202 100644 --- a/packages/redux/src/checkout/actions/__tests__/__snapshots__/updateCheckoutOrder.test.ts.snap +++ b/packages/redux/src/checkout/actions/__tests__/__snapshots__/updateCheckoutOrder.test.ts.snap @@ -293,6 +293,7 @@ Object { }, ], "currency": "EUR", + "customerId": 123, "customerType": 0, "formattedGrandTotal": "102 €", "formattedSubTotalAmount": "100 €", @@ -310,6 +311,7 @@ Object { 30380051, ], "locale": "en-US", + "metadata": Object {}, "orderId": "D7XM6Y", "paymentIntentId": "123", "shippingAddress": Object { @@ -739,6 +741,7 @@ Object { }, ], "currency": "EUR", + "customerId": 123, "customerType": 0, "formattedGrandTotal": "102 €", "formattedSubTotalAmount": "100 €", @@ -756,6 +759,7 @@ Object { 30380051, ], "locale": "en-US", + "metadata": Object {}, "orderId": "D7XM6Y", "paymentIntentId": "123", "shippingAddress": Object { @@ -1185,6 +1189,7 @@ Object { }, ], "currency": "EUR", + "customerId": 123, "customerType": 0, "formattedGrandTotal": "102 €", "formattedSubTotalAmount": "100 €", @@ -1202,6 +1207,7 @@ Object { 30380051, ], "locale": "en-US", + "metadata": Object {}, "orderId": "D7XM6Y", "paymentIntentId": "123", "shippingAddress": Object { diff --git a/tests/__fixtures__/checkout/checkout.fixtures.mts b/tests/__fixtures__/checkout/checkout.fixtures.mts index b8f4376c7..2105d42c4 100644 --- a/tests/__fixtures__/checkout/checkout.fixtures.mts +++ b/tests/__fixtures__/checkout/checkout.fixtures.mts @@ -428,6 +428,8 @@ export const mockResponse = { isGuestUser: true, shippingMode: ShippingMode.ByMerchant, status: CheckoutOrderStatus.Opened, + metadata: {}, + customerId: 123, }, deliveryBundles: mockDeliveryBundlesResponse, shippingOptions: [], @@ -791,12 +793,6 @@ export const mockCheckoutDetailsEntity = { shippingOptions: [], }; -// export const checkoutOrderItemEntity = { -// id: checkoutOrderItemId, -// product: productId, -// tags: ['GIFT'], -// }; - export const mockCheckoutOrderItemEntity = { // Since a lot of properties are ommited for the CheckoutOrderItemEntity type, // we didn't spread the properties from the original mockCheckoutOrderItem (...mockCheckoutOrderItem) @@ -937,6 +933,8 @@ export const mockUpdateCheckoutResponse = { }, orderStatus: OrderStatusError.NoError, id: 123, + customerId: 123, + metadata: {}, }, }, }; diff --git a/tests/__fixtures__/checkout/index.mts b/tests/__fixtures__/checkout/index.mts index b3c368b39..78ef9b1cb 100644 --- a/tests/__fixtures__/checkout/index.mts +++ b/tests/__fixtures__/checkout/index.mts @@ -1,3 +1,4 @@ export * from './checkout.fixtures.mjs'; export * from './checkoutSessions.fixtures.mjs'; export * from './draftOrders.fixtures.mjs'; +export * from './packagingOptions.fixtures.mjs'; diff --git a/tests/__fixtures__/checkout/packagingOptions.fixtures.mts b/tests/__fixtures__/checkout/packagingOptions.fixtures.mts new file mode 100644 index 000000000..e28adcc0b --- /dev/null +++ b/tests/__fixtures__/checkout/packagingOptions.fixtures.mts @@ -0,0 +1,3 @@ +export const mockPackagingOption = 'Basic'; + +export const mockPackagingOptionsResponse = [mockPackagingOption, 'Signature'];