-
Notifications
You must be signed in to change notification settings - Fork 15
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 in v1
feat: add missing address endpoints
- Loading branch information
Showing
20 changed files
with
755 additions
and
6 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
packages/core/src/addresses/client/__fixtures__/deleteDefaultBillingAddress.fixtures.js
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,34 @@ | ||
import join from 'proper-url-join'; | ||
import moxios from 'moxios'; | ||
|
||
export default { | ||
success: params => { | ||
moxios.stubRequest( | ||
join('/api/account/v1/users', params.userId, 'addresses/billing/current'), | ||
{ | ||
method: 'delete', | ||
status: 204, | ||
}, | ||
); | ||
}, | ||
failure: params => { | ||
moxios.stubRequest( | ||
join('/api/account/v1/users', params.userId, 'addresses/billing/current'), | ||
{ | ||
method: 'delete', | ||
response: { | ||
errors: [ | ||
{ | ||
code: 0, | ||
message: 'error', | ||
developerMessage: 'This is developer message', | ||
moreInformation: 'Error more information', | ||
exception: {}, | ||
}, | ||
], | ||
}, | ||
status: 400, | ||
}, | ||
); | ||
}, | ||
}; |
42 changes: 42 additions & 0 deletions
42
packages/core/src/addresses/client/__fixtures__/deleteDefaultShippingAddress.fixtures.js
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,42 @@ | ||
import join from 'proper-url-join'; | ||
import moxios from 'moxios'; | ||
|
||
export default { | ||
success: params => { | ||
moxios.stubRequest( | ||
join( | ||
'/api/account/v1/users', | ||
params.userId, | ||
'addresses/shipping/current', | ||
), | ||
{ | ||
method: 'delete', | ||
status: 204, | ||
}, | ||
); | ||
}, | ||
failure: params => { | ||
moxios.stubRequest( | ||
join( | ||
'/api/account/v1/users', | ||
params.userId, | ||
'addresses/shipping/current', | ||
), | ||
{ | ||
method: 'delete', | ||
response: { | ||
errors: [ | ||
{ | ||
code: 0, | ||
message: 'error', | ||
developerMessage: 'This is developer message', | ||
moreInformation: 'Error more information', | ||
exception: {}, | ||
}, | ||
], | ||
}, | ||
status: 400, | ||
}, | ||
); | ||
}, | ||
}; |
12 changes: 12 additions & 0 deletions
12
...ore/src/addresses/client/__tests__/__snapshots__/deleteDefaultBillingAddress.test.js.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,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`deleteDefaultBillingAddress should receive a client request error 1`] = ` | ||
Object { | ||
"code": 0, | ||
"developerMessage": "This is developer message", | ||
"exception": Object {}, | ||
"message": "error", | ||
"moreInformation": "Error more information", | ||
"status": 400, | ||
} | ||
`; |
12 changes: 12 additions & 0 deletions
12
...re/src/addresses/client/__tests__/__snapshots__/deleteDefaultShippingAddress.test.js.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,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`deleteDefaultShippingAddress should receive a client request error 1`] = ` | ||
Object { | ||
"code": 0, | ||
"developerMessage": "This is developer message", | ||
"exception": Object {}, | ||
"message": "error", | ||
"moreInformation": "Error more information", | ||
"status": 400, | ||
} | ||
`; |
36 changes: 36 additions & 0 deletions
36
packages/core/src/addresses/client/__tests__/deleteDefaultBillingAddress.test.js
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,36 @@ | ||
import { deleteDefaultBillingAddress } from '../'; | ||
import client from '../../../helpers/client'; | ||
import fixture from '../__fixtures__/deleteDefaultBillingAddress.fixtures'; | ||
import moxios from 'moxios'; | ||
|
||
describe('deleteDefaultBillingAddress', () => { | ||
const userId = '123456'; | ||
const expectedConfig = undefined; | ||
const spy = jest.spyOn(client, 'delete'); | ||
const expectedUrl = `/account/v1/users/${userId}/addresses/billing/current`; | ||
|
||
beforeEach(() => { | ||
moxios.install(client); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
afterEach(() => moxios.uninstall(client)); | ||
|
||
it('should handle a client request successfully', async () => { | ||
fixture.success({ userId }); | ||
|
||
expect.assertions(2); | ||
|
||
await expect(deleteDefaultBillingAddress(userId)).resolves.toBe(204); | ||
expect(spy).toHaveBeenCalledWith(expectedUrl, expectedConfig); | ||
}); | ||
|
||
it('should receive a client request error', async () => { | ||
fixture.failure({ userId }); | ||
|
||
expect.assertions(2); | ||
|
||
await expect(deleteDefaultBillingAddress(userId)).rejects.toMatchSnapshot(); | ||
expect(spy).toHaveBeenCalledWith(expectedUrl, expectedConfig); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/core/src/addresses/client/__tests__/deleteDefaultShippingAddress.test.js
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,38 @@ | ||
import { deleteDefaultShippingAddress } from '../'; | ||
import client from '../../../helpers/client'; | ||
import fixture from '../__fixtures__/deleteDefaultShippingAddress.fixtures'; | ||
import moxios from 'moxios'; | ||
|
||
describe('deleteDefaultShippingAddress', () => { | ||
const userId = '123456'; | ||
const expectedConfig = undefined; | ||
const spy = jest.spyOn(client, 'delete'); | ||
const expectedUrl = `/account/v1/users/${userId}/addresses/shipping/current`; | ||
|
||
beforeEach(() => { | ||
moxios.install(client); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
afterEach(() => moxios.uninstall(client)); | ||
|
||
it('should handle a client request successfully', async () => { | ||
fixture.success({ userId }); | ||
|
||
expect.assertions(2); | ||
|
||
await expect(deleteDefaultShippingAddress(userId)).resolves.toBe(204); | ||
expect(spy).toHaveBeenCalledWith(expectedUrl, expectedConfig); | ||
}); | ||
|
||
it('should receive a client request error', async () => { | ||
fixture.failure({ userId }); | ||
|
||
expect.assertions(2); | ||
|
||
await expect( | ||
deleteDefaultShippingAddress(userId), | ||
).rejects.toMatchSnapshot(); | ||
expect(spy).toHaveBeenCalledWith(expectedUrl, expectedConfig); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/core/src/addresses/client/deleteDefaultBillingAddress.js
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,26 @@ | ||
import client, { adaptError } from '../../helpers/client'; | ||
import join from 'proper-url-join'; | ||
|
||
/** | ||
* Responsible for unsetting the users default billing address. | ||
* | ||
* @function deleteDefaultBillingAddress | ||
* @memberof module:addresses/client | ||
* | ||
* @param {string} userId - Identifier of the user. | ||
* @param {object} [config] - Custom configurations to send to the client | ||
* instance (axios). | ||
* | ||
* @returns {Promise} Promise that will resolve when the call to | ||
* the endpoint finishes. | ||
*/ | ||
export default (userId, config) => | ||
client | ||
.delete( | ||
join('/account/v1/users', userId, 'addresses/billing/current'), | ||
config, | ||
) | ||
.then(response => response.status) | ||
.catch(error => { | ||
throw adaptError(error); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/core/src/addresses/client/deleteDefaultShippingAddress.js
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,26 @@ | ||
import client, { adaptError } from '../../helpers/client'; | ||
import join from 'proper-url-join'; | ||
|
||
/** | ||
* Responsible for unsetting the users default shipping address. | ||
* | ||
* @function deleteDefaultShippingAddress | ||
* @memberof module:addresses/client | ||
* | ||
* @param {string} userId - Identifier of the user. | ||
* @param {object} [config] - Custom configurations to send to the client | ||
* instance (axios). | ||
* | ||
* @returns {Promise} Promise that will resolve when the call to | ||
* the endpoint finishes. | ||
*/ | ||
export default (userId, config) => | ||
client | ||
.delete( | ||
join('/account/v1/users', userId, 'addresses/shipping/current'), | ||
config, | ||
) | ||
.then(response => response.status) | ||
.catch(error => { | ||
throw adaptError(error); | ||
}); |
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
Oops, something went wrong.