From e7683fb05ac89878fd320cf3847c9dd121b082e5 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 16 Nov 2023 12:00:35 +0100 Subject: [PATCH] work on fixing tests --- .../ContributionMessagesFormular.spec.js | 4 ++- .../ContributionMessagesFormular.vue | 1 + .../ContributionMessagesList.spec.js | 1 + .../CreationTransactionList.spec.js | 4 +++ admin/src/graphql/getContribution.js | 27 +++++++++++++++ admin/src/pages/CreationConfirm.spec.js | 31 ++++++++++++++--- admin/src/pages/CreationConfirm.vue | 33 ++----------------- admin/src/pages/Overview.spec.js | 4 +++ .../UnconfirmedContributionAdmin.role.ts | 9 +++++ .../UnconfirmedContributionUser.role.ts | 10 ++++++ .../Contributions/ContributionForm.vue | 1 - frontend/src/pages/Community.vue | 6 ++-- 12 files changed, 92 insertions(+), 39 deletions(-) create mode 100644 admin/src/graphql/getContribution.js diff --git a/admin/src/components/ContributionMessages/ContributionMessagesFormular.spec.js b/admin/src/components/ContributionMessages/ContributionMessagesFormular.spec.js index b7f01f8b8..60395c68b 100644 --- a/admin/src/components/ContributionMessages/ContributionMessagesFormular.spec.js +++ b/admin/src/components/ContributionMessages/ContributionMessagesFormular.spec.js @@ -12,6 +12,7 @@ describe('ContributionMessagesFormular', () => { const propsData = { contributionId: 42, + contributionMemo: 'It is a test memo', } const mocks = { @@ -52,9 +53,10 @@ describe('ContributionMessagesFormular', () => { await wrapper.find('form').trigger('reset') }) - it('form has empty text', () => { + it('form has empty text and memo reset to contribution memo input', () => { expect(wrapper.vm.form).toEqual({ text: '', + memo: 'It is a test memo', }) }) }) diff --git a/admin/src/components/ContributionMessages/ContributionMessagesFormular.vue b/admin/src/components/ContributionMessages/ContributionMessagesFormular.vue index b61a65447..96ecef6c1 100644 --- a/admin/src/components/ContributionMessages/ContributionMessagesFormular.vue +++ b/admin/src/components/ContributionMessages/ContributionMessagesFormular.vue @@ -148,6 +148,7 @@ export default { }, onReset(event) { this.form.text = '' + this.form.memo = this.contributionMemo }, enableMemo() { this.chatOrMemo = 1 diff --git a/admin/src/components/ContributionMessages/ContributionMessagesList.spec.js b/admin/src/components/ContributionMessages/ContributionMessagesList.spec.js index 023f65974..671a05f83 100644 --- a/admin/src/components/ContributionMessages/ContributionMessagesList.spec.js +++ b/admin/src/components/ContributionMessages/ContributionMessagesList.spec.js @@ -86,6 +86,7 @@ describe('ContributionMessagesList', () => { const propsData = { contributionId: 42, + contributionMemo: 'test memo', contributionUserId: 108, contributionStatus: 'PENDING', } diff --git a/admin/src/components/CreationTransactionList.spec.js b/admin/src/components/CreationTransactionList.spec.js index 28aa1707d..394cfd9ea 100644 --- a/admin/src/components/CreationTransactionList.spec.js +++ b/admin/src/components/CreationTransactionList.spec.js @@ -38,6 +38,8 @@ const defaultData = () => { contributionDate: new Date(), deletedBy: null, deletedAt: null, + updatedAt: null, + updatedBy: null, createdAt: new Date(), moderatorId: null, }, @@ -61,6 +63,8 @@ const defaultData = () => { contributionDate: new Date(), deletedBy: null, deletedAt: null, + updatedAt: null, + updatedBy: null, createdAt: new Date(), moderatorId: null, }, diff --git a/admin/src/graphql/getContribution.js b/admin/src/graphql/getContribution.js new file mode 100644 index 000000000..bc42bceb1 --- /dev/null +++ b/admin/src/graphql/getContribution.js @@ -0,0 +1,27 @@ +import gql from 'graphql-tag' + +export const getContribution = gql` + query ($id: Int!) { + contribution(id: $id) { + id + firstName + lastName + amount + memo + createdAt + contributionDate + confirmedAt + confirmedBy + updatedAt + updatedBy + status + messagesCount + deniedAt + deniedBy + deletedAt + deletedBy + moderatorId + userId + } + } +` \ No newline at end of file diff --git a/admin/src/pages/CreationConfirm.spec.js b/admin/src/pages/CreationConfirm.spec.js index 36e2479aa..d26b183e6 100644 --- a/admin/src/pages/CreationConfirm.spec.js +++ b/admin/src/pages/CreationConfirm.spec.js @@ -4,6 +4,7 @@ import { adminDeleteContribution } from '../graphql/adminDeleteContribution' import { denyContribution } from '../graphql/denyContribution' import { adminListContributions } from '../graphql/adminListContributions' import { confirmContribution } from '../graphql/confirmContribution' +import { getContribution } from '../graphql/getContribution' import { toastErrorSpy, toastSuccessSpy } from '../../test/testSetup' import VueApollo from 'vue-apollo' import { createMockClient } from 'mock-apollo-client' @@ -61,6 +62,8 @@ const defaultData = () => { contributionDate: new Date(), deletedBy: null, deletedAt: null, + updatedAt: null, + updatedBy: null, createdAt: new Date(), }, { @@ -83,6 +86,8 @@ const defaultData = () => { contributionDate: new Date(), deletedBy: null, deletedAt: null, + updatedAt: null, + updatedBy: null, createdAt: new Date(), }, ], @@ -96,6 +101,7 @@ describe('CreationConfirm', () => { const adminDeleteContributionMock = jest.fn() const adminDenyContributionMock = jest.fn() const confirmContributionMock = jest.fn() + const getContributionMock = jest.fn() mockClient.setRequestHandler( adminListContributions, @@ -121,6 +127,11 @@ describe('CreationConfirm', () => { confirmContributionMock.mockResolvedValue({ data: { confirmContribution: true } }), ) + mockClient.setRequestHandler( + getContribution, + getContributionMock.mockResolvedValue({ data: {} }), + ) + const Wrapper = () => { return mount(CreationConfirm, { localVue, mocks, apolloProvider }) } @@ -141,7 +152,7 @@ describe('CreationConfirm', () => { }) }) - describe('server response is succes', () => { + describe('server response is success', () => { it('has a DIV element with the class.creation-confirm', () => { expect(wrapper.find('div.creation-confirm').exists()).toBeTruthy() }) @@ -150,7 +161,7 @@ describe('CreationConfirm', () => { expect(wrapper.find('tbody').findAll('tr')).toHaveLength(2) }) }) - + describe('actions in overlay', () => { describe('delete creation', () => { beforeEach(async () => { @@ -219,7 +230,7 @@ describe('CreationConfirm', () => { expect(wrapper.find('#overlay').isVisible()).toBeTruthy() }) - describe('with succes', () => { + describe('with success', () => { describe('cancel confirmation', () => { beforeEach(async () => { await wrapper.find('#overlay').findAll('button').at(0).trigger('click') @@ -278,7 +289,7 @@ describe('CreationConfirm', () => { expect(wrapper.find('#overlay').isVisible()).toBeTruthy() }) - describe('with succes', () => { + describe('with success', () => { describe('cancel deny', () => { beforeEach(async () => { await wrapper.find('#overlay').findAll('button').at(0).trigger('click') @@ -510,6 +521,18 @@ describe('CreationConfirm', () => { }) }) + describe('reload contribution', () => { + beforeEach(async () => { + await wrapper.findComponent({ name: 'OpenCreationsTable' }).vm.$emit('reload-contribution', 1) + }) + + it('reloaded contribution', () => { + expect(getContributionMock).toBeCalledWith({ + id: 1 + }) + }) + }) + describe('unknown variant', () => { beforeEach(async () => { await wrapper.setData({ variant: 'unknown' }) diff --git a/admin/src/pages/CreationConfirm.vue b/admin/src/pages/CreationConfirm.vue index 593603e43..3ca382c43 100644 --- a/admin/src/pages/CreationConfirm.vue +++ b/admin/src/pages/CreationConfirm.vue @@ -3,7 +3,7 @@
@@ -96,33 +96,7 @@ import { adminListContributions } from '../graphql/adminListContributions' import { adminDeleteContribution } from '../graphql/adminDeleteContribution' import { confirmContribution } from '../graphql/confirmContribution' import { denyContribution } from '../graphql/denyContribution' -import gql from 'graphql-tag' - -export const getContribution = gql` - query ($id: Int!) { - contribution(id: $id) { - id - firstName - lastName - amount - memo - createdAt - contributionDate - confirmedAt - confirmedBy - updatedAt - updatedBy - status - messagesCount - deniedAt - deniedBy - deletedAt - deletedBy - moderatorId - userId - } - } -` +import { getContribution } from '../graphql/getContribution' const FILTER_TAB_MAP = [ ['IN_PROGRESS', 'PENDING'], @@ -175,9 +149,6 @@ export default { this.toastError(error.message) }) }, - swapNoHashtag() { - this.query() - }, deleteCreation() { this.$apollo .mutate({ diff --git a/admin/src/pages/Overview.spec.js b/admin/src/pages/Overview.spec.js index b9ad77cdd..d5265f0e2 100644 --- a/admin/src/pages/Overview.spec.js +++ b/admin/src/pages/Overview.spec.js @@ -53,6 +53,8 @@ const defaultData = () => { contributionDate: new Date(), deletedBy: null, deletedAt: null, + updatedAt: null, + updatedBy: null, createdAt: new Date(), }, { @@ -75,6 +77,8 @@ const defaultData = () => { contributionDate: new Date(), deletedBy: null, deletedAt: null, + updatedAt: null, + updatedBy: null, createdAt: new Date(), }, ], diff --git a/backend/src/interactions/updateUnconfirmedContribution/UnconfirmedContributionAdmin.role.ts b/backend/src/interactions/updateUnconfirmedContribution/UnconfirmedContributionAdmin.role.ts index 593308a7c..c55283272 100644 --- a/backend/src/interactions/updateUnconfirmedContribution/UnconfirmedContributionAdmin.role.ts +++ b/backend/src/interactions/updateUnconfirmedContribution/UnconfirmedContributionAdmin.role.ts @@ -41,4 +41,13 @@ export class UnconfirmedContributionAdminRole extends UnconfirmedContributionRol } return this } + protected async validate(clientTimezoneOffset: number): Promise { + await super.validate(clientTimezoneOffset) + // creation date is currently not changeable + if (this.self.memo === this.updateData.memo && + this.self.amount === this.updatedAmount && + this.self.contributionDate.getTime() === (new Date(this.updatedCreationDate).getTime())) { + throw new LogError("the contribution wasn't changed at all") + } + } } diff --git a/backend/src/interactions/updateUnconfirmedContribution/UnconfirmedContributionUser.role.ts b/backend/src/interactions/updateUnconfirmedContribution/UnconfirmedContributionUser.role.ts index 3d7a15b63..85374e3e8 100644 --- a/backend/src/interactions/updateUnconfirmedContribution/UnconfirmedContributionUser.role.ts +++ b/backend/src/interactions/updateUnconfirmedContribution/UnconfirmedContributionUser.role.ts @@ -43,4 +43,14 @@ export class UnconfirmedContributionUserRole extends UnconfirmedContributionRole } return this } + + protected async validate(clientTimezoneOffset: number): Promise { + await super.validate(clientTimezoneOffset) + // creation date is currently not changeable + if (this.self.memo === this.updateData.memo && + this.self.amount === this.updatedAmount && + this.self.contributionDate.getTime() === (new Date(this.updatedCreationDate).getTime())) { + throw new LogError("the contribution wasn't changed at all") + } + } } diff --git a/frontend/src/components/Contributions/ContributionForm.vue b/frontend/src/components/Contributions/ContributionForm.vue index e8fb3eb30..8b2113e5d 100644 --- a/frontend/src/components/Contributions/ContributionForm.vue +++ b/frontend/src/components/Contributions/ContributionForm.vue @@ -16,7 +16,6 @@ reset-value="" :label-no-date-selected="$t('contribution.noDateSelected')" required - :disabled="this.form.id !== null" :no-flip="true" > diff --git a/frontend/src/pages/Community.vue b/frontend/src/pages/Community.vue index c4df3a47e..2381b5be1 100644 --- a/frontend/src/pages/Community.vue +++ b/frontend/src/pages/Community.vue @@ -91,6 +91,7 @@ export default { hours: 0, amount: '', }, + originalContributionDate: '', updateAmount: '', maximalDate: new Date(), openCreations: [], @@ -183,10 +184,10 @@ export default { return 0 }, maxForMonths() { - const formDate = new Date(this.form.date) + const originalContributionDate = new Date(this.originalContributionDate) if (this.openCreations && this.openCreations.length) return this.openCreations.slice(1).map((creation) => { - if (creation.year === formDate.getFullYear() && creation.month === formDate.getMonth()) + if (creation.year === originalContributionDate.getFullYear() && creation.month === originalContributionDate.getMonth()) return parseInt(creation.amount) + this.amountToAdd return parseInt(creation.amount) }) @@ -280,6 +281,7 @@ export default { updateContributionForm(item) { this.form.id = item.id this.form.date = item.contributionDate + this.originalContributionDate = item.contributionDate this.form.memo = item.memo this.form.amount = item.amount this.form.hours = item.amount / 20