VerifyCode.spec passes

This commit is contained in:
Robert Schäfer 2019-06-18 13:48:30 +02:00
parent 559210d204
commit 3948cb8ace
4 changed files with 90 additions and 37 deletions

View File

@ -26,6 +26,8 @@ describe('VerifyCode ', () => {
})
describe('mount', () => {
beforeEach(jest.useFakeTimers)
Wrapper = () => {
return mount(VerifyCode, {
mocks,
@ -62,15 +64,25 @@ describe('VerifyCode ', () => {
})
it('delivers new password to backend', () => {
const expected = expect.objectContaining({ variables: { newPassword: 'supersecret' } })
const expected = expect.objectContaining({
variables: { token: '123456', email: 'mail@example.org', newPassword: 'supersecret' },
})
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expected)
})
describe('password reset successful', () => {
it('displays success message', () => {
const expected = 'verify-code.change-password.sucess'
const expected = 'verify-code.form.change-password.success'
expect(mocks.$t).toHaveBeenCalledWith(expected)
})
describe('after animation', () => {
beforeEach(jest.runAllTimers)
it('emits `change-password-sucess`', () => {
expect(wrapper.emitted('change-password-result')).toEqual([['success']])
})
})
})
})
})

View File

@ -32,8 +32,9 @@
{{ $t('verify-code.form.submit') }}
</ds-button>
</ds-form>
<template v-else>
<ds-form
v-else
v-if="!changePasswordResult"
v-model="password.formData"
:schema="password.formSchema"
@submit="handleSubmitPassword"
@ -62,12 +63,18 @@
</ds-button>
</ds-space>
</ds-form>
<ds-text v-else>
{{ changePasswordResultMessage }}
</ds-text>
</template>
</ds-space>
</ds-card>
</template>
<script>
import PasswordStrength from '../Password/Strength'
import gql from 'graphql-tag'
export default {
components: {
PasswordStrength,
@ -119,19 +126,53 @@ export default {
},
verificationSubmitted: false,
disabled: true,
changePasswordResult: null,
}
},
computed: {
changePasswordResultMessage() {
if (!this.changePasswordResult) return ''
return this.$t(`verify-code.form.change-password.${this.changePasswordResult}`)
},
},
methods: {
async handleInput(data) {
async handleInput() {
this.disabled = true
},
async handleInputValid(data) {
async handleInputValid() {
this.disabled = false
},
handleSubmitVerify() {
this.verificationSubmitted = true
},
handleSubmitPassword() {},
async handleSubmitPassword() {
const mutation = gql`
mutation($token: String!, $email: String!, $newPassword: String!) {
resetPassword(token: $token, email: $email, newPassword: $newPassword)
}
`
const { newPassword } = this.password.formData
const { email, code: token } = this.verification.formData
const variables = { newPassword, email, token }
try {
const {
data: { resetPassword },
} = await this.$apollo.mutate({ mutation, variables })
const changePasswordResult = resetPassword ? 'success' : 'failure'
this.changePasswordResult = changePasswordResult
this.$emit('change-password-result', changePasswordResult)
this.verification.formData = {
code: '',
email: '',
}
this.password.formData = {
newPassword: '',
confirmPassword: '',
}
} catch (err) {
this.$toast.error(err.message)
}
},
matchPassword(rule, value, callback, source, options) {
var errors = []
if (this.password.formData.newPassword !== value) {

View File

@ -29,7 +29,7 @@
"submit": "Sicherheitscode überprüfen",
"change-password":{
"success": "Änderung des Passworts war erfolgreich",
"failure": "Passwort Änderung fehlgeschlagen. Möglicherweise falscher Sicherheitscode."
"failure": "Passwort Änderung fehlgeschlagen. Möglicherweise falscher Sicherheitscode?"
}
}
},

View File

@ -29,7 +29,7 @@
"submit": "Check security code",
"change-password": {
"success": "Changing your password was successful",
"failure": "Changing your password failed. Probably the security code was not correct"
"failure": "Changing your password failed. Maybe the security code was not correct?"
}
}
},