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

feat: expose missing address endpoints on main #958

Merged
merged 1 commit into from
Jan 16, 2024
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 @@ -1077,7 +1077,9 @@ Object {
"deleteUserAttribute": [Function],
"deleteUserClosetItem": [Function],
"deleteUserContact": [Function],
"deleteUserDefaultBillingAddress": [Function],
"deleteUserDefaultContactAddress": [Function],
"deleteUserDefaultShippingAddress": [Function],
"deleteUserExternalLogin": [Function],
"deleteUserPersonalId": [Function],
"deleteWishlistItem": [Function],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { rest, type RestHandler } from 'msw';

const path = '/api/account/v1/users/:userId/addresses/billing/current';

const fixtures = {
success: (): RestHandler =>
rest.delete(path, (_req, res, ctx) => res(ctx.status(204))),
failure: (): RestHandler =>
rest.delete(path, (_req, res, ctx) =>
res(
ctx.status(400),
ctx.json({
errors: [
{
code: 0,
message: 'error',
developerMessage: 'This is developer message',
moreInformation: 'Error more information',
exception: {},
},
],
}),
),
),
};

export default fixtures;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { rest, type RestHandler } from 'msw';

const path = '/api/account/v1/users/:userId/addresses/shipping/current';

const fixtures = {
success: (): RestHandler =>
rest.delete(path, (_req, res, ctx) => res(ctx.status(204))),
failure: (): RestHandler =>
rest.delete(path, (_req, res, ctx) =>
res(
ctx.status(400),
ctx.json({
errors: [
{
code: 0,
message: 'error',
developerMessage: 'This is developer message',
moreInformation: 'Error more information',
exception: {},
},
],
}),
),
),
};

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

exports[`deleteUserDefaultBillingAddress should receive a client request error 1`] = `
Object {
"code": 0,
"developerMessage": "This is developer message",
"exception": Object {},
"message": "error",
"moreInformation": "Error more information",
"name": "AxiosError",
"status": 400,
"transportLayerErrorCode": "ERR_BAD_REQUEST",
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`deleteUserDefaultShippingAddress should receive a client request error 1`] = `
Object {
"code": 0,
"developerMessage": "This is developer message",
"exception": Object {},
"message": "error",
"moreInformation": "Error more information",
"name": "AxiosError",
"status": 400,
"transportLayerErrorCode": "ERR_BAD_REQUEST",
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { deleteUserDefaultBillingAddress } from '../index.js';
import { userId } from 'tests/__fixtures__/addresses/index.mjs';
import client from '../../../helpers/client/index.js';
import fixtures from '../__fixtures__/deleteUserDefaultBillingAddress.fixtures.js';
import mswServer from '../../../../tests/mswServer.js';

describe('deleteUserDefaultBillingAddress', () => {
const expectedConfig = undefined;
const spy = jest.spyOn(client, 'delete');
const expectedUrl = `/account/v1/users/${userId}/addresses/billing/current`;

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

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

await expect(deleteUserDefaultBillingAddress(userId)).resolves.toBe(204);
expect(spy).toHaveBeenCalledWith(expectedUrl, expectedConfig);
});

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

await expect(
deleteUserDefaultBillingAddress(userId),
).rejects.toMatchSnapshot();
expect(spy).toHaveBeenCalledWith(expectedUrl, expectedConfig);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { deleteUserDefaultShippingAddress } from '../index.js';
import { userId } from 'tests/__fixtures__/addresses/index.mjs';
import client from '../../../helpers/client/index.js';
import fixtures from '../__fixtures__/deleteUserDefaultShippingAddress.fixtures.js';
import mswServer from '../../../../tests/mswServer.js';

describe('deleteUserDefaultShippingAddress', () => {
const expectedConfig = undefined;
const spy = jest.spyOn(client, 'delete');
const expectedUrl = `/account/v1/users/${userId}/addresses/shipping/current`;

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

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

await expect(deleteUserDefaultShippingAddress(userId)).resolves.toBe(204);
expect(spy).toHaveBeenCalledWith(expectedUrl, expectedConfig);
});

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

await expect(
deleteUserDefaultShippingAddress(userId),
).rejects.toMatchSnapshot();
expect(spy).toHaveBeenCalledWith(expectedUrl, expectedConfig);
});
});
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 join from 'proper-url-join';
import type { DeleteUserDefaultBillingAddress } from './types/index.js';

/**
* Responsible for unsetting the users default billing address.
*
* @param userId - Identifier of the user.
* @param config - Custom configurations to send to the client instance (axios).
*
* @returns Promise that will resolve when the call to the endpoint finishes.
*/
const deleteUserDefaultBillingAddress: DeleteUserDefaultBillingAddress = (
userId,
config,
) =>
client
.delete(
join('/account/v1/users', userId, 'addresses/billing/current'),
config,
)
.then(response => response.status)
.catch(error => {
throw adaptError(error);
});

export default deleteUserDefaultBillingAddress;
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 join from 'proper-url-join';
import type { DeleteUserDefaultShippingAddress } from './types/index.js';

/**
* Responsible for unsetting the users default shipping address.
*
* @param userId - Identifier of the user.
* @param config - Custom configurations to send to the client instance (axios).
*
* @returns Promise that will resolve when the call to the endpoint finishes.
*/
const deleteUserDefaultShippingAddress: DeleteUserDefaultShippingAddress = (
userId,
config,
) =>
client
.delete(
join('/account/v1/users', userId, 'addresses/shipping/current'),
config,
)
.then(response => response.status)
.catch(error => {
throw adaptError(error);
});

export default deleteUserDefaultShippingAddress;
2 changes: 2 additions & 0 deletions packages/client/src/users/addresses/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export { default as deleteUserAddress } from './deleteUserAddress.js';
export { default as deleteUserDefaultContactAddress } from './deleteUserDefaultContactAddress.js';
export { default as deleteUserDefaultBillingAddress } from './deleteUserDefaultBillingAddress.js';
export { default as deleteUserDefaultShippingAddress } from './deleteUserDefaultShippingAddress.js';
export { default as getUserAddress } from './getUserAddress.js';
export { default as getUserAddresses } from './getUserAddresses.js';
export { default as getUserDefaultContactAddress } from './getUserDefaultContactAddress.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Config } from '../../../types/index.js';
import type { User } from '../../authentication/types/user.types.js';

export type DeleteUserDefaultBillingAddress = (
userId: User['id'],
config?: Config,
) => Promise<number>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Config } from '../../../types/index.js';
import type { User } from '../../authentication/types/user.types.js';

export type DeleteUserDefaultShippingAddress = (
userId: User['id'],
config?: Config,
) => Promise<number>;
2 changes: 2 additions & 0 deletions packages/client/src/users/addresses/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export * from './deleteUserAddress.types.js';
export * from './deleteUserDefaultBillingAddress.types.js';
export * from './deleteUserDefaultContactAddress.types.js';
export * from './deleteUserDefaultShippingAddress.types.js';
export * from './getDefaultContactAddress.types.js';
export * from './getUserAddress.types.js';
export * from './getUserAddresses.types.js';
Expand Down
14 changes: 14 additions & 0 deletions packages/redux/src/__tests__/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,9 @@ Object {
"@farfetch/blackout-redux/LOGOUT_SUCCESS": [Function],
"@farfetch/blackout-redux/REGISTER_SUCCESS": [Function],
"@farfetch/blackout-redux/REMOVE_USER_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/REMOVE_USER_DEFAULT_BILLING_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/REMOVE_USER_DEFAULT_CONTACT_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/REMOVE_USER_DEFAULT_SHIPPING_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/RESET_USER_ENTITIES": [Function],
"@farfetch/blackout-redux/SET_USER_DEFAULT_BILLING_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/SET_USER_DEFAULT_CONTACT_ADDRESS_SUCCESS": [Function],
Expand Down Expand Up @@ -1668,8 +1670,12 @@ Object {
"removeUserClosetItemFactory": [Function],
"removeUserContact": [Function],
"removeUserContactFactory": [Function],
"removeUserDefaultBillingAddress": [Function],
"removeUserDefaultBillingAddressFactory": [Function],
"removeUserDefaultContactAddress": [Function],
"removeUserDefaultContactAddressFactory": [Function],
"removeUserDefaultShippingAddress": [Function],
"removeUserDefaultShippingAddressFactory": [Function],
"removeUserExternalLogin": [Function],
"removeUserExternalLoginFactory": [Function],
"removeUserPersonalId": [Function],
Expand Down Expand Up @@ -2058,9 +2064,15 @@ Object {
"REMOVE_USER_CONTACT_FAILURE": "@farfetch/blackout-redux/REMOVE_USER_CONTACT_FAILURE",
"REMOVE_USER_CONTACT_REQUEST": "@farfetch/blackout-redux/REMOVE_USER_CONTACT_REQUEST",
"REMOVE_USER_CONTACT_SUCCESS": "@farfetch/blackout-redux/REMOVE_USER_CONTACT_SUCCESS",
"REMOVE_USER_DEFAULT_BILLING_ADDRESS_FAILURE": "@farfetch/blackout-redux/REMOVE_USER_DEFAULT_BILLING_ADDRESS_FAILURE",
"REMOVE_USER_DEFAULT_BILLING_ADDRESS_REQUEST": "@farfetch/blackout-redux/REMOVE_USER_DEFAULT_BILLING_ADDRESS_REQUEST",
"REMOVE_USER_DEFAULT_BILLING_ADDRESS_SUCCESS": "@farfetch/blackout-redux/REMOVE_USER_DEFAULT_BILLING_ADDRESS_SUCCESS",
"REMOVE_USER_DEFAULT_CONTACT_ADDRESS_FAILURE": "@farfetch/blackout-redux/REMOVE_USER_DEFAULT_CONTACT_ADDRESS_FAILURE",
"REMOVE_USER_DEFAULT_CONTACT_ADDRESS_REQUEST": "@farfetch/blackout-redux/REMOVE_USER_DEFAULT_CONTACT_ADDRESS_REQUEST",
"REMOVE_USER_DEFAULT_CONTACT_ADDRESS_SUCCESS": "@farfetch/blackout-redux/REMOVE_USER_DEFAULT_CONTACT_ADDRESS_SUCCESS",
"REMOVE_USER_DEFAULT_SHIPPING_ADDRESS_FAILURE": "@farfetch/blackout-redux/REMOVE_USER_DEFAULT_SHIPPING_ADDRESS_FAILURE",
"REMOVE_USER_DEFAULT_SHIPPING_ADDRESS_REQUEST": "@farfetch/blackout-redux/REMOVE_USER_DEFAULT_SHIPPING_ADDRESS_REQUEST",
"REMOVE_USER_DEFAULT_SHIPPING_ADDRESS_SUCCESS": "@farfetch/blackout-redux/REMOVE_USER_DEFAULT_SHIPPING_ADDRESS_SUCCESS",
"REMOVE_USER_EXTERNAL_LOGIN_FAILURE": "@farfetch/blackout-redux/REMOVE_USER_EXTERNAL_LOGIN_FAILURE",
"REMOVE_USER_EXTERNAL_LOGIN_REQUEST": "@farfetch/blackout-redux/REMOVE_USER_EXTERNAL_LOGIN_REQUEST",
"REMOVE_USER_EXTERNAL_LOGIN_SUCCESS": "@farfetch/blackout-redux/REMOVE_USER_EXTERNAL_LOGIN_SUCCESS",
Expand Down Expand Up @@ -2140,7 +2152,9 @@ Object {
"@farfetch/blackout-redux/LOGOUT_SUCCESS": [Function],
"@farfetch/blackout-redux/REGISTER_SUCCESS": [Function],
"@farfetch/blackout-redux/REMOVE_USER_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/REMOVE_USER_DEFAULT_BILLING_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/REMOVE_USER_DEFAULT_CONTACT_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/REMOVE_USER_DEFAULT_SHIPPING_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/RESET_USER_ENTITIES": [Function],
"@farfetch/blackout-redux/SET_USER_DEFAULT_BILLING_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/SET_USER_DEFAULT_CONTACT_ADDRESS_SUCCESS": [Function],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ Object {
"@farfetch/blackout-redux/LOGOUT_SUCCESS": [Function],
"@farfetch/blackout-redux/REGISTER_SUCCESS": [Function],
"@farfetch/blackout-redux/REMOVE_USER_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/REMOVE_USER_DEFAULT_BILLING_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/REMOVE_USER_DEFAULT_CONTACT_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/REMOVE_USER_DEFAULT_SHIPPING_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/RESET_USER_ENTITIES": [Function],
"@farfetch/blackout-redux/SET_USER_DEFAULT_BILLING_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/SET_USER_DEFAULT_CONTACT_ADDRESS_SUCCESS": [Function],
Expand Down
Loading
Loading