Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weekly release - dev-main-12-09-23 #866

Merged
merged 6 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,7 @@ Object {
"deleteToken": [Function],
"deleteUserAddress": [Function],
"deleteUserAttribute": [Function],
"deleteUserClosetItem": [Function],
"deleteUserContact": [Function],
"deleteUserDefaultContactAddress": [Function],
"deleteUserExternalLogin": [Function],
Expand All @@ -1056,6 +1057,7 @@ Object {
"getCheckoutOrderDeliveryBundleProvisioning": [Function],
"getCheckoutOrderDeliveryBundleUpgradeProvisioning": [Function],
"getCheckoutOrderDeliveryBundleUpgrades": [Function],
"getCheckoutOrderDeliveryBundles": [Function],
"getCheckoutOrderDetails": [Function],
"getCheckoutOrderOperation": [Function],
"getCheckoutOrderOperations": [Function],
Expand Down Expand Up @@ -1147,6 +1149,8 @@ Object {
"getUserAttribute": [Function],
"getUserAttributes": [Function],
"getUserBenefits": [Function],
"getUserClosetItems": [Function],
"getUserClosets": [Function],
"getUserContact": [Function],
"getUserContacts": [Function],
"getUserCreditBalance": [Function],
Expand All @@ -1170,6 +1174,7 @@ Object {
"patchBagItem": [Function],
"patchCheckoutOrder": [Function],
"patchCheckoutOrderDeliveryBundleUpgrades": [Function],
"patchCheckoutOrderDeliveryBundles": [Function],
"patchCheckoutOrderItem": [Function],
"patchCheckoutOrderItems": [Function],
"patchCheckoutSession": [Function],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { rest, type RestHandler } from 'msw';
import type { CheckoutOrderDeliveryBundle } from '../types/index.js';

const path = '/api/checkout/v1/orders/:id/deliveryBundles';

const fixtures = {
success: (response: CheckoutOrderDeliveryBundle[]): 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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { rest, type RestHandler } from 'msw';

const path = '/api/checkout/v1/orders/:id/deliveryBundles/:deliveryBundleId';

const fixtures = {
success: (): RestHandler =>
rest.patch(path, (_req, res, ctx) => res(ctx.status(204))),
failure: (): RestHandler =>
rest.patch(path, (_req, res, ctx) =>
res(ctx.status(404), ctx.json({ message: 'stub error' })),
),
};

export default fixtures;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`getCheckoutOrderDeliveryBundles should receive a client request error 1`] = `
Object {
"code": "-1",
"message": "stub error",
"name": "AxiosError",
"status": 404,
"transportLayerErrorCode": "ERR_BAD_REQUEST",
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`patchCheckoutOrderDeliveryBundles should receive a client request error 1`] = `
Object {
"code": "-1",
"message": "stub error",
"name": "AxiosError",
"status": 404,
"transportLayerErrorCode": "ERR_BAD_REQUEST",
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as checkoutClient from '../index.js';
import {
type CheckoutOrderDeliveryBundle,
CheckoutOrderDeliveryWindowType,
} from '../types/index.js';
import { id } from 'tests/__fixtures__/checkout/index.mjs';
import client from '../../helpers/client/index.js';
import fixtures from '../__fixtures__/getCheckoutOrderDeliveryBundles.fixtures.js';
import mswServer from '../../../tests/mswServer.js';

describe('getCheckoutOrderDeliveryBundles', () => {
const spy = jest.spyOn(client, 'get');
const expectedConfig = undefined;
const urlToBeCalled = `/checkout/v1/orders/${id}/deliveryBundles`;

beforeEach(() => jest.clearAllMocks());

it('should handle a client request successfully', async () => {
const response: CheckoutOrderDeliveryBundle[] = [
{
id: 'string',
name: 'string',
isSelected: true,
price: 0,
finalPrice: 0,
currency: 'string',
rank: 0,
itemsDeliveryOptions: [
{
itemId: 123,
name: 'string',
deliveryWindow: {
type: CheckoutOrderDeliveryWindowType.Nominated,
min: '2021-07-22T10:15:13.847Z',
max: '2021-07-22T10:15:13.847Z',
},
},
],
},
];

mswServer.use(fixtures.success(response));

await expect(
checkoutClient.getCheckoutOrderDeliveryBundles(id),
).resolves.toStrictEqual(response);
expect(spy).toHaveBeenCalledWith(urlToBeCalled, expectedConfig);
});

it('should receive a client request error', async () => {
mswServer.use(fixtures.failure());

await expect(
checkoutClient.getCheckoutOrderDeliveryBundles(id),
).rejects.toMatchSnapshot();
expect(spy).toHaveBeenCalledWith(urlToBeCalled, expectedConfig);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as checkoutClient from '../index.js';
import {
checkoutOrderId,
deliveryBundleId,
} from 'tests/__fixtures__/checkout/index.mjs';
import client from '../../helpers/client/index.js';
import fixtures from '../__fixtures__/patchCheckoutOrderDeliveryBundles.fixtures.js';
import mswServer from '../../../tests/mswServer.js';
import type { PatchCheckoutOrderDeliveryBundlesData } from '../types/index.js';

describe('patchCheckoutOrderDeliveryBundles', () => {
beforeEach(() => jest.clearAllMocks());

const spy = jest.spyOn(client, 'patch');
const expectedConfig = undefined;
const data: PatchCheckoutOrderDeliveryBundlesData = [
{
op: 'replace',
path: '/0/isSelected',
value: 'true',
},
];
const urlToBeCalled = `/checkout/v1/orders/${checkoutOrderId}/deliveryBundles/${deliveryBundleId}`;

it('should handle a client request successfully', async () => {
mswServer.use(fixtures.success());

await expect(
checkoutClient.patchCheckoutOrderDeliveryBundles(
checkoutOrderId,
deliveryBundleId,
data,
),
).resolves.toBe(204);
expect(spy).toHaveBeenCalledWith(urlToBeCalled, data, expectedConfig);
});

it('should receive a client request error', async () => {
mswServer.use(fixtures.failure());

await expect(
checkoutClient.patchCheckoutOrderDeliveryBundles(
checkoutOrderId,
deliveryBundleId,
data,
),
).rejects.toMatchSnapshot();
expect(spy).toHaveBeenCalledWith(urlToBeCalled, data, expectedConfig);
});
});
28 changes: 28 additions & 0 deletions packages/client/src/checkout/getCheckoutOrderDeliveryBundles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { adaptError } from '../helpers/client/formatError.js';
import client from '../helpers/client/index.js';
import urlJoin from 'proper-url-join';
import type { GetCheckoutOrderDeliveryBundles } from './types/index.js';

/**
* Obtains the delivery bundles available for the specified checkout order.
*
* @param checkoutOrderId - Identifier of the checkout order.
* @param config - Custom configurations to send to the client instance (axios).
*
* @returns Promise that will resolve when the call to the endpoint finishes.
*/
const getCheckoutOrderDeliveryBundles: GetCheckoutOrderDeliveryBundles = (
checkoutOrderId,
config,
) =>
client
.get(
urlJoin('/checkout/v1/orders/', checkoutOrderId, 'deliveryBundles'),
config,
)
.then(response => response.data)
.catch(error => {
throw adaptError(error);
});

export default getCheckoutOrderDeliveryBundles;
2 changes: 2 additions & 0 deletions packages/client/src/checkout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export { default as getCheckoutOrder } from './getCheckoutOrder.js';
export { default as getCheckoutOrderCharge } from './getCheckoutOrderCharge.js';
export { default as getCheckoutOrderContext } from './getCheckoutOrderContext.js';
export { default as getCheckoutOrderContexts } from './getCheckoutOrderContexts.js';
export { default as getCheckoutOrderDeliveryBundles } from './getCheckoutOrderDeliveryBundles.js';
export { default as getCheckoutOrderDeliveryBundleProvisioning } from './getCheckoutOrderDeliveryBundleProvisioning.js';
export { default as getCheckoutOrderDeliveryBundleUpgradeProvisioning } from './getCheckoutOrderDeliveryBundleUpgradeProvisioning.js';
export { default as getCheckoutOrderDeliveryBundleUpgrades } from './getCheckoutOrderDeliveryBundleUpgrades.js';
Expand All @@ -19,6 +20,7 @@ export { default as getCheckoutSession } from './getCheckoutSession.js';
export { default as getCheckoutSessionCharge } from './getCheckoutSessionCharge.js';
export { default as getCollectPoints } from './getCollectPoints.js';
export { default as patchCheckoutOrder } from './patchCheckoutOrder.js';
export { default as patchCheckoutOrderDeliveryBundles } from './patchCheckoutOrderDeliveryBundles.js';
export { default as patchCheckoutOrderDeliveryBundleUpgrades } from './patchCheckoutOrderDeliveryBundleUpgrades.js';
export { default as patchCheckoutOrderItem } from './patchCheckoutOrderItem.js';
export { default as patchCheckoutOrderItems } from './patchCheckoutOrderItems.js';
Expand Down
47 changes: 47 additions & 0 deletions packages/client/src/checkout/patchCheckoutOrderDeliveryBundles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { adaptError } from '../helpers/client/formatError.js';
import client from '../helpers/client/index.js';
import type { PatchCheckoutOrderDeliveryBundles } from './types/index.js';

/**
* Method responsible for applying the selected delivery bundle for the
* specified checkout order.
*
* @param checkoutOrderId - Identifier of the checkout order.
* @param deliveryBundleId - Identifier of the delivery bundle.
* @param data - JSON Patch document to update a list of upgrades JSONPatch document as
* defined by RFC 6902 using: op: replace and test path: \{index\}/isSelected
* and \{index\}/id where \{index\} is the index (zero-based) of the delivery
* bundle to select.
*
* It's recommended to add a test operation to the request to
* guarantee the index is the upgrade to be selected.
* Example:
* [
* \{
* "op":"replace",
* "path": "0/isSelected",
* "value": "true"
* \}
* ].
* @param config - Custom configurations to send to the client instance (axios).
*
* @returns Promise that will resolve when the call to the endpoint finishes.
*/
const patchCheckoutOrderDeliveryBundles: PatchCheckoutOrderDeliveryBundles = (
checkoutOrderId,
deliveryBundleId,
data,
config,
) =>
client
.patch(
`/checkout/v1/orders/${checkoutOrderId}/deliveryBundles/${deliveryBundleId}`,
data,
config,
)
.then(response => response.status)
.catch(error => {
throw adaptError(error);
});

export default patchCheckoutOrderDeliveryBundles;
6 changes: 3 additions & 3 deletions packages/client/src/checkout/types/deliveryBundle.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export type CheckoutOrderDeliveryBundle = {
name: string;
isSelected: boolean;
price: number;
formattedPrice: string;
formattedPrice?: string;
finalPrice: number;
formattedFinalPrice: string;
discount: number;
formattedFinalPrice?: string;
discount?: number;
currency: string;
rank: number;
itemsDeliveryOptions: CheckoutOrderDeliveryBundleItemDeliveryOption[];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { CheckoutOrder, CheckoutOrderDeliveryBundle } from './index.js';
import type { Config } from '../../types/index.js';

export type GetCheckoutOrderDeliveryBundles = (
checkoutOrderId: CheckoutOrder['id'],
config?: Config,
) => Promise<CheckoutOrderDeliveryBundle[]>;
2 changes: 2 additions & 0 deletions packages/client/src/checkout/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export * from './getCheckoutOrderCharge.types.js';
export * from './getCheckoutOrderChargeResponse.types.js';
export * from './getCheckoutOrderContext.types.js';
export * from './getCheckoutOrderContexts.types.js';
export * from './getCheckoutOrderDeliveryBundles.types.js';
export * from './getCheckoutOrderDeliveryBundleProvisioning.types.js';
export * from './getCheckoutOrderDeliveryBundleUpgradeProvisioning.types.js';
export * from './getCheckoutOrderDeliveryBundleUpgrades.types.js';
Expand All @@ -31,6 +32,7 @@ export * from './getCheckoutSessionCharge.types.js';
export * from './getCollectPoints.types.js';
export * from './itemDeliveryProvisioning.types.js';
export * from './patchCheckoutOrder.types.js';
export * from './patchCheckoutOrderDeliveryBundles.types.js';
export * from './patchCheckoutOrderDeliveryBundleUpgrades.types.js';
export * from './patchCheckoutOrderItem.types.js';
export * from './patchCheckoutOrderItems.types.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { CheckoutOrder } from './checkoutOrder.types.js';
import type { CheckoutOrderDeliveryBundle } from './deliveryBundle.types.js';
import type { Config } from '../../types/index.js';
import type { ReplacePatch } from 'json-patch';

export type PatchCheckoutOrderDeliveryBundlesData = Array<ReplacePatch>;

export type PatchCheckoutOrderDeliveryBundles = (
checkoutOrderId: CheckoutOrder['id'],
deliveryBundleId: CheckoutOrderDeliveryBundle['id'],
data: PatchCheckoutOrderDeliveryBundlesData,
config?: Config,
) => Promise<number>;
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type ExchangeFilterCondition = ExchangeFilterLogicOperatorData;
export type ExchangeFilterLogicOperatorData = {
criteria: ExchangeFilterLogicOperatorCriteria;
comparator: ExchangeFilterLogicOperatorComparator;
value: string | string[];
values: string | string[];
};

export enum ExchangeFilterLogicOperatorCriteria {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { rest, type RestHandler } from 'msw';
import type { User } from '../types/index.js';

const path = '/api/account/v1/oidc/accountlinking';
const path = '/api/account/oidc/accountlinking';

const fixtures = {
success: (response: User): RestHandler =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { rest, type RestHandler } from 'msw';
import type { User } from '../types/index.js';

const path = '/api/account/v1/oidc/login';
const path = '/api/account/oidc/login';

const fixtures = {
success: (response: User): RestHandler =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('postAccountLink', () => {
mockUsersResponse,
);
expect(spy).toHaveBeenCalledWith(
'/account/v1/oidc/accountlinking',
'/account/oidc/accountlinking',
requestData,
expectedConfig,
);
Expand All @@ -33,7 +33,7 @@ describe('postAccountLink', () => {

await expect(postAccountLink(requestData)).rejects.toMatchSnapshot();
expect(spy).toHaveBeenCalledWith(
'/account/v1/oidc/accountlinking',
'/account/oidc/accountlinking',
requestData,
expectedConfig,
);
Expand Down
Loading