-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose missing address endpoints
- Loading branch information
Showing
26 changed files
with
633 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/client/src/users/addresses/__fixtures__/deleteUserDefaultBillingAddress.fixtures.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
27 changes: 27 additions & 0 deletions
27
...ages/client/src/users/addresses/__fixtures__/deleteUserDefaultShippingAddress.fixtures.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
14 changes: 14 additions & 0 deletions
14
.../src/users/addresses/__tests__/__snapshots__/deleteUserDefaultBillingAddress.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} | ||
`; |
14 changes: 14 additions & 0 deletions
14
...src/users/addresses/__tests__/__snapshots__/deleteUserDefaultShippingAddress.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} | ||
`; |
29 changes: 29 additions & 0 deletions
29
packages/client/src/users/addresses/__tests__/deleteUserDefaultBillingAddress.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/client/src/users/addresses/__tests__/deleteUserDefaultShippingAddress.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/client/src/users/addresses/deleteUserDefaultBillingAddress.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
28 changes: 28 additions & 0 deletions
28
packages/client/src/users/addresses/deleteUserDefaultShippingAddress.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/client/src/users/addresses/types/deleteUserDefaultBillingAddress.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
7 changes: 7 additions & 0 deletions
7
packages/client/src/users/addresses/types/deleteUserDefaultShippingAddress.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...rs/addresses/actions/__tests__/__snapshots__/removeUserDefaultBillingAddress.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`removeUserDefaultBillingAddress() action creator should create the correct actions for when the delete user default billing address procedure is successful: delete user default billing address success payload 1`] = ` | ||
Object { | ||
"meta": Object { | ||
"addressId": "2222222", | ||
"userId": 29556478, | ||
}, | ||
"type": "@farfetch/blackout-redux/REMOVE_USER_DEFAULT_BILLING_ADDRESS_SUCCESS", | ||
} | ||
`; |
11 changes: 11 additions & 0 deletions
11
...s/addresses/actions/__tests__/__snapshots__/removeUserDefaultShippingAddress.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`removeUserDefaultShippingAddress() action creator should create the correct actions for when the delete user default shipping address procedure is successful: delete user default shipping address success payload 1`] = ` | ||
Object { | ||
"meta": Object { | ||
"addressId": "2222222", | ||
"userId": 29556478, | ||
}, | ||
"type": "@farfetch/blackout-redux/REMOVE_USER_DEFAULT_SHIPPING_ADDRESS_SUCCESS", | ||
} | ||
`; |
Oops, something went wrong.