refactor: use email of backend response in Signup

This commit is contained in:
roschaefer 2019-11-05 14:24:02 +01:00
parent 0cf59743ab
commit 2a53eb2e6c
2 changed files with 10 additions and 14 deletions

View File

@ -48,7 +48,7 @@ describe('Signup', () => {
describe('submit', () => { describe('submit', () => {
beforeEach(async () => { beforeEach(async () => {
wrapper = Wrapper() wrapper = Wrapper()
wrapper.find('input#email').setValue('mail@example.org') wrapper.find('input#email').setValue('mAIL@exAMPLE.org')
await wrapper.find('form').trigger('submit') await wrapper.find('form').trigger('submit')
}) })
@ -59,7 +59,7 @@ describe('Signup', () => {
it('delivers email to backend', () => { it('delivers email to backend', () => {
const expected = expect.objectContaining({ const expected = expect.objectContaining({
variables: { email: 'mail@example.org', token: null }, variables: { email: 'mAIL@exAMPLE.org', token: null },
}) })
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expected) expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expected)
}) })

View File

@ -1,5 +1,5 @@
<template> <template>
<ds-space v-if="!success && !error" margin="large"> <ds-space v-if="!data && !error" margin="large">
<ds-form <ds-form
@input="handleInput" @input="handleInput"
@input-valid="handleInputValid" @input-valid="handleInputValid"
@ -63,7 +63,6 @@
<script> <script>
import gql from 'graphql-tag' import gql from 'graphql-tag'
import { SweetalertIcon } from 'vue-sweetalert-icons' import { SweetalertIcon } from 'vue-sweetalert-icons'
import { normalizeEmail } from 'validator'
export const SignupMutation = gql` export const SignupMutation = gql`
mutation($email: String!) { mutation($email: String!) {
@ -101,16 +100,13 @@ export default {
}, },
}, },
disabled: true, disabled: true,
success: false, data: null,
error: null, error: null,
} }
}, },
computed: { computed: {
email() {
return normalizeEmail(this.formData.email)
},
submitMessage() { submitMessage() {
const { email } = this const { email } = this.data.Signup
return this.$t('components.registration.signup.form.success', { email }) return this.$t('components.registration.signup.form.success', { email })
}, },
}, },
@ -123,14 +119,14 @@ export default {
}, },
async handleSubmit() { async handleSubmit() {
const mutation = this.token ? SignupByInvitationMutation : SignupMutation const mutation = this.token ? SignupByInvitationMutation : SignupMutation
const { email, token } = this const { token } = this
const { email } = this.formData
try { try {
await this.$apollo.mutate({ mutation, variables: { email, token } }) const response = await this.$apollo.mutate({ mutation, variables: { email, token } })
this.success = true this.data = response.data
setTimeout(() => { setTimeout(() => {
this.$emit('submit', { email }) this.$emit('submit', { email: this.data.Signup.email })
}, 3000) }, 3000)
} catch (err) { } catch (err) {
const { message } = err const { message } = err