Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

feat: reset password feature #756

Merged
merged 8 commits into from
May 25, 2020

Conversation

mmularski
Copy link
Collaborator

@mmularski mmularski commented May 19, 2020

Changes

Closes #667

image

image

Checklist

@vercel vercel bot temporarily deployed to preview May 19, 2020 14:28 Inactive
@vercel
Copy link

vercel bot commented May 19, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/shopware-pwa/shopware-pwa-docs/ilc6mk9te
✅ Preview: https://shopware-pwa-docs-git-fork-mmularski-feat-reset-password.shopware-pwa.now.sh

@rmakara
Copy link
Collaborator

rmakara commented May 19, 2020

@mmularski
Thanks for your contribution! :)

Is "No matching customer for the email..." message returned from Shopware 6 API or it is somehow validated on Shopware PWA end? A common practice is to always return a successful resetting message in a way "If your user account really exists then check your email for the link to reset a password.". No matter if an account exists or not.

@mmularski
Copy link
Collaborator Author

@rmakara

It is Shopware API response.

Copy link
Collaborator

@patzick patzick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice start! Just one thing with checking storefrontUrl in params.
Also, tests are not passing so I cannot see coverage. Please see page for this build: https://app.circleci.com/pipelines/github/DivanteLtd/shopware-pwa/731/workflows/bf914308-47a4-4933-81c0-b1eaafa66940/jobs/747
You should be able to run yarn test locally to see if tests are passing and coverage result :)

Also, I agree with @rmakara and prepared #764 Shopware Task for this, as it's the API part to fix.

@mmularski what are you displaying if operation ends successfully?

export async function resetPassword(
params: CustomerResetPasswordParam
): Promise<void> {
if (!params.storefrontUrl) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of params being null we should prevent error.

Suggested change
if (!params.storefrontUrl) {
if (!params?.storefrontUrl) {

more about: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#optional-chaining
This will require to add unit test invoking method with no params like

const result = await resetPassword(null as any);

Copy link
Collaborator Author

@mmularski mmularski May 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I have added optional chaining here but it makes a problem with branch coverage due to
    Optional chaining does not count as branch for coverage istanbuljs/istanbuljs#516

Just added a workaround with /* istanbul ignore next */ FYI :)

This will require to add unit test invoking method with no params like
const result = await resetPassword(null as any);

I do not get this. null as any will cause TypeError due to inconsistency with CustomerResetPasswordParam or I just do not understand something? :D

  1. After a successful operation, modal just closes and email is sending. I was modeling on login operation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what I meant with this test, turned out it has to be another if statement. What we needed to test:

  1. invocation with no parameter provided
  2. invocation without any parameters provided

please take a look at this commit: 29bc328

Why should we test for 2? Because library compiles to JS and someone might unintentionally ignore param for method. We need to be resistant to this kind of behaviour:)

Comment on lines +502 to +504
mockedApiClient.resetPassword.mockImplementationOnce(async () =>
Promise.resolve(undefined)
);
Copy link
Collaborator

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

Copy link
Collaborator Author

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 :)

@vercel vercel bot temporarily deployed to preview May 20, 2020 11:28 Inactive
@vercel vercel bot temporarily deployed to preview May 21, 2020 06:54 Inactive
@vercel vercel bot temporarily deployed to preview May 21, 2020 09:26 Inactive
@vercel vercel bot temporarily deployed to preview May 21, 2020 09:44 Inactive
@patzick
Copy link
Collaborator

patzick commented May 21, 2020

After a successful operation, modal just closes and email is sending. I was modeling on login operation.

After successful invocation (no API error) please hide email input and button, the display below message and let the user close the modal by himself. When he'll get this feedback on the action he knows what happened and what should he expect next :)

After this, PR is ready as everything else looks 👌

Message:

You should receive a link in a few moments. Please open that link to reset your password.

@vercel vercel bot requested a deployment to Preview May 25, 2020 04:42 Abandoned
@vercel
Copy link

vercel bot commented May 25, 2020

Deployment failed with the following error:

request to https://api.vercel.com/v12/now/deployments?teamId=team_zpOFzrZjyURkFwGZsKEEHzcv&skipAutoDetectionConfirmation=1 failed, reason: socket hang up

@mmularski
Copy link
Collaborator Author

@patzick fixed. Now after a successful operation, modal looks like below

image

@mmularski mmularski requested a review from patzick May 25, 2020 04:57
Copy link
Collaborator

@patzick patzick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 Cool! Thanks for contribution :)

@vercel vercel bot temporarily deployed to preview May 25, 2020 12:19 Inactive
@patzick patzick merged commit e01a8fe into vuestorefront:master May 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Reset password
3 participants