This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(customer): change logic, tests and other parts.
- Loading branch information
Maciej Kucmus
committed
Oct 22, 2019
1 parent
0e9d73e
commit 9ba6de4
Showing
17 changed files
with
297 additions
and
429 deletions.
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
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
35 changes: 17 additions & 18 deletions
35
packages/shopware-6-client/__tests__/services/CustomerService/getCustomer.spec.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 |
---|---|---|
@@ -1,38 +1,37 @@ | ||
import { when } from "jest-when"; | ||
import { getCustomer } from "@shopware-pwa/shopware-6-client"; | ||
import { getCustomer, update, config } from "@shopware-pwa/shopware-6-client"; | ||
import { apiService } from "../../../src/apiService"; | ||
import { getCustomerEndpoint } from "../../../src/endpoints"; | ||
import { random } from "faker"; | ||
jest.mock("../../../src/apiService"); | ||
const mockedAxios = apiService as jest.Mocked<typeof apiService>; | ||
|
||
describe("CustomerService - getCustomer", () => { | ||
let contextToken: string; | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
contextToken = random.uuid(); | ||
update({ contextToken }); | ||
}); | ||
afterEach(() => { | ||
afterEach(() => { | ||
expect(config.contextToken).toEqual(contextToken); | ||
}); | ||
}); | ||
|
||
it("should an current customer's data - using correct token", async () => { | ||
when(mockedAxios.get) | ||
.expectCalledWith(getCustomerEndpoint(), { | ||
headers: { "sw-context-token": "c370eb5cd1df4d4dbcc78f055b693e79" } | ||
}) | ||
.mockReturnValueOnce({ | ||
data: { data: { id: "c370eb5cd1df4d4dbcc78f055b693e79" } } | ||
}); | ||
const result = await getCustomer("c370eb5cd1df4d4dbcc78f055b693e79"); | ||
expect(mockedAxios.get).toBeCalledTimes(1); | ||
expect(mockedAxios.get).toBeCalledWith("/customer", { | ||
headers: { "sw-context-token": "c370eb5cd1df4d4dbcc78f055b693e79" } | ||
mockedAxios.get.mockResolvedValueOnce({ | ||
data: { data: { id: "c370eb5cd1df4d4dbcc78f055b693e79" } } | ||
}); | ||
expect(result).toHaveProperty("id"); | ||
const result = await getCustomer(); | ||
expect(mockedAxios.get).toBeCalledTimes(1); | ||
expect(mockedAxios.get).toBeCalledWith(getCustomerEndpoint()); | ||
expect(result.id).toEqual("c370eb5cd1df4d4dbcc78f055b693e79"); | ||
}); | ||
|
||
it("should an current customer's data - using incorrect token", async () => { | ||
mockedAxios.get.mockRejectedValue(new Error()); | ||
expect(getCustomer("b370eb5cd1df4d4dbcc78f055b693e79")).rejects.toThrow(); | ||
expect(getCustomer()).rejects.toThrow(); | ||
expect(mockedAxios.get).toBeCalledTimes(1); | ||
expect(mockedAxios.get).toBeCalledWith("/customer", { | ||
headers: { "sw-context-token": "b370eb5cd1df4d4dbcc78f055b693e79" } | ||
}); | ||
expect(mockedAxios.get).toBeCalledWith(getCustomerEndpoint()); | ||
}); | ||
}); |
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: 17 additions & 10 deletions
27
packages/shopware-6-client/__tests__/services/CustomerService/getCustomerAddresses.spec.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 |
---|---|---|
@@ -1,26 +1,33 @@ | ||
import { random } from "faker"; | ||
import { when } from "jest-when"; | ||
import { getCustomerAddresses } from "../../../src/index"; | ||
import { | ||
getCustomerAddresses, | ||
update, | ||
config | ||
} from "@shopware-pwa/shopware-6-client"; | ||
import { getCustomerEndpoint } from "../../../src/endpoints"; | ||
import { apiService } from "../../../src/apiService"; | ||
|
||
jest.mock("../../../src/apiService"); | ||
const mockedAxios = apiService as jest.Mocked<typeof apiService>; | ||
|
||
describe("CustomerService - register", () => { | ||
const customerToken = random.uuid(); | ||
let contextToken: string; | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
contextToken = random.uuid(); | ||
update({ contextToken }); | ||
}); | ||
afterEach(() => { | ||
afterEach(() => { | ||
expect(config.contextToken).toEqual(contextToken); | ||
}); | ||
}); | ||
|
||
it("should return object of addresses", async () => { | ||
when(mockedAxios.get) | ||
.expectCalledWith(`${getCustomerEndpoint()}/address`) | ||
.mockReturnValueOnce({ data: { data: {} } }); | ||
const result = await getCustomerAddresses(customerToken); | ||
mockedAxios.get.mockResolvedValueOnce({ data: { data: {} } }); | ||
const result = await getCustomerAddresses(); | ||
expect(mockedAxios.get).toBeCalledTimes(1); | ||
expect(mockedAxios.get).toBeCalledWith(`${getCustomerEndpoint()}/address`, { | ||
headers: { "sw-context-token": customerToken } | ||
}); | ||
expect(mockedAxios.get).toBeCalledWith(`${getCustomerEndpoint()}/address`); | ||
expect(result).toMatchObject({}); | ||
}); | ||
}); |
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.