diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index 632a63bf3..9405e1631 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -107,3 +107,11 @@ export const sendCoins = gql` sendCoins(sessionId: $sessionId, email: $email, amount: $amount, memo: $memo) } ` + +export const sendResetPasswordEmail = gql` + query($email: String!) { + sendResetPasswordEmail(email: $email) { + state + } + } +` diff --git a/frontend/src/views/Pages/ForgotPassword.spec.js b/frontend/src/views/Pages/ForgotPassword.spec.js index df60568b9..d4615c221 100644 --- a/frontend/src/views/Pages/ForgotPassword.spec.js +++ b/frontend/src/views/Pages/ForgotPassword.spec.js @@ -1,12 +1,8 @@ import { mount, RouterLinkStub } from '@vue/test-utils' import flushPromises from 'flush-promises' -import loginAPI from '../../apis/loginAPI.js' import ForgotPassword from './ForgotPassword' -jest.mock('../../apis/loginAPI.js') - const mockAPIcall = jest.fn() -loginAPI.sendEmail = mockAPIcall const localVue = global.localVue @@ -20,6 +16,9 @@ describe('ForgotPassword', () => { $router: { push: mockRouterPush, }, + $apollo: { + query: mockAPIcall, + }, } const stubs = { @@ -92,18 +91,56 @@ describe('ForgotPassword', () => { }) describe('valid Email', () => { - beforeEach(async () => { - await form.find('input').setValue('user@example.org') - await form.trigger('submit') - await flushPromises() + beforeEach(() => { + form.find('input').setValue('user@example.org') }) - it('calls the API', () => { - expect(mockAPIcall).toHaveBeenCalledWith('user@example.org') - }) + describe('calls the API', () => { + describe('sends back error', () => { + beforeEach(async () => { + mockAPIcall.mockRejectedValue({ + message: 'error', + }) + await form.trigger('submit') + await flushPromises() + }) - it('pushes "/thx/password" to the route', () => { - expect(mockRouterPush).toHaveBeenCalledWith('/thx/password') + it('pushes to "/thx/password"', () => { + expect(mockAPIcall).toBeCalledWith( + expect.objectContaining({ + variables: { + email: 'user@example.org', + }, + }), + ) + expect(mockRouterPush).toHaveBeenCalledWith('/thx/password') + }) + }) + + describe('success', () => { + beforeEach(async () => { + mockAPIcall.mockResolvedValue({ + data: { + sendResetPasswordEmail: { + state: 'success', + }, + }, + }) + await form.trigger('submit') + await flushPromises() + }) + + it('pushes to "/thx/password"', () => { + expect(mockAPIcall).toBeCalledWith( + expect.objectContaining({ + variables: { + email: 'user@example.org', + }, + }), + ) + expect(mockRouterPush).toHaveBeenCalledWith('/thx/password') + }) + }) }) }) }) diff --git a/frontend/src/views/Pages/ForgotPassword.vue b/frontend/src/views/Pages/ForgotPassword.vue index db4bf2e5e..4d4fe4c80 100644 --- a/frontend/src/views/Pages/ForgotPassword.vue +++ b/frontend/src/views/Pages/ForgotPassword.vue @@ -38,7 +38,7 @@