diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b7000100e..34ebeff11 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -528,7 +528,7 @@ jobs: report_name: Coverage Backend type: lcov result_path: ./backend/coverage/lcov.info - min_coverage: 68 + min_coverage: 74 token: ${{ github.token }} ########################################################################## diff --git a/admin/src/components/ContributionLink.spec.js b/admin/src/components/ContributionLink.spec.js index f1b9cfb97..9818e8b93 100644 --- a/admin/src/components/ContributionLink.spec.js +++ b/admin/src/components/ContributionLink.spec.js @@ -5,6 +5,7 @@ const localVue = global.localVue const mocks = { $t: jest.fn((t) => t), + $d: jest.fn((d) => d), } const propsData = { diff --git a/admin/src/components/ContributionLinkForm.spec.js b/admin/src/components/ContributionLinkForm.spec.js index 7182fb2e9..2baefcbe2 100644 --- a/admin/src/components/ContributionLinkForm.spec.js +++ b/admin/src/components/ContributionLinkForm.spec.js @@ -1,6 +1,7 @@ import { mount } from '@vue/test-utils' import ContributionLinkForm from './ContributionLinkForm.vue' -import { toastErrorSpy } from '../../test/testSetup' +import { toastErrorSpy, toastSuccessSpy } from '../../test/testSetup' +import { createContributionLink } from '@/graphql/createContributionLink.js' const localVue = global.localVue @@ -72,48 +73,70 @@ describe('ContributionLinkForm', () => { }) }) - // describe('successfull submit', () => { - // beforeEach(async () => { - // mockAPIcall.mockResolvedValue({ - // data: { - // createContributionLink: { - // link: 'https://localhost/redeem/CL-1a2345678', - // }, - // }, - // }) - // await wrapper.find('input.test-validFrom').setValue('2022-6-18') - // await wrapper.find('input.test-validTo').setValue('2022-7-18') - // await wrapper.find('input.test-name').setValue('test name') - // await wrapper.find('input.test-memo').setValue('test memo') - // await wrapper.find('input.test-amount').setValue('100') - // await wrapper.find('form').trigger('submit') - // }) + describe('successfull submit', () => { + beforeEach(async () => { + apolloMutateMock.mockResolvedValue({ + data: { + createContributionLink: { + link: 'https://localhost/redeem/CL-1a2345678', + }, + }, + }) + await wrapper + .findAllComponents({ name: 'BFormDatepicker' }) + .at(0) + .vm.$emit('input', '2022-6-18') + await wrapper + .findAllComponents({ name: 'BFormDatepicker' }) + .at(1) + .vm.$emit('input', '2022-7-18') + await wrapper.find('input.test-name').setValue('test name') + await wrapper.find('textarea.test-memo').setValue('test memo') + await wrapper.find('input.test-amount').setValue('100') + await wrapper.find('form').trigger('submit') + }) - // it('calls the API', () => { - // expect(mockAPIcall).toHaveBeenCalledWith( - // expect.objectContaining({ - // variables: { - // link: 'https://localhost/redeem/CL-1a2345678', - // }, - // }), - // ) - // }) + it('calls the API', () => { + expect(apolloMutateMock).toHaveBeenCalledWith({ + mutation: createContributionLink, + variables: { + validFrom: '2022-6-18', + validTo: '2022-7-18', + name: 'test name', + amount: '100', + memo: 'test memo', + cycle: 'ONCE', + maxPerCycle: 1, + maxAmountPerMonth: '0', + }, + }) + }) - // it('displays the new username', () => { - // expect(wrapper.find('div.display-username').text()).toEqual('@username') - // }) - // }) - }) - - describe('send createContributionLink with error', () => { - beforeEach(() => { - apolloMutateMock.mockRejectedValue({ message: 'OUCH!' }) - wrapper = Wrapper() - wrapper.vm.onSubmit() + it('toasts a succes message', () => { + expect(toastSuccessSpy).toBeCalledWith('https://localhost/redeem/CL-1a2345678') + }) }) - it('toasts an error message', () => { - expect(toastErrorSpy).toBeCalledWith('contributionLink.noStartDate') + describe('send createContributionLink with error', () => { + beforeEach(async () => { + apolloMutateMock.mockRejectedValue({ message: 'OUCH!' }) + await wrapper + .findAllComponents({ name: 'BFormDatepicker' }) + .at(0) + .vm.$emit('input', '2022-6-18') + await wrapper + .findAllComponents({ name: 'BFormDatepicker' }) + .at(1) + .vm.$emit('input', '2022-7-18') + await wrapper.find('input.test-name').setValue('test name') + await wrapper.find('textarea.test-memo').setValue('test memo') + await wrapper.find('input.test-amount').setValue('100') + await wrapper.find('form').trigger('submit') + }) + + it('toasts an error message', () => { + expect(toastErrorSpy).toBeCalledWith('OUCH!') + }) }) }) }) diff --git a/admin/src/components/ContributionLinkForm.vue b/admin/src/components/ContributionLinkForm.vue index 6daf1e299..c21a7f17c 100644 --- a/admin/src/components/ContributionLinkForm.vue +++ b/admin/src/components/ContributionLinkForm.vue @@ -1,8 +1,5 @@