diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 581c8d850..7e07cc8d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -441,7 +441,7 @@ jobs: report_name: Coverage Admin Interface type: lcov result_path: ./coverage/lcov.info - min_coverage: 55 + min_coverage: 60 token: ${{ github.token }} ############################################################################## @@ -657,4 +657,4 @@ jobs: - name: database | up run: docker-compose -f docker-compose.yml run -T database yarn up - name: database | reset - run: docker-compose -f docker-compose.yml run -T database yarn reset \ No newline at end of file + run: docker-compose -f docker-compose.yml run -T database yarn reset diff --git a/admin/src/components/CreationFormular.spec.js b/admin/src/components/CreationFormular.spec.js index e1bbff1cc..f6bd1a924 100644 --- a/admin/src/components/CreationFormular.spec.js +++ b/admin/src/components/CreationFormular.spec.js @@ -11,7 +11,14 @@ const apolloMock = jest.fn().mockResolvedValue({ }, }, }) +const apolloMutateMock = jest.fn().mockResolvedValue({ + data: { + createPendingCreation: [0, 0, 0], + }, +}) const stateCommitMock = jest.fn() +const toastedErrorMock = jest.fn() +const toastedSuccessMock = jest.fn() const mocks = { $moment: jest.fn(() => { @@ -26,15 +33,25 @@ const mocks = { }), $apollo: { query: apolloMock, + mutate: apolloMutateMock, }, $store: { commit: stateCommitMock, + state: { + moderator: { + id: 0, + name: 'test moderator', + }, + }, + }, + $toasted: { + error: toastedErrorMock, + success: toastedSuccessMock, }, } const propsData = { type: '', - item: {}, creation: [], itemsMassCreation: {}, } @@ -64,9 +81,10 @@ describe('CreationFormular', () => { describe('server throws error for moderator data call', () => { beforeEach(() => { jest.clearAllMocks() - apolloMock.mockRejectedValue({ message: 'Ouch!' }) + apolloMock.mockRejectedValueOnce({ message: 'Ouch!' }) wrapper = Wrapper() }) + it('has called store commit with fake data', () => { expect(stateCommitMock).toBeCalledWith('moderator', { id: 0, name: 'Test Moderator' }) }) @@ -125,6 +143,8 @@ describe('CreationFormular', () => { 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 }) }) describe('first radio button', () => { @@ -139,6 +159,66 @@ describe('CreationFormular', () => { it('sets rangeMax to 200', () => { expect(wrapper.vm.rangeMax).toBe(200) }) + + describe('sendForm', () => { + beforeEach(async () => { + await wrapper.find('.test-submit').trigger('click') + }) + + it('sends ... to apollo', () => { + expect(apolloMutateMock).toBeCalled() + }) + }) + + describe('sendForm', () => { + beforeEach(async () => { + apolloMutateMock.mockRejectedValueOnce({ message: 'Ouch!' }) + await wrapper.find('.test-submit').trigger('click') + }) + + it('sends ... to apollo', () => { + expect(toastedErrorMock).toBeCalled() + }) + }) + + describe('Negativ value', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ value: -20 }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) + + describe('Empty text', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ text: '' }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) + + describe('Text length less than 10', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ text: 'Try this' }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) }) describe('second radio button', () => { @@ -153,6 +233,55 @@ describe('CreationFormular', () => { it('sets rangeMax to 400', () => { expect(wrapper.vm.rangeMax).toBe(400) }) + + describe('sendForm', () => { + beforeEach(async () => { + await wrapper.find('.test-submit').trigger('click') + }) + + it('sends ... to apollo', () => { + expect(apolloMutateMock).toBeCalled() + }) + }) + + describe('Negativ value', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ value: -20 }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) + + describe('Empty text', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ text: '' }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) + + describe('Text length less than 10', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ text: 'Try this' }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) }) describe('third radio button', () => { @@ -167,6 +296,63 @@ describe('CreationFormular', () => { it('sets rangeMax to 400', () => { expect(wrapper.vm.rangeMax).toBe(600) }) + + describe('sendForm', () => { + beforeEach(async () => { + await wrapper.find('.test-submit').trigger('click') + }) + + it('sends mutation to apollo', () => { + expect(apolloMutateMock).toBeCalled() + }) + + it('toast success message', () => { + expect(toastedSuccessMock).toBeCalled() + }) + + it('store commit openCreationPlus', () => { + expect(stateCommitMock).toBeCalledWith('openCreationsPlus', 1) + }) + }) + + describe('Negativ value', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ value: -20 }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) + + describe('Empty text', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ text: '' }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) + + describe('Text length less than 10', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ text: 'Try this' }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) }) }) }) diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index 7fb3af514..d73ea3c81 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -6,6 +6,7 @@ - +
@@ -92,6 +95,7 @@ v-if="pagetype === 'PageCreationConfirm'" type="button" variant="success" + class="test-submit" @click="submitCreation" :disabled="radioSelected === '' || value <= 0 || text.length < 10" > @@ -102,6 +106,7 @@ v-else type="button" variant="success" + class="test-submit" @click="submitCreation" :disabled="radioSelected === '' || value <= 0 || text.length < 10" > @@ -159,7 +164,7 @@ export default { return { radioSelected: '', text: !this.creationUserData.memo ? '' : this.creationUserData.memo, - value: !this.creationUserData.amount ? 0 : this.creationUserData.amount / 10000, + value: !this.creationUserData.amount ? 0 : this.creationUserData.amount, rangeMin: 0, rangeMax: 1000, currentMonth: { @@ -195,28 +200,12 @@ export default { } }, submitCreation() { - // Formular Prüfen ob ein Zeitraum ausgewählt wurde. Ansonsten abbrechen und Hinweis anzeigen - if (this.radioSelected === '') { - return alert('Bitte wähle einen Zeitraum!') - } - // Formular Prüfen ob der GDD Betrag grösser 0 ist. Ansonsten abbrechen und Hinweis anzeigen - if (this.value === 0) { - return alert('Bitte gib einen GDD Betrag an!') - } - // Formular Prüfen ob der Text vorhanden ist. Ansonsten abbrechen und Hinweis anzeigen - if (this.text === '') { - return alert('Bitte gib einen Text ein!') - } - // Formular Prüfen ob der Text länger als 10 Zeichen hat. Ansonsten abbrechen und Hinweis anzeigen - if (this.text.length < 10) { - return alert('Bitte gib einen Text ein der länger als 10 Zeichen ist!') - } - if (this.type === 'massCreation') { // Die anzahl der Mitglieder aus der Mehrfachschöpfung const i = Object.keys(this.itemsMassCreation).length // hinweis das eine Mehrfachschöpfung ausgeführt wird an (Anzahl der MItgleider an die geschöpft wird) - alert('SUBMIT CREATION => ' + this.type + ' >> für VIELE ' + i + ' Mitglieder') + // eslint-disable-next-line no-console + console.log('SUBMIT CREATION => ' + this.type + ' >> für VIELE ' + i + ' Mitglieder') this.submitObj = [ { item: this.itemsMassCreation, @@ -227,7 +216,8 @@ export default { moderator: this.$store.state.moderator.id, }, ] - alert('MehrfachSCHÖPFUNG ABSENDEN FÜR >> ' + i + ' Mitglieder') + // eslint-disable-next-line no-console + console.log('MehrfachSCHÖPFUNG ABSENDEN FÜR >> ' + i + ' Mitglieder') // $store - offene Schöpfungen hochzählen this.$store.commit('openCreationsPlus', i) diff --git a/admin/src/components/EditCreationFormular.spec.js b/admin/src/components/EditCreationFormular.spec.js index 61536dab2..50704ed76 100644 --- a/admin/src/components/EditCreationFormular.spec.js +++ b/admin/src/components/EditCreationFormular.spec.js @@ -15,6 +15,7 @@ const apolloMutateMock = jest.fn().mockResolvedValue({ }) const stateCommitMock = jest.fn() +const toastedErrorMock = jest.fn() const mocks = { $moment: jest.fn(() => { @@ -31,14 +32,21 @@ const mocks = { mutate: apolloMutateMock, }, $store: { + state: { + moderator: { + id: 0, + name: 'test moderator', + }, + }, commit: stateCommitMock, }, + $toasted: { + error: toastedErrorMock, + }, } const propsData = { type: '', - item: {}, - row: [], creation: [], itemsMassCreation: {}, } @@ -69,6 +77,8 @@ describe('EditCreationFormular', () => { 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 }) }) describe('first radio button', () => { @@ -83,6 +93,27 @@ describe('EditCreationFormular', () => { it('sets rangeMax to 200', () => { expect(wrapper.vm.rangeMax).toBe(200) }) + + describe('sendForm', () => { + beforeEach(async () => { + await wrapper.find('.test-submit').trigger('click') + }) + + it('sends ... to apollo', () => { + expect(apolloMutateMock).toBeCalledWith( + expect.objectContaining({ + variables: { + amount: 90, + creationDate: 'YYYY-MM-01', + email: undefined, + id: undefined, + memo: 'Test create coins', + moderator: 0, + }, + }), + ) + }) + }) }) describe('second radio button', () => { @@ -97,6 +128,27 @@ describe('EditCreationFormular', () => { it('sets rangeMax to 400', () => { expect(wrapper.vm.rangeMax).toBe(400) }) + + describe('sendForm', () => { + beforeEach(async () => { + await wrapper.find('.test-submit').trigger('click') + }) + + it('sends ... to apollo', () => { + expect(apolloMutateMock).toBeCalledWith( + expect.objectContaining({ + variables: { + amount: 90, + creationDate: 'YYYY-MM-01', + email: undefined, + id: undefined, + memo: 'Test create coins', + moderator: 0, + }, + }), + ) + }) + }) }) describe('third radio button', () => { @@ -111,6 +163,27 @@ describe('EditCreationFormular', () => { it('sets rangeMax to 400', () => { expect(wrapper.vm.rangeMax).toBe(600) }) + + describe('sendForm', () => { + beforeEach(async () => { + await wrapper.find('.test-submit').trigger('click') + }) + + it('sends ... to apollo', () => { + expect(apolloMutateMock).toBeCalledWith( + expect.objectContaining({ + variables: { + amount: 90, + creationDate: 'YYYY-MM-DD', + email: undefined, + id: undefined, + memo: 'Test create coins', + moderator: 0, + }, + }), + ) + }) + }) }) }) }) diff --git a/admin/src/components/EditCreationFormular.vue b/admin/src/components/EditCreationFormular.vue index 2b1bb566c..3a1c91a02 100644 --- a/admin/src/components/EditCreationFormular.vue +++ b/admin/src/components/EditCreationFormular.vue @@ -6,6 +6,7 @@ @@ -147,10 +151,10 @@ export default { }, }, row: { - type: Array, - required: Object, + type: Object, + required: false, default() { - return [] + return {} }, }, creationUserData: { @@ -165,34 +169,11 @@ export default { required: true, }, }, - created() { - if (this.pagetype === 'PageCreationConfirm' && this.creationUserData.date) { - switch (this.$moment(this.creationUserData.date).format('MMMM')) { - case this.currentMonth.short: - this.createdIndex = 2 - this.radioSelected = this.currentMonth - break - case this.lastMonth.short: - this.createdIndex = 1 - this.radioSelected = this.lastMonth - break - case this.beforeLastMonth.short: - this.createdIndex = 0 - this.radioSelected = this.beforeLastMonth - break - default: - throw new Error('Something went wrong') - } - this.selectedOpenCreationAmount[this.createdIndex] = - this.creation[this.createdIndex] + this.creationUserData.amount / 10000 - this.rangeMax = this.selectedOpenCreationAmount[this.createdIndex] - } - }, data() { return { radioSelected: '', text: !this.creationUserData.memo ? '' : this.creationUserData.memo, - value: !this.creationUserData.amount ? 0 : this.creationUserData.amount / 10000, + value: !this.creationUserData.amount ? 0 : this.creationUserData.amount, rangeMin: 0, rangeMax: 1000, currentMonth: { @@ -221,22 +202,6 @@ export default { this.rangeMax = this.creation[index] }, submitCreation() { - // Formular Prüfen ob ein Zeitraum ausgewählt wurde. Ansonsten abbrechen und Hinweis anzeigen - if (this.radioSelected === '') { - return alert('Bitte wähle einen Zeitraum!') - } - // Formular Prüfen ob der GDD Betrag grösser 0 ist. Ansonsten abbrechen und Hinweis anzeigen - if (this.value <= 0) { - return alert('Bitte gib einen GDD Betrag an!') - } - // Formular Prüfen ob der Text vorhanden ist. Ansonsten abbrechen und Hinweis anzeigen - if (this.text === '') { - return alert('Bitte gib einen Text ein!') - } - // Formular Prüfen ob der Text länger als 10 Zeichen hat. Ansonsten abbrechen und Hinweis anzeigen - if (this.text.length < 10) { - return alert('Bitte gib einen Text ein der länger als 10 Zeichen ist!') - } this.submitObj = { id: this.item.id, email: this.item.email, @@ -281,5 +246,28 @@ export default { }) }, }, + created() { + if (this.pagetype === 'PageCreationConfirm' && this.creationUserData.date) { + switch (this.$moment(this.creationUserData.date).format('MMMM')) { + case this.currentMonth.short: + this.createdIndex = 2 + this.radioSelected = this.currentMonth + break + case this.lastMonth.short: + this.createdIndex = 1 + this.radioSelected = this.lastMonth + break + case this.beforeLastMonth.short: + this.createdIndex = 0 + this.radioSelected = this.beforeLastMonth + break + default: + throw new Error('Something went wrong') + } + this.selectedOpenCreationAmount[this.createdIndex] = + this.creation[this.createdIndex] + this.creationUserData.amount + this.rangeMax = this.selectedOpenCreationAmount[this.createdIndex] + } + }, } diff --git a/admin/src/components/UserTable.vue b/admin/src/components/UserTable.vue index e47963159..4a8ca8e84 100644 --- a/admin/src/components/UserTable.vue +++ b/admin/src/components/UserTable.vue @@ -132,6 +132,7 @@