diff --git a/admin/src/components/CreationFormular.spec.js b/admin/src/components/CreationFormular.spec.js index 5b0ac09f5..b3807b16f 100644 --- a/admin/src/components/CreationFormular.spec.js +++ b/admin/src/components/CreationFormular.spec.js @@ -1,5 +1,7 @@ import { mount } from '@vue/test-utils' import CreationFormular from './CreationFormular.vue' +import { createPendingCreation } from '../graphql/createPendingCreation' +import { createPendingCreations } from '../graphql/createPendingCreations' const localVue = global.localVue @@ -145,10 +147,14 @@ describe('CreationFormular', () => { describe('with single creation', () => { beforeEach(async () => { jest.clearAllMocks() - await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) - await wrapper.setData({ rangeMin: 180 }) - await wrapper.setData({ text: 'Test create coins' }) - await wrapper.setData({ value: 90 }) + await wrapper.setProps({ + type: 'singleCreation', + creation: [200, 400, 600], + item: { email: 'benjamin@bluemchen.de' }, + }) + await wrapper.findAll('input[type="radio"]').at(1).setChecked() + await wrapper.find('textarea').setValue('Test create coins') + await wrapper.find('input[type="number"]').setValue(90) }) describe('first radio button', () => { @@ -156,12 +162,8 @@ describe('CreationFormular', () => { await wrapper.findAll('input[type="radio"]').at(0).setChecked() }) - it('sets rangeMin to 0', () => { - expect(wrapper.vm.rangeMin).toBe(0) - }) - it('sets rangeMax to 200', () => { - expect(wrapper.vm.rangeMax).toBe(200) + expect(wrapper.vm.rangeMax).toBe(400) }) describe('sendForm', () => { @@ -170,7 +172,18 @@ describe('CreationFormular', () => { }) it('sends ... to apollo', () => { - expect(apolloMutateMock).toBeCalled() + expect(apolloMutateMock).toBeCalledWith( + expect.objectContaining({ + mutation: createPendingCreation, + variables: { + email: 'benjamin@bluemchen.de', + creationDate: 'YYYY-MM-01', + amount: 90, + memo: 'Test create coins', + moderator: 0, + }, + }), + ) }) }) @@ -359,6 +372,47 @@ describe('CreationFormular', () => { }) }) }) + + describe('with mass creation', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ + type: 'massCreation', + creation: [200, 400, 600], + items: [{ email: 'bob@baumeister.de' }, { email: 'bibi@bloxberg.de' }], + }) + await wrapper.findAll('input[type="radio"]').at(1).setChecked() + await wrapper.find('textarea').setValue('Test mass create coins') + await wrapper.find('input[type="number"]').setValue(200) + await wrapper.find('.test-submit').trigger('click') + }) + + it('calls the API', () => { + expect(apolloMutateMock).toBeCalledWith( + expect.objectContaining({ + mutation: createPendingCreations, + variables: { + pendingCreations: [ + { + email: 'bob@baumeister.de', + creationDate: 'YYYY-MM-01', + amount: 200, + memo: 'Test mass create coins', + moderator: 0, + }, + { + email: 'bibi@bloxberg.de', + creationDate: 'YYYY-MM-01', + amount: 200, + memo: 'Test mass create coins', + moderator: 0, + }, + ], + }, + }), + ) + }) + }) }) }) }) diff --git a/admin/src/components/UserTable.spec.js b/admin/src/components/UserTable.spec.js index e26a548cc..4910c7e80 100644 --- a/admin/src/components/UserTable.spec.js +++ b/admin/src/components/UserTable.spec.js @@ -192,8 +192,10 @@ describe('UserTable', () => { expect(wrapper.findAll('tr:nth-child(1) > td').length).toBe(7) }) - it('click button on fifth column', () => { - wrapper.find('tbody tr td[aria-colindex="5"] button').trigger('click') + it('find button on fifth column', () => { + expect( + wrapper.findAll('tr:nth-child(1) > td').at(5).find('button').isVisible(), + ).toBeTruthy() }) }) }) diff --git a/admin/src/components/UserTable.vue b/admin/src/components/UserTable.vue index 22fadafa2..c0c288e25 100644 --- a/admin/src/components/UserTable.vue +++ b/admin/src/components/UserTable.vue @@ -47,7 +47,13 @@ diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 9ca558a9c..e02d23b4c 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -61,7 +61,10 @@ export class AdminResolver { ): Promise { const userRepository = getCustomRepository(UserRepository) const user = await userRepository.findByEmail(email) - + const isActivated = await hasActivatedEmail(user.email) + if (!isActivated) { + throw new Error('Creation could not be saved, Email is not activated') + } const creations = await getUserCreations(user.id) const creationDateObj = new Date(creationDate) if (isCreationValid(creations, amount, creationDateObj)) {