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(default-theme): reset password functionality (#756)
- Loading branch information
Showing
8 changed files
with
213 additions
and
8 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
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
97 changes: 97 additions & 0 deletions
97
packages/shopware-6-client/__tests__/services/CustomerService/resetPassword.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,97 @@ | ||
import { getCustomerResetPasswordEndpoint } from "../../../src/endpoints"; | ||
import { apiService } from "../../../src/apiService"; | ||
import { internet, random } from "faker"; | ||
import { resetPassword, update, config } from "@shopware-pwa/shopware-6-client"; | ||
|
||
const DEFAULT_ENDPOINT = "https://shopware-2.vuestorefront.io"; | ||
const email = internet.email("John", "Doe"); | ||
const credentials = { | ||
email: email, | ||
storefrontUrl: config.endpoint ?? DEFAULT_ENDPOINT, | ||
}; | ||
|
||
jest.mock("../../../src/apiService"); | ||
const mockedAxios = apiService as jest.Mocked<typeof apiService>; | ||
|
||
describe("CustomerService - resetPassword", () => { | ||
let contextToken: string; | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
contextToken = random.uuid(); | ||
update({ contextToken }); | ||
}); | ||
afterEach(() => { | ||
expect(config.contextToken).toEqual(contextToken); | ||
}); | ||
|
||
it("rejects the promise if the email do not mach any in Sales Channel", async () => { | ||
mockedAxios.post.mockRejectedValueOnce( | ||
new Error("400 - invalid email address") | ||
); | ||
expect( | ||
resetPassword({ | ||
email: credentials.email, | ||
storefrontUrl: credentials.storefrontUrl, | ||
}) | ||
).rejects.toThrow("400 - invalid email"); | ||
expect(mockedAxios.post).toBeCalledTimes(1); | ||
expect(mockedAxios.post).toBeCalledWith( | ||
getCustomerResetPasswordEndpoint(), | ||
{ | ||
email: credentials.email, | ||
storefrontUrl: credentials.storefrontUrl, | ||
} | ||
); | ||
}); | ||
|
||
it("returns no data if successfully updated", async () => { | ||
mockedAxios.post.mockResolvedValueOnce(null); | ||
|
||
const resultWithFullParams = await resetPassword({ | ||
email: credentials.email, | ||
storefrontUrl: credentials.storefrontUrl, | ||
}); | ||
expect(resultWithFullParams).toBeFalsy(); | ||
|
||
const resultWithEmptyUrl = await resetPassword({ | ||
email: credentials.email, | ||
storefrontUrl: "", | ||
}); | ||
expect(resultWithEmptyUrl).toBeFalsy(); | ||
|
||
const resultWithoutUrl = await resetPassword({ | ||
email: credentials.email, | ||
}); | ||
expect(resultWithoutUrl).toBeFalsy(); | ||
|
||
expect(mockedAxios.post).toBeCalledTimes(3); | ||
expect(mockedAxios.post).toBeCalledWith( | ||
getCustomerResetPasswordEndpoint(), | ||
{ | ||
email: credentials.email, | ||
storefrontUrl: credentials.storefrontUrl, | ||
} | ||
); | ||
}); | ||
|
||
it("should set storefrontUrl from config if not provided with params ", async () => { | ||
await resetPassword({ | ||
email: credentials.email, | ||
}); | ||
expect(mockedAxios.post).toBeCalledWith( | ||
"/store-api/v1/account/recovery-password", | ||
{ | ||
email: credentials.email, | ||
storefrontUrl: "https://shopware6-demo.vuestorefront.io", | ||
} | ||
); | ||
}); | ||
|
||
it("should invokde post method with null if params are not provided", async () => { | ||
await resetPassword(null as any); | ||
expect(mockedAxios.post).toBeCalledWith( | ||
"/store-api/v1/account/recovery-password", | ||
null | ||
); | ||
}); | ||
}); |
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
e01a8fe
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 following URLs: