Fix signup component and test

This commit is contained in:
Wolfgang Huß 2021-03-22 14:53:14 +01:00
parent a5d4dc50a6
commit a8cfdf8192
3 changed files with 45 additions and 42 deletions

View File

@ -58,7 +58,8 @@ describe('Signup', () => {
it('delivers email to backend', () => {
const expected = expect.objectContaining({
variables: { email: 'mAIL@exAMPLE.org', token: null },
mutation: SignupMutation,
variables: { email: 'mAIL@exAMPLE.org', inviteCode: null },
})
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expected)
})
@ -84,45 +85,5 @@ describe('Signup', () => {
})
})
})
describe('with invitation code', () => {
let action
beforeEach(() => {
propsData.token = '666777'
action = async () => {
wrapper = Wrapper()
wrapper.find('input#email').setValue('mail@example.org')
await wrapper.find('form').trigger('submit')
await wrapper.html()
}
})
describe('submit', () => {
it('delivers invitation token to backend', async () => {
await action()
const expected = expect.objectContaining({
variables: { email: 'mail@example.org', token: '666777' },
})
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expected)
})
describe('in case a user account with the email already exists', () => {
beforeEach(() => {
mocks.$apollo.mutate = jest
.fn()
.mockRejectedValue(
new Error('UserInputError: A user account with this email already exists.'),
)
})
it('explains the error', async () => {
await action()
expect(mocks.$t).toHaveBeenCalledWith(
'components.registration.signup.form.errors.email-exists',
)
})
})
})
})
})
})

View File

@ -119,7 +119,7 @@ export default {
try {
const response = await this.$apollo.mutate({
SignupMutation,
mutation: SignupMutation,
variables: { email, inviteCode: null },
})
this.data = response.data

View File

@ -147,5 +147,47 @@ describe('Registration', () => {
})
})
})
// Wolle copied from webapp/components/Registration/Signup.spec.js as testing template
// describe('with invitation code', () => {
// let action
// beforeEach(() => {
// propsData.token = '12345'
// action = async () => {
// wrapper = Wrapper()
// wrapper.find('input#email').setValue('mail@example.org')
// await wrapper.find('form').trigger('submit')
// await wrapper.html()
// }
// })
// describe('submit', () => {
// it('delivers invitation code to backend', async () => {
// await action()
// const expected = expect.objectContaining({
// mutation: SignupMutation,
// variables: { email: 'mail@example.org', inviteCode: '12345' },
// })
// expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expected)
// })
// describe('in case a user account with the email already exists', () => {
// beforeEach(() => {
// mocks.$apollo.mutate = jest
// .fn()
// .mockRejectedValue(
// new Error('UserInputError: A user account with this email already exists.'),
// )
// })
// it('explains the error', async () => {
// await action()
// expect(mocks.$t).toHaveBeenCalledWith(
// 'components.registration.signup.form.errors.email-exists',
// )
// })
// })
// })
// })
})
})