-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(composables): add setCurrentCountry (#330)
- Loading branch information
1 parent
133faf4
commit 3683116
Showing
5 changed files
with
107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@shopware-pwa/composables-next": minor | ||
--- | ||
|
||
Add `setCountry` method for `useSessionContext` composable |
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,5 @@ | ||
--- | ||
"@shopware/api-client": minor | ||
--- | ||
|
||
Add `setCurrentCountry` for changing context countryId |
62 changes: 62 additions & 0 deletions
62
packages/api-client/src/services/ContextServiceTests/setCurrentCountry.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,62 @@ | ||
import { defaultInstance } from "../../apiService"; | ||
import { setCurrentCountry } from "../contextService"; | ||
import { update } from "../.."; | ||
import { describe, expect, it, beforeEach, vi } from "vitest"; | ||
|
||
vi.mock("../../../src/apiService"); | ||
const mockedApiInstance = defaultInstance; | ||
|
||
describe("ContextService - setCurrentCountry", () => { | ||
const newCountryId = "28bbf3f6e79145ba8ffc91c409690ab8"; | ||
const contextToken = "NWDdcRTTWoPk4Ngv13z5NDMMsDFRb9W6"; | ||
|
||
const mockedPatch = vi.fn(); | ||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
mockedApiInstance.invoke = { | ||
patch: mockedPatch, | ||
} as any; | ||
}); | ||
|
||
describe("with contextToken given", () => { | ||
beforeEach(() => { | ||
update({ contextToken }); | ||
}); | ||
|
||
it("should return context token", async () => { | ||
mockedPatch.mockResolvedValueOnce({ | ||
data: { "sw-context-token": contextToken }, | ||
}); | ||
|
||
const result = await setCurrentCountry(newCountryId); | ||
|
||
expect(mockedPatch).toBeCalledTimes(1); | ||
expect(mockedPatch).toBeCalledWith("/store-api/context", { | ||
countryId: newCountryId, | ||
}); | ||
|
||
expect(result.contextToken).toEqual(contextToken); | ||
}); | ||
}); | ||
|
||
describe("without contextToken given", () => { | ||
beforeEach(() => { | ||
update({ contextToken: undefined }); | ||
}); | ||
|
||
it("should return context token", async () => { | ||
mockedPatch.mockResolvedValueOnce({ | ||
data: { "sw-context-token": contextToken }, | ||
}); | ||
|
||
const result = await setCurrentCountry(newCountryId); | ||
|
||
expect(mockedPatch).toBeCalledTimes(1); | ||
expect(mockedPatch).toBeCalledWith("/store-api/context", { | ||
countryId: "28bbf3f6e79145ba8ffc91c409690ab8", | ||
}); | ||
|
||
expect(result.contextToken).toEqual(contextToken); | ||
}); | ||
}); | ||
}); |
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
3683116
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
shopware-frontends-docs – ./
shopware-frontends-docs-git-main-shopware-frontends.vercel.app
shopware-frontends-docs.vercel.app
frontends.shopware.com
shopware-frontends-docs-shopware-frontends.vercel.app
3683116
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
frontends-demo – ./templates/vue-demo-store
frontends-demo-git-main-shopware-frontends.vercel.app
frontends-demo-shopware-frontends.vercel.app
frontends-demo.vercel.app