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.
feat(api-client): set current context's address - billing & shipping (#…
…536)
- Loading branch information
Showing
4 changed files
with
138 additions
and
0 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
55 changes: 55 additions & 0 deletions
55
...ages/shopware-6-client/__tests__/services/ContextService/setCurrentBillingAddress.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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { apiService } from "../../../src/apiService"; | ||
import { | ||
setCurrentBillingAddress, | ||
update | ||
} from "@shopware-pwa/shopware-6-client"; | ||
|
||
jest.mock("../../../src/apiService"); | ||
const mockedAxios = apiService as jest.Mocked<typeof apiService>; | ||
|
||
describe("ContextService - setCurrentBillingAddress with contextToken given", () => { | ||
beforeEach(() => { | ||
update({ contextToken: "NWDdcRTTWoPk4Ngv13z5NDMMsDFRb9W6" }); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it("should return context token", async () => { | ||
mockedAxios.patch.mockResolvedValueOnce({ | ||
data: { "sw-context-token": "NWDdcRTTWoPk4Ngv13z5NDMMsDFRb9W6" } | ||
}); | ||
|
||
let newBillingAddressId = "45f96f681f9d4834b29e9e15df3a7149"; | ||
|
||
const result = await setCurrentBillingAddress(newBillingAddressId); | ||
|
||
expect(mockedAxios.patch).toBeCalledTimes(1); | ||
expect(mockedAxios.patch).toBeCalledWith("/context", { | ||
billingAddressId: "45f96f681f9d4834b29e9e15df3a7149" | ||
}); | ||
|
||
expect(result.contextToken).toEqual("NWDdcRTTWoPk4Ngv13z5NDMMsDFRb9W6"); | ||
}); | ||
}); | ||
|
||
describe("ContextService - setCurrentBillingAddress without contextToken given", () => { | ||
beforeEach(() => { | ||
update({ contextToken: undefined }); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it("should return context token", async () => { | ||
mockedAxios.patch.mockResolvedValueOnce({ | ||
data: { "sw-context-token": "NWDdcRTTWoPk4Ngv13z5NDMMsDFRb9W6" } | ||
}); | ||
|
||
let newBillingAddressId = "45f96f681f9d4834b29e9e15df3a7149"; | ||
|
||
const result = await setCurrentBillingAddress(newBillingAddressId); | ||
expect(mockedAxios.patch).toBeCalledTimes(1); | ||
expect(mockedAxios.patch).toBeCalledWith("/context", { | ||
billingAddressId: "45f96f681f9d4834b29e9e15df3a7149" | ||
}); | ||
|
||
expect(result.contextToken).toEqual("NWDdcRTTWoPk4Ngv13z5NDMMsDFRb9W6"); | ||
}); | ||
}); |
55 changes: 55 additions & 0 deletions
55
...ges/shopware-6-client/__tests__/services/ContextService/setCurrentShippingAddress.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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { apiService } from "../../../src/apiService"; | ||
import { | ||
setCurrentShippingAddress, | ||
update | ||
} from "@shopware-pwa/shopware-6-client"; | ||
|
||
jest.mock("../../../src/apiService"); | ||
const mockedAxios = apiService as jest.Mocked<typeof apiService>; | ||
|
||
describe("ContextService - setCurrentShippingAddress with contextToken given", () => { | ||
beforeEach(() => { | ||
update({ contextToken: "NWDdcRTTWoPk4Ngv13z5NDMMsDFRb9W6" }); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it("should return context token", async () => { | ||
mockedAxios.patch.mockResolvedValueOnce({ | ||
data: { "sw-context-token": "NWDdcRTTWoPk4Ngv13z5NDMMsDFRb9W6" } | ||
}); | ||
|
||
let newShippingAddressId = "45f96f681f9d4834b29e9e15df3a7149"; | ||
|
||
const result = await setCurrentShippingAddress(newShippingAddressId); | ||
|
||
expect(mockedAxios.patch).toBeCalledTimes(1); | ||
expect(mockedAxios.patch).toBeCalledWith("/context", { | ||
shippingAddressId: "45f96f681f9d4834b29e9e15df3a7149" | ||
}); | ||
|
||
expect(result.contextToken).toEqual("NWDdcRTTWoPk4Ngv13z5NDMMsDFRb9W6"); | ||
}); | ||
}); | ||
|
||
describe("ContextService - setCurrentShippingAddress without contextToken given", () => { | ||
beforeEach(() => { | ||
update({ contextToken: undefined }); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it("should return context token", async () => { | ||
mockedAxios.patch.mockResolvedValueOnce({ | ||
data: { "sw-context-token": "NWDdcRTTWoPk4Ngv13z5NDMMsDFRb9W6" } | ||
}); | ||
|
||
let newShippingAddressId = "45f96f681f9d4834b29e9e15df3a7149"; | ||
|
||
const result = await setCurrentShippingAddress(newShippingAddressId); | ||
expect(mockedAxios.patch).toBeCalledTimes(1); | ||
expect(mockedAxios.patch).toBeCalledWith("/context", { | ||
shippingAddressId: "45f96f681f9d4834b29e9e15df3a7149" | ||
}); | ||
|
||
expect(result.contextToken).toEqual("NWDdcRTTWoPk4Ngv13z5NDMMsDFRb9W6"); | ||
}); | ||
}); |
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