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
feat: reset password feature #756
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b89e454
feat: reset password feature
mmularski 97873d2
Merge branch 'master' into feat-reset-password
patzick d78bd6e
feat: reset password code review
mmularski da34dfc
Merge branch 'feat-reset-password' of github.com:mmularski/shopware-p…
mmularski 461d079
Merge branch 'master' into feat-reset-password
patzick 29bc328
fix: tests coverage
patzick ba7ac6d
feat: successful password reset adjustment
mmularski 43927cb
Merge branch 'master' into feat-reset-password
patzick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this is perfectly okay, more educational improvement here you can do
https://jestjs.io/docs/en/mock-function-api#mockfnmockreturnvalueoncevalue
and in case of mocking rejections like in line 513
https://jestjs.io/docs/en/mock-function-api#mockfnmockrejectedvalueoncevalue
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.
Some good hints. Thank you :)