-
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.
- Loading branch information
Showing
18 changed files
with
679 additions
and
2 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
import join from 'proper-url-join'; | ||
import moxios from 'moxios'; | ||
|
||
export default { | ||
success: params => { | ||
console.log(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); | ||
}); | ||
}); |
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
...ddresses/redux/actions/__tests__/__snapshots__/doDeleteDefaultBillingAddress.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,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`doDeleteDefaultBillingAddress() action creator should create the correct actions for when the delete default billing address procedure is successful: delete default billing address success payload 1`] = ` | ||
Object { | ||
"meta": Object { | ||
"addressId": "2222222", | ||
"userId": "121212", | ||
}, | ||
"type": "@farfetch/blackout-redux/DELETE_DEFAULT_BILLING_ADDRESS_SUCCESS", | ||
} | ||
`; |
11 changes: 11 additions & 0 deletions
11
...dresses/redux/actions/__tests__/__snapshots__/doDeleteDefaultShippingAddress.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,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`doDeleteDefaultShippingAddress() action creator should create the correct actions for when the delete default shipping address procedure is successful: delete default shipping address success payload 1`] = ` | ||
Object { | ||
"meta": Object { | ||
"addressId": "2222222", | ||
"userId": "121212", | ||
}, | ||
"type": "@farfetch/blackout-redux/DELETE_DEFAULT_SHIPPING_ADDRESS_SUCCESS", | ||
} | ||
`; |
Oops, something went wrong.