From c08aac58a9ca13c723a39f8489fc67f4cfcbe25f Mon Sep 17 00:00:00 2001 From: joseji Date: Thu, 22 Sep 2022 11:44:30 +0200 Subject: [PATCH 01/26] events and half log tests --- .../resolver/ContributionResolver.test.ts | 24 ++++++++++++++++++- .../graphql/resolver/ContributionResolver.ts | 18 ++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 20f11ff9a..b91d3213b 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -16,6 +16,9 @@ import { userFactory } from '@/seeds/factory/user' import { creationFactory } from '@/seeds/factory/creation' import { creations } from '@/seeds/creation/index' import { peterLustig } from '@/seeds/users/peter-lustig' +import { EventProtocol } from '@entity/EventProtocol' +import { EventProtocolType } from '@/event/EventProtocolType' +import { logger } from '@test/testSetup' let mutate: any, query: any, con: any let testEnv: any @@ -35,6 +38,8 @@ afterAll(async () => { }) describe('ContributionResolver', () => { + let bibi: any + describe('createContribution', () => { describe('unauthenticated', () => { it('returns an error', async () => { @@ -54,7 +59,7 @@ describe('ContributionResolver', () => { describe('authenticated with valid user', () => { beforeAll(async () => { await userFactory(testEnv, bibiBloxberg) - await query({ + bibi = await query({ query: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, }) @@ -84,6 +89,10 @@ describe('ContributionResolver', () => { ) }) + it('logs the error found', () => { + expect(logger.error).toBeCalledWith(`memo text is too short: memo.length=4 < (5)`) + }) + it('throws error when memo length greater than 255 chars', async () => { const date = new Date() await expect( @@ -102,6 +111,10 @@ describe('ContributionResolver', () => { ) }) + it('logs the error found', () => { + expect(logger.error).toBeCalledWith(`memo text is too long: memo.length=259 > (255)`) + }) + it('throws error when creationDate not-valid', async () => { await expect( mutate({ @@ -165,6 +178,15 @@ describe('ContributionResolver', () => { }), ) }) + + it('stores the create contribution event in the database', async () => { + await expect(EventProtocol.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventProtocolType.CONTRIBUTION_CREATE, + userId: bibi.data.login.id, + }), + ) + }) }) }) }) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index fc93880f1..b788384f1 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -13,6 +13,8 @@ import { Contribution, ContributionListResult } from '@model/Contribution' import { UnconfirmedContribution } from '@model/UnconfirmedContribution' import { validateContribution, getUserCreation, updateCreations } from './util/creations' import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const' +import { Event, EventConfirmationEmail, EventContributionCreate } from '@/event/Event' +import { eventProtocol } from '@/event/EventProtocolEmitter' @Resolver() export class ContributionResolver { @@ -23,15 +25,17 @@ export class ContributionResolver { @Ctx() context: Context, ): Promise { if (memo.length > MEMO_MAX_CHARS) { - logger.error(`memo text is too long: memo.length=${memo.length} > (${MEMO_MAX_CHARS}`) + logger.error(`memo text is too long: memo.length=${memo.length} > (${MEMO_MAX_CHARS})`) throw new Error(`memo text is too long (${MEMO_MAX_CHARS} characters maximum)`) } if (memo.length < MEMO_MIN_CHARS) { - logger.error(`memo text is too short: memo.length=${memo.length} < (${MEMO_MIN_CHARS}`) + logger.error(`memo text is too short: memo.length=${memo.length} < (${MEMO_MIN_CHARS})`) throw new Error(`memo text is too short (${MEMO_MIN_CHARS} characters minimum)`) } + const event = new Event() + const user = getUser(context) const creations = await getUserCreation(user.id) logger.trace('creations', creations) @@ -49,6 +53,11 @@ export class ContributionResolver { logger.trace('contribution to save', contribution) await dbContribution.save(contribution) + + const eventCreateContribution = new EventContributionCreate() + eventCreateContribution.userId = user.id + await eventProtocol.writeEvent(event.setEventContributionCreate(eventCreateContribution)) + return new UnconfirmedContribution(contribution, user, creations) } @@ -61,12 +70,15 @@ export class ContributionResolver { const user = getUser(context) const contribution = await dbContribution.findOne(id) if (!contribution) { + logger.error('Contribution not found for given id') throw new Error('Contribution not found for given id.') } if (contribution.userId !== user.id) { + logger.error('Can not delete contribution of another user') throw new Error('Can not delete contribution of another user') } if (contribution.confirmedAt) { + logger.error('A confirmed contribution can not be deleted') throw new Error('A confirmed contribution can not be deleted') } contribution.contributionStatus = ContributionStatus.DELETED @@ -154,9 +166,11 @@ export class ContributionResolver { where: { id: contributionId, confirmedAt: IsNull() }, }) if (!contributionToUpdate) { + logger.error('No contribution found for given id') throw new Error('No contribution found to given id.') } if (contributionToUpdate.userId !== user.id) { + logger.error('user of the pending contribution and send user does not correspond') throw new Error('user of the pending contribution and send user does not correspond') } From 0176131c39db97c81c208978957ae0e165aabe29 Mon Sep 17 00:00:00 2001 From: joseji Date: Thu, 22 Sep 2022 12:07:12 +0200 Subject: [PATCH 02/26] errors are now logged, and events are checked --- .../resolver/ContributionResolver.test.ts | 58 ++++++++++++++++++- .../graphql/resolver/ContributionResolver.ts | 4 +- .../src/graphql/resolver/util/creations.ts | 4 ++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index b91d3213b..d08396285 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -134,6 +134,12 @@ describe('ContributionResolver', () => { ) }) + it('logs the error found', () => { + expect(logger.error).toBeCalledWith( + 'No information for available creations for the given date', + ) + }) + it('throws error when creationDate 3 month behind', async () => { const date = new Date() await expect( @@ -153,6 +159,12 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith( + 'No information for available creations for the given date', + ) + }) }) describe('valid input', () => { @@ -369,6 +381,10 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('No contribution found to given id') + }) }) describe('Memo length smaller than 5 chars', () => { @@ -390,6 +406,10 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('memo text is too short: memo.length=4 < (5)') + }) }) describe('Memo length greater than 255 chars', () => { @@ -411,6 +431,10 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('memo text is too long: memo.length=259 > (255)') + }) }) describe('wrong user tries to update the contribution', () => { @@ -442,6 +466,12 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith( + 'user of the pending contribution and send user does not correspond', + ) + }) }) describe('admin tries to update a user contribution', () => { @@ -463,6 +493,8 @@ describe('ContributionResolver', () => { }), ) }) + + // TODO check that the error is logged (need to modify AdminResolver, avoid conflicts) }) describe('update too much so that the limit is exceeded', () => { @@ -494,6 +526,12 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith( + 'The amount (1019 GDD) to be created exceeds the amount (1000 GDD) still available for this month.', + ) + }) }) describe('update creation to a date that is older than 3 months', () => { @@ -517,6 +555,12 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith( + 'No information for available creations for the given date', + ) + }) }) describe('valid input', () => { @@ -686,9 +730,13 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('Contribution not found for given id') + }) }) - describe('other user sends a deleteContribtuion', () => { + describe('other user sends a deleteContribution', () => { it('returns an error', async () => { await query({ query: login, @@ -707,6 +755,10 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('Can not delete contribution of another user') + }) }) describe('User deletes own contribution', () => { @@ -751,6 +803,10 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('A confirmed contribution can not be deleted') + }) }) }) }) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index b788384f1..3c33a4e0f 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -13,7 +13,7 @@ import { Contribution, ContributionListResult } from '@model/Contribution' import { UnconfirmedContribution } from '@model/UnconfirmedContribution' import { validateContribution, getUserCreation, updateCreations } from './util/creations' import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const' -import { Event, EventConfirmationEmail, EventContributionCreate } from '@/event/Event' +import { Event, EventContributionCreate } from '@/event/Event' import { eventProtocol } from '@/event/EventProtocolEmitter' @Resolver() @@ -166,7 +166,7 @@ export class ContributionResolver { where: { id: contributionId, confirmedAt: IsNull() }, }) if (!contributionToUpdate) { - logger.error('No contribution found for given id') + logger.error('No contribution found to given id') throw new Error('No contribution found to given id.') } if (contributionToUpdate.userId !== user.id) { diff --git a/backend/src/graphql/resolver/util/creations.ts b/backend/src/graphql/resolver/util/creations.ts index ad15ebec6..afbadead1 100644 --- a/backend/src/graphql/resolver/util/creations.ts +++ b/backend/src/graphql/resolver/util/creations.ts @@ -19,10 +19,14 @@ export const validateContribution = ( const index = getCreationIndex(creationDate.getMonth()) if (index < 0) { + logger.error('No information for available creations for the given date') throw new Error('No information for available creations for the given date') } if (amount.greaterThan(creations[index].toString())) { + logger.error( + `The amount (${amount} GDD) to be created exceeds the amount (${creations[index]} GDD) still available for this month.`, + ) throw new Error( `The amount (${amount} GDD) to be created exceeds the amount (${creations[index]} GDD) still available for this month.`, ) From 79f7ebce57d2179d1b365de8dfb6f6118fde103f Mon Sep 17 00:00:00 2001 From: joseji Date: Thu, 22 Sep 2022 17:35:41 +0200 Subject: [PATCH 03/26] updated event working, deletion is not working properly (deeper than the event itself) --- backend/src/event/Event.ts | 16 ++++++++++++ backend/src/event/EventProtocolType.ts | 2 ++ .../resolver/ContributionResolver.test.ts | 21 ++++++++++++++++ .../graphql/resolver/ContributionResolver.ts | 25 ++++++++++++++++++- 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 6f07661f1..40eb333fd 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -48,6 +48,8 @@ export class EventTransactionCreation extends EventBasicUserId { export class EventTransactionReceive extends EventBasicTx {} export class EventTransactionReceiveRedeem extends EventBasicTx {} export class EventContributionCreate extends EventBasicCt {} +export class EventContributionDelete extends EventBasicCt {} +export class EventContributionUpdate extends EventBasicCt {} export class EventContributionConfirm extends EventBasicCt { xUserId: number xCommunityId: number @@ -206,6 +208,20 @@ export class Event { return this } + public setEventContributionDelete(ev: EventContributionDelete): Event { + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + this.type = EventProtocolType.CONTRIBUTION_DELETE + + return this + } + + public setEventContributionUpdate(ev: EventContributionUpdate): Event { + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + this.type = EventProtocolType.CONTRIBUTION_UPDATE + + return this + } + public setEventContributionConfirm(ev: EventContributionConfirm): Event { this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) if (ev.xUserId) this.xUserId = ev.xUserId diff --git a/backend/src/event/EventProtocolType.ts b/backend/src/event/EventProtocolType.ts index 0f61f787a..c0fc1bb8e 100644 --- a/backend/src/event/EventProtocolType.ts +++ b/backend/src/event/EventProtocolType.ts @@ -21,4 +21,6 @@ export enum EventProtocolType { CONTRIBUTION_CONFIRM = 'CONTRIBUTION_CONFIRM', CONTRIBUTION_LINK_DEFINE = 'CONTRIBUTION_LINK_DEFINE', CONTRIBUTION_LINK_ACTIVATE_REDEEM = 'CONTRIBUTION_LINK_ACTIVATE_REDEEM', + CONTRIBUTION_DELETE = 'CONTRIBUTION_DELETE', + CONTRIBUTION_UPDATE = 'CONTRIBUTION_UPDATE', } diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index d08396285..683946633 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -19,6 +19,7 @@ import { peterLustig } from '@/seeds/users/peter-lustig' import { EventProtocol } from '@entity/EventProtocol' import { EventProtocolType } from '@/event/EventProtocolType' import { logger } from '@test/testSetup' +import { Contribution } from '@entity/Contribution' let mutate: any, query: any, con: any let testEnv: any @@ -587,6 +588,15 @@ describe('ContributionResolver', () => { }), ) }) + + it('stores the update contribution event in the database', async () => { + await expect(EventProtocol.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventProtocolType.CONTRIBUTION_UPDATE, + contributionId: result.data.createContribution.id, + }), + ) + }) }) }) }) @@ -763,6 +773,7 @@ describe('ContributionResolver', () => { describe('User deletes own contribution', () => { it('deletes successfully', async () => { + console.log(await Contribution.find({ id: result.data.createContribution.id })) await expect( mutate({ mutation: deleteContribution, @@ -772,6 +783,16 @@ describe('ContributionResolver', () => { }), ).resolves.toBeTruthy() }) + + it('stores the delete contribution event in the database', async () => { + console.log(await Contribution.find({ id: result.data.createContribution.id })) + await expect(EventProtocol.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventProtocolType.CONTRIBUTION_DELETE, + // id: result.data.createContribution.id, + }), + ) + }) }) describe('User deletes already confirmed contribution', () => { diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 3c33a4e0f..9886eeb05 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -13,7 +13,12 @@ import { Contribution, ContributionListResult } from '@model/Contribution' import { UnconfirmedContribution } from '@model/UnconfirmedContribution' import { validateContribution, getUserCreation, updateCreations } from './util/creations' import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const' -import { Event, EventContributionCreate } from '@/event/Event' +import { + Event, + EventContributionCreate, + EventContributionDelete, + EventContributionUpdate, +} from '@/event/Event' import { eventProtocol } from '@/event/EventProtocolEmitter' @Resolver() @@ -56,6 +61,8 @@ export class ContributionResolver { const eventCreateContribution = new EventContributionCreate() eventCreateContribution.userId = user.id + eventCreateContribution.amount = amount + eventCreateContribution.contributionId = contribution.id await eventProtocol.writeEvent(event.setEventContributionCreate(eventCreateContribution)) return new UnconfirmedContribution(contribution, user, creations) @@ -67,6 +74,7 @@ export class ContributionResolver { @Arg('id', () => Int) id: number, @Ctx() context: Context, ): Promise { + const event = new Event() const user = getUser(context) const contribution = await dbContribution.findOne(id) if (!contribution) { @@ -81,8 +89,16 @@ export class ContributionResolver { logger.error('A confirmed contribution can not be deleted') throw new Error('A confirmed contribution can not be deleted') } + contribution.contributionStatus = ContributionStatus.DELETED + contribution.deletedAt = new Date() await contribution.save() + + const eventDeleteContribution = new EventContributionDelete() + eventDeleteContribution.userId = user.id + eventDeleteContribution.contributionId = contribution.id + await eventProtocol.writeEvent(event.setEventContributionDelete(eventDeleteContribution)) + const res = await contribution.softRemove() return !!res } @@ -188,6 +204,13 @@ export class ContributionResolver { contributionToUpdate.contributionStatus = ContributionStatus.PENDING dbContribution.save(contributionToUpdate) + const event = new Event() + + const eventUpdateContribution = new EventContributionUpdate() + eventUpdateContribution.userId = user.id + eventUpdateContribution.contributionId = contributionId + await eventProtocol.writeEvent(event.setEventContributionUpdate(eventUpdateContribution)) + return new UnconfirmedContribution(contributionToUpdate, user, creations) } } From 60d2e2ff7bd0c093bb7b4acbea0b81ca34044e42 Mon Sep 17 00:00:00 2001 From: joseji Date: Fri, 23 Sep 2022 18:46:40 +0200 Subject: [PATCH 04/26] fixed contribution delete event saving and testing --- .../resolver/ContributionResolver.test.ts | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 683946633..ee261c545 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -19,7 +19,6 @@ import { peterLustig } from '@/seeds/users/peter-lustig' import { EventProtocol } from '@entity/EventProtocol' import { EventProtocolType } from '@/event/EventProtocolType' import { logger } from '@test/testSetup' -import { Contribution } from '@entity/Contribution' let mutate: any, query: any, con: any let testEnv: any @@ -773,7 +772,6 @@ describe('ContributionResolver', () => { describe('User deletes own contribution', () => { it('deletes successfully', async () => { - console.log(await Contribution.find({ id: result.data.createContribution.id })) await expect( mutate({ mutation: deleteContribution, @@ -785,11 +783,26 @@ describe('ContributionResolver', () => { }) it('stores the delete contribution event in the database', async () => { - console.log(await Contribution.find({ id: result.data.createContribution.id })) + const contribution = await mutate({ + mutation: createContribution, + variables: { + amount: 166.0, + memo: 'Whatever contribution', + creationDate: new Date().toString(), + }, + }) + + await mutate({ + mutation: deleteContribution, + variables: { + id: contribution.data.createContribution.id, + }, + }) + await expect(EventProtocol.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_DELETE, - // id: result.data.createContribution.id, + contributionId: contribution.data.createContribution.id, }), ) }) From 744c961c0bcda7595eb6ed1f8269aef5c993d700 Mon Sep 17 00:00:00 2001 From: joseji Date: Fri, 23 Sep 2022 19:33:54 +0200 Subject: [PATCH 05/26] fixed tests with new log message --- backend/src/event/EventProtocolType.ts | 12 ++++++++++++ .../graphql/resolver/ContributionResolver.test.ts | 11 ++++++++--- backend/src/graphql/resolver/util/creations.ts | 5 ++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/backend/src/event/EventProtocolType.ts b/backend/src/event/EventProtocolType.ts index c0fc1bb8e..4265fb924 100644 --- a/backend/src/event/EventProtocolType.ts +++ b/backend/src/event/EventProtocolType.ts @@ -3,24 +3,36 @@ export enum EventProtocolType { VISIT_GRADIDO = 'VISIT_GRADIDO', REGISTER = 'REGISTER', REDEEM_REGISTER = 'REDEEM_REGISTER', + VERIFY_REDEEM = 'VERIFY_REDEEM', // TODO INACTIVE_ACCOUNT = 'INACTIVE_ACCOUNT', SEND_CONFIRMATION_EMAIL = 'SEND_CONFIRMATION_EMAIL', + SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = 'SEND_ACCOUNT_MULTIREGISTRATION_EMAIL', // TODO CONFIRM_EMAIL = 'CONFIRM_EMAIL', REGISTER_EMAIL_KLICKTIPP = 'REGISTER_EMAIL_KLICKTIPP', LOGIN = 'LOGIN', + LOGOUT = 'LOGOUT', // TODO REDEEM_LOGIN = 'REDEEM_LOGIN', ACTIVATE_ACCOUNT = 'ACTIVATE_ACCOUNT', + SEND_FORGOT_PASSWORD_EMAIL = 'SEND_FORGOT_PASSWORD_EMAIL', // TODO PASSWORD_CHANGE = 'PASSWORD_CHANGE', + SEND_TRANSACTION_SEND_EMAIL = 'SEND_TRANSACTION_SEND_EMAIL', // TODO + SEND_TRANSACTION_RECEIVE_EMAIL = 'SEND_TRANSACTION_RECEIVE_EMAIL', // TODO TRANSACTION_SEND = 'TRANSACTION_SEND', TRANSACTION_SEND_REDEEM = 'TRANSACTION_SEND_REDEEM', TRANSACTION_REPEATE_REDEEM = 'TRANSACTION_REPEATE_REDEEM', TRANSACTION_CREATION = 'TRANSACTION_CREATION', TRANSACTION_RECEIVE = 'TRANSACTION_RECEIVE', TRANSACTION_RECEIVE_REDEEM = 'TRANSACTION_RECEIVE_REDEEM', + SEND_TRANSACTION_LINK_REDEEM_EMAIL = 'SEND_TRANSACTION_LINK_REDEEM_EMAIL', // TODO + SEND_ADDED_CONTRIBUTION_EMAIL = 'SEND_ADDED_CONTRIBUTION_EMAIL', // TODO + SEND_CONTRIBUTION_CONFIRM_EMAIL = 'SEND_CONTRIBUTION_CONFIRM_EMAIL', // TODO CONTRIBUTION_CREATE = 'CONTRIBUTION_CREATE', CONTRIBUTION_CONFIRM = 'CONTRIBUTION_CONFIRM', + CONTRIBUTION_DENY = 'CONTRIBUTION_DENY', // TODO CONTRIBUTION_LINK_DEFINE = 'CONTRIBUTION_LINK_DEFINE', CONTRIBUTION_LINK_ACTIVATE_REDEEM = 'CONTRIBUTION_LINK_ACTIVATE_REDEEM', CONTRIBUTION_DELETE = 'CONTRIBUTION_DELETE', CONTRIBUTION_UPDATE = 'CONTRIBUTION_UPDATE', + USER_CREATE_CONTRIBUTION_MESSAGE = 'USER_CREATE_CONTRIBUTION_MESSAGE', // TODO + ADMIN_CREATE_CONTRIBUTION_MESSAGE = 'ADMIN_CREATE_CONTRIBUTION_MESSAGE', // TODO } diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index ee261c545..b8bbebbd9 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -136,7 +136,8 @@ describe('ContributionResolver', () => { it('logs the error found', () => { expect(logger.error).toBeCalledWith( - 'No information for available creations for the given date', + 'No information for available creations with the given creationDate=', + new Date('non-valid').toDateString, ) }) @@ -161,8 +162,10 @@ describe('ContributionResolver', () => { }) it('logs the error found', () => { + const date = new Date() expect(logger.error).toBeCalledWith( - 'No information for available creations for the given date', + 'No information for available creations with the given creationDate=', + new Date(date.setMonth(date.getMonth() - 3).toString()).toDateString, ) }) }) @@ -557,8 +560,10 @@ describe('ContributionResolver', () => { }) it('logs the error found', () => { + const date = new Date() expect(logger.error).toBeCalledWith( - 'No information for available creations for the given date', + 'No information for available creations with the given creationDate=', + new Date(date.setMonth(date.getMonth() - 3).toString()).toDateString, ) }) }) diff --git a/backend/src/graphql/resolver/util/creations.ts b/backend/src/graphql/resolver/util/creations.ts index afbadead1..0b055e1d0 100644 --- a/backend/src/graphql/resolver/util/creations.ts +++ b/backend/src/graphql/resolver/util/creations.ts @@ -19,7 +19,10 @@ export const validateContribution = ( const index = getCreationIndex(creationDate.getMonth()) if (index < 0) { - logger.error('No information for available creations for the given date') + logger.error( + 'No information for available creations with the given creationDate=', + creationDate.toDateString, + ) throw new Error('No information for available creations for the given date') } From 49378c64e250beccdf72045eaea6598257d39bd0 Mon Sep 17 00:00:00 2001 From: joseji Date: Mon, 26 Sep 2022 22:17:07 +0200 Subject: [PATCH 06/26] new events fully implemented --- backend/src/event/Event.ts | 115 +++++++++++++++++++++++++ backend/src/event/EventProtocolType.ts | 24 +++--- 2 files changed, 127 insertions(+), 12 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 40eb333fd..f6e6a554c 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -30,11 +30,20 @@ export class EventBasicRedeem extends EventBasicUserId { export class EventVisitGradido extends EventBasic {} export class EventRegister extends EventBasicUserId {} export class EventRedeemRegister extends EventBasicRedeem {} +export class EventVerifyRedeem extends EventBasicRedeem {} export class EventInactiveAccount extends EventBasicUserId {} export class EventSendConfirmationEmail extends EventBasicUserId {} +export class EventSendAccountMultiregistrationEmail extends EventBasicUserId {} +export class EventSendForgotPasswordEmail extends EventBasicUserId {} +export class EventSendTransactionSendEmail extends EventBasicRedeem {} +export class EventSendTransactionReceiveEmail extends EventBasicRedeem {} +export class EventSendTransactionLinkRedeemEmail extends EventBasicRedeem {} +export class EventSendAddedContributionEmail extends EventBasicCt {} +export class EventSendContributionConfirmEmail extends EventBasicCt {} export class EventConfirmationEmail extends EventBasicUserId {} export class EventRegisterEmailKlicktipp extends EventBasicUserId {} export class EventLogin extends EventBasicUserId {} +export class EventLogout extends EventBasicUserId {} export class EventRedeemLogin extends EventBasicRedeem {} export class EventActivateAccount extends EventBasicUserId {} export class EventPasswordChange extends EventBasicUserId {} @@ -48,12 +57,22 @@ export class EventTransactionCreation extends EventBasicUserId { export class EventTransactionReceive extends EventBasicTx {} export class EventTransactionReceiveRedeem extends EventBasicTx {} export class EventContributionCreate extends EventBasicCt {} +export class EventUserCreateContributionMessage extends EventBasicCt { + message: string +} +export class EventAdminCreateContributionMessage extends EventBasicCt { + message: string +} export class EventContributionDelete extends EventBasicCt {} export class EventContributionUpdate extends EventBasicCt {} export class EventContributionConfirm extends EventBasicCt { xUserId: number xCommunityId: number } +export class EventContributionDeny extends EventBasicCt { + xUserId: number + xCommunityId: number +} export class EventContributionLinkDefine extends EventBasicCt {} export class EventContributionLinkActivateRedeem extends EventBasicCt {} @@ -101,6 +120,13 @@ export class Event { return this } + public setEventVerifyRedeem(ev: EventVerifyRedeem): Event { + this.setByBasicRedeem(ev.userId, ev.transactionId, ev.contributionId) + this.type = EventProtocolType.VERIFY_REDEEM + + return this + } + public setEventInactiveAccount(ev: EventInactiveAccount): Event { this.setByBasicUser(ev.userId) this.type = EventProtocolType.INACTIVE_ACCOUNT @@ -115,6 +141,62 @@ export class Event { return this } + public setEventSendAccountMultiregistrationEmail( + ev: EventSendAccountMultiregistrationEmail, + ): Event { + this.setByBasicUser(ev.userId) + this.type = EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL + + return this + } + + public setEventSendForgotPasswordEmail(ev: EventSendForgotPasswordEmail): Event { + this.setByBasicUser(ev.userId) + this.type = EventProtocolType.SEND_FORGOT_PASSWORD_EMAIL + + return this + } + + public setEventSendTransactionSendEmail(ev: EventSendTransactionSendEmail): Event { + this.setByBasicUser(ev.userId) + this.transactionId = ev.transactionId + this.type = EventProtocolType.SEND_TRANSACTION_SEND_EMAIL + + return this + } + + public setEventSendTransactionReceiveEmail(ev: EventSendTransactionReceiveEmail): Event { + this.setByBasicUser(ev.userId) + this.transactionId = ev.transactionId + this.type = EventProtocolType.SEND_TRANSACTION_RECEIVE_EMAIL + + return this + } + + public setEventSendTransactionLinkRedeemEmail(ev: EventSendTransactionLinkRedeemEmail): Event { + this.setByBasicUser(ev.userId) + this.transactionId = ev.transactionId + this.type = EventProtocolType.SEND_TRANSACTION_LINK_REDEEM_EMAIL + + return this + } + + public setEventSendAddedContributionEmail(ev: EventSendAddedContributionEmail): Event { + this.setByBasicUser(ev.userId) + this.contributionId = ev.contributionId + this.type = EventProtocolType.SEND_ADDED_CONTRIBUTION_EMAIL + + return this + } + + public setEventSendContributionConfirmEmail(ev: EventSendContributionConfirmEmail): Event { + this.setByBasicUser(ev.userId) + this.contributionId = ev.contributionId + this.type = EventProtocolType.SEND_CONTRIBUTION_CONFIRM_EMAIL + + return this + } + public setEventConfirmationEmail(ev: EventConfirmationEmail): Event { this.setByBasicUser(ev.userId) this.type = EventProtocolType.CONFIRM_EMAIL @@ -136,6 +218,13 @@ export class Event { return this } + public setEventLogout(ev: EventLogout): Event { + this.setByBasicUser(ev.userId) + this.type = EventProtocolType.LOGOUT + + return this + } + public setEventRedeemLogin(ev: EventRedeemLogin): Event { this.setByBasicRedeem(ev.userId, ev.transactionId, ev.contributionId) this.type = EventProtocolType.REDEEM_LOGIN @@ -208,6 +297,22 @@ export class Event { return this } + public setEventUserCreateContributionMessage(ev: EventUserCreateContributionMessage): Event { + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + if (ev.message) this.message = ev.message + this.type = EventProtocolType.USER_CREATE_CONTRIBUTION_MESSAGE + + return this + } + + public setEventAdminCreateContributionMessage(ev: EventAdminCreateContributionMessage): Event { + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + if (ev.message) this.message = ev.message + this.type = EventProtocolType.ADMIN_CREATE_CONTRIBUTION_MESSAGE + + return this + } + public setEventContributionDelete(ev: EventContributionDelete): Event { this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) this.type = EventProtocolType.CONTRIBUTION_DELETE @@ -231,6 +336,15 @@ export class Event { return this } + public setEventContributionDeny(ev: EventContributionDeny): Event { + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + if (ev.xUserId) this.xUserId = ev.xUserId + if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId + this.type = EventProtocolType.CONTRIBUTION_DENY + + return this + } + public setEventContributionLinkDefine(ev: EventContributionLinkDefine): Event { this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) this.type = EventProtocolType.CONTRIBUTION_LINK_DEFINE @@ -314,4 +428,5 @@ export class Event { transactionId?: number contributionId?: number amount?: decimal + message?: string } diff --git a/backend/src/event/EventProtocolType.ts b/backend/src/event/EventProtocolType.ts index 4265fb924..d53eb6961 100644 --- a/backend/src/event/EventProtocolType.ts +++ b/backend/src/event/EventProtocolType.ts @@ -3,36 +3,36 @@ export enum EventProtocolType { VISIT_GRADIDO = 'VISIT_GRADIDO', REGISTER = 'REGISTER', REDEEM_REGISTER = 'REDEEM_REGISTER', - VERIFY_REDEEM = 'VERIFY_REDEEM', // TODO + VERIFY_REDEEM = 'VERIFY_REDEEM', INACTIVE_ACCOUNT = 'INACTIVE_ACCOUNT', SEND_CONFIRMATION_EMAIL = 'SEND_CONFIRMATION_EMAIL', - SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = 'SEND_ACCOUNT_MULTIREGISTRATION_EMAIL', // TODO + SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = 'SEND_ACCOUNT_MULTIREGISTRATION_EMAIL', CONFIRM_EMAIL = 'CONFIRM_EMAIL', REGISTER_EMAIL_KLICKTIPP = 'REGISTER_EMAIL_KLICKTIPP', LOGIN = 'LOGIN', - LOGOUT = 'LOGOUT', // TODO + LOGOUT = 'LOGOUT', REDEEM_LOGIN = 'REDEEM_LOGIN', ACTIVATE_ACCOUNT = 'ACTIVATE_ACCOUNT', - SEND_FORGOT_PASSWORD_EMAIL = 'SEND_FORGOT_PASSWORD_EMAIL', // TODO + SEND_FORGOT_PASSWORD_EMAIL = 'SEND_FORGOT_PASSWORD_EMAIL', PASSWORD_CHANGE = 'PASSWORD_CHANGE', - SEND_TRANSACTION_SEND_EMAIL = 'SEND_TRANSACTION_SEND_EMAIL', // TODO - SEND_TRANSACTION_RECEIVE_EMAIL = 'SEND_TRANSACTION_RECEIVE_EMAIL', // TODO + SEND_TRANSACTION_SEND_EMAIL = 'SEND_TRANSACTION_SEND_EMAIL', + SEND_TRANSACTION_RECEIVE_EMAIL = 'SEND_TRANSACTION_RECEIVE_EMAIL', TRANSACTION_SEND = 'TRANSACTION_SEND', TRANSACTION_SEND_REDEEM = 'TRANSACTION_SEND_REDEEM', TRANSACTION_REPEATE_REDEEM = 'TRANSACTION_REPEATE_REDEEM', TRANSACTION_CREATION = 'TRANSACTION_CREATION', TRANSACTION_RECEIVE = 'TRANSACTION_RECEIVE', TRANSACTION_RECEIVE_REDEEM = 'TRANSACTION_RECEIVE_REDEEM', - SEND_TRANSACTION_LINK_REDEEM_EMAIL = 'SEND_TRANSACTION_LINK_REDEEM_EMAIL', // TODO - SEND_ADDED_CONTRIBUTION_EMAIL = 'SEND_ADDED_CONTRIBUTION_EMAIL', // TODO - SEND_CONTRIBUTION_CONFIRM_EMAIL = 'SEND_CONTRIBUTION_CONFIRM_EMAIL', // TODO + SEND_TRANSACTION_LINK_REDEEM_EMAIL = 'SEND_TRANSACTION_LINK_REDEEM_EMAIL', + SEND_ADDED_CONTRIBUTION_EMAIL = 'SEND_ADDED_CONTRIBUTION_EMAIL', + SEND_CONTRIBUTION_CONFIRM_EMAIL = 'SEND_CONTRIBUTION_CONFIRM_EMAIL', CONTRIBUTION_CREATE = 'CONTRIBUTION_CREATE', CONTRIBUTION_CONFIRM = 'CONTRIBUTION_CONFIRM', - CONTRIBUTION_DENY = 'CONTRIBUTION_DENY', // TODO + CONTRIBUTION_DENY = 'CONTRIBUTION_DENY', CONTRIBUTION_LINK_DEFINE = 'CONTRIBUTION_LINK_DEFINE', CONTRIBUTION_LINK_ACTIVATE_REDEEM = 'CONTRIBUTION_LINK_ACTIVATE_REDEEM', CONTRIBUTION_DELETE = 'CONTRIBUTION_DELETE', CONTRIBUTION_UPDATE = 'CONTRIBUTION_UPDATE', - USER_CREATE_CONTRIBUTION_MESSAGE = 'USER_CREATE_CONTRIBUTION_MESSAGE', // TODO - ADMIN_CREATE_CONTRIBUTION_MESSAGE = 'ADMIN_CREATE_CONTRIBUTION_MESSAGE', // TODO + USER_CREATE_CONTRIBUTION_MESSAGE = 'USER_CREATE_CONTRIBUTION_MESSAGE', + ADMIN_CREATE_CONTRIBUTION_MESSAGE = 'ADMIN_CREATE_CONTRIBUTION_MESSAGE', } From 329e6f0893e8a2786c60a2264717965cb578a791 Mon Sep 17 00:00:00 2001 From: joseji Date: Mon, 26 Sep 2022 22:29:48 +0200 Subject: [PATCH 07/26] removed unnecesary previously included parameter 'message' on events --- backend/src/event/Event.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index f6e6a554c..bebc91915 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -299,7 +299,6 @@ export class Event { public setEventUserCreateContributionMessage(ev: EventUserCreateContributionMessage): Event { this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) - if (ev.message) this.message = ev.message this.type = EventProtocolType.USER_CREATE_CONTRIBUTION_MESSAGE return this @@ -307,7 +306,6 @@ export class Event { public setEventAdminCreateContributionMessage(ev: EventAdminCreateContributionMessage): Event { this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) - if (ev.message) this.message = ev.message this.type = EventProtocolType.ADMIN_CREATE_CONTRIBUTION_MESSAGE return this @@ -428,5 +426,4 @@ export class Event { transactionId?: number contributionId?: number amount?: decimal - message?: string } From c8a2d899b88bc563e1363cead9caef1064481605 Mon Sep 17 00:00:00 2001 From: joseji Date: Mon, 26 Sep 2022 22:41:33 +0200 Subject: [PATCH 08/26] all stated according to the events table --- backend/src/event/Event.ts | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index bebc91915..27e188a64 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -35,9 +35,9 @@ export class EventInactiveAccount extends EventBasicUserId {} export class EventSendConfirmationEmail extends EventBasicUserId {} export class EventSendAccountMultiregistrationEmail extends EventBasicUserId {} export class EventSendForgotPasswordEmail extends EventBasicUserId {} -export class EventSendTransactionSendEmail extends EventBasicRedeem {} -export class EventSendTransactionReceiveEmail extends EventBasicRedeem {} -export class EventSendTransactionLinkRedeemEmail extends EventBasicRedeem {} +export class EventSendTransactionSendEmail extends EventBasicTx {} +export class EventSendTransactionReceiveEmail extends EventBasicTx {} +export class EventSendTransactionLinkRedeemEmail extends EventBasicTx {} export class EventSendAddedContributionEmail extends EventBasicCt {} export class EventSendContributionConfirmEmail extends EventBasicCt {} export class EventConfirmationEmail extends EventBasicUserId {} @@ -57,9 +57,7 @@ export class EventTransactionCreation extends EventBasicUserId { export class EventTransactionReceive extends EventBasicTx {} export class EventTransactionReceiveRedeem extends EventBasicTx {} export class EventContributionCreate extends EventBasicCt {} -export class EventUserCreateContributionMessage extends EventBasicCt { - message: string -} +export class EventUserCreateContributionMessage extends EventBasicCt {} export class EventAdminCreateContributionMessage extends EventBasicCt { message: string } @@ -159,7 +157,10 @@ export class Event { public setEventSendTransactionSendEmail(ev: EventSendTransactionSendEmail): Event { this.setByBasicUser(ev.userId) - this.transactionId = ev.transactionId + if (ev.transactionId) this.transactionId = ev.transactionId + if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId + if (ev.xUserId) this.xUserId = ev.xUserId + if (ev.amount) this.amount = ev.amount this.type = EventProtocolType.SEND_TRANSACTION_SEND_EMAIL return this @@ -167,7 +168,10 @@ export class Event { public setEventSendTransactionReceiveEmail(ev: EventSendTransactionReceiveEmail): Event { this.setByBasicUser(ev.userId) - this.transactionId = ev.transactionId + if (ev.transactionId) this.transactionId = ev.transactionId + if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId + if (ev.xUserId) this.xUserId = ev.xUserId + if (ev.amount) this.amount = ev.amount this.type = EventProtocolType.SEND_TRANSACTION_RECEIVE_EMAIL return this @@ -175,7 +179,10 @@ export class Event { public setEventSendTransactionLinkRedeemEmail(ev: EventSendTransactionLinkRedeemEmail): Event { this.setByBasicUser(ev.userId) - this.transactionId = ev.transactionId + if (ev.transactionId) this.transactionId = ev.transactionId + if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId + if (ev.xUserId) this.xUserId = ev.xUserId + if (ev.amount) this.amount = ev.amount this.type = EventProtocolType.SEND_TRANSACTION_LINK_REDEEM_EMAIL return this @@ -183,7 +190,7 @@ export class Event { public setEventSendAddedContributionEmail(ev: EventSendAddedContributionEmail): Event { this.setByBasicUser(ev.userId) - this.contributionId = ev.contributionId + if (ev.contributionId) this.contributionId = ev.contributionId this.type = EventProtocolType.SEND_ADDED_CONTRIBUTION_EMAIL return this @@ -191,7 +198,7 @@ export class Event { public setEventSendContributionConfirmEmail(ev: EventSendContributionConfirmEmail): Event { this.setByBasicUser(ev.userId) - this.contributionId = ev.contributionId + if (ev.contributionId) this.contributionId = ev.contributionId this.type = EventProtocolType.SEND_CONTRIBUTION_CONFIRM_EMAIL return this From e97aac759fd33ec0e678789686f78d681d69a5ad Mon Sep 17 00:00:00 2001 From: joseji Date: Mon, 26 Sep 2022 23:00:33 +0200 Subject: [PATCH 09/26] typo camel case in 'send multiregistration email event' --- backend/src/event/Event.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 7c212978a..a0b5c05ec 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -33,7 +33,7 @@ export class EventRedeemRegister extends EventBasicRedeem {} export class EventVerifyRedeem extends EventBasicRedeem {} export class EventInactiveAccount extends EventBasicUserId {} export class EventSendConfirmationEmail extends EventBasicUserId {} -export class EventSendAccountMultiregistrationEmail extends EventBasicUserId {} +export class EventSendAccountMultiRegistrationEmail extends EventBasicUserId {} export class EventSendForgotPasswordEmail extends EventBasicUserId {} export class EventSendTransactionSendEmail extends EventBasicTx {} export class EventSendTransactionReceiveEmail extends EventBasicTx {} @@ -139,8 +139,8 @@ export class Event { return this } - public setEventSendAccountMultiregistrationEmail( - ev: EventSendAccountMultiregistrationEmail, + public setEventSendAccountMultiRegistrationEmail( + ev: EventSendAccountMultiRegistrationEmail, ): Event { this.setByBasicUser(ev.userId) this.type = EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL From ce280f6320c802ded0d9a422aabdb8a51d26a531 Mon Sep 17 00:00:00 2001 From: joseji Date: Thu, 29 Sep 2022 11:53:32 +0200 Subject: [PATCH 10/26] some conversations solved --- backend/src/event/Event.ts | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index a0b5c05ec..8b8834b59 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -22,11 +22,22 @@ export class EventBasicCt extends EventBasicUserId { amount: decimal } +export class EventBasicCtX extends EventBasicUserId { + xUserId: number + xCommunityId: number + contributionId: number + amount: decimal +} + export class EventBasicRedeem extends EventBasicUserId { transactionId?: number contributionId?: number } +export class EventBasicCtMsg extends EventBasicCt { + message: string +} + export class EventVisitGradido extends EventBasic {} export class EventRegister extends EventBasicUserId {} export class EventRedeemRegister extends EventBasicRedeem {} @@ -57,8 +68,8 @@ export class EventTransactionCreation extends EventBasicUserId { export class EventTransactionReceive extends EventBasicTx {} export class EventTransactionReceiveRedeem extends EventBasicTx {} export class EventContributionCreate extends EventBasicCt {} -export class EventUserCreateContributionMessage extends EventBasicCt {} -export class EventAdminCreateContributionMessage extends EventBasicCt { +export class EventUserCreateContributionMessage extends EventBasicCtMsg {} +export class EventAdminCreateContributionMessage extends EventBasicCtMsg { message: string } export class EventContributionDelete extends EventBasicCt {} @@ -67,10 +78,7 @@ export class EventContributionConfirm extends EventBasicCt { xUserId: number xCommunityId: number } -export class EventContributionDeny extends EventBasicCt { - xUserId: number - xCommunityId: number -} +export class EventContributionDeny extends EventBasicCtX {} export class EventContributionLinkDefine extends EventBasicCt {} export class EventContributionLinkActivateRedeem extends EventBasicCt {} @@ -306,14 +314,14 @@ export class Event { public setEventUserCreateContributionMessage(ev: EventUserCreateContributionMessage): Event { this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) this.type = EventProtocolType.USER_CREATE_CONTRIBUTION_MESSAGE - + this.message = ev.message return this } public setEventAdminCreateContributionMessage(ev: EventAdminCreateContributionMessage): Event { this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) this.type = EventProtocolType.ADMIN_CREATE_CONTRIBUTION_MESSAGE - + this.message = ev.message return this } @@ -341,9 +349,11 @@ export class Event { } public setEventContributionDeny(ev: EventContributionDeny): Event { - this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) - if (ev.xUserId) this.xUserId = ev.xUserId + this.setByBasicTx(ev.userId) + if (ev.contributionId) this.contributionId = ev.contributionId if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId + if (ev.xUserId) this.xUserId = ev.xUserId + if (ev.amount) this.amount = ev.amount this.type = EventProtocolType.CONTRIBUTION_DENY return this @@ -432,4 +442,5 @@ export class Event { transactionId?: number contributionId?: number amount?: decimal + message?: string } From 7061718c1f92aee84ef2c14aeb21055ad59162f9 Mon Sep 17 00:00:00 2001 From: joseji Date: Thu, 29 Sep 2022 12:20:08 +0200 Subject: [PATCH 11/26] all conversations solved --- backend/src/event/Event.ts | 78 ++++++++++--------- .../resolver/ContributionResolver.test.ts | 8 +- .../src/graphql/resolver/util/creations.ts | 2 +- 3 files changed, 46 insertions(+), 42 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 8b8834b59..ee24c768b 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -22,7 +22,7 @@ export class EventBasicCt extends EventBasicUserId { amount: decimal } -export class EventBasicCtX extends EventBasicUserId { +export class EventBasicCtX extends EventBasicCt { xUserId: number xCommunityId: number contributionId: number @@ -74,10 +74,7 @@ export class EventAdminCreateContributionMessage extends EventBasicCtMsg { } export class EventContributionDelete extends EventBasicCt {} export class EventContributionUpdate extends EventBasicCt {} -export class EventContributionConfirm extends EventBasicCt { - xUserId: number - xCommunityId: number -} +export class EventContributionConfirm extends EventBasicCtX {} export class EventContributionDeny extends EventBasicCtX {} export class EventContributionLinkDefine extends EventBasicCt {} export class EventContributionLinkActivateRedeem extends EventBasicCt {} @@ -164,50 +161,37 @@ export class Event { } public setEventSendTransactionSendEmail(ev: EventSendTransactionSendEmail): Event { - this.setByBasicUser(ev.userId) - if (ev.transactionId) this.transactionId = ev.transactionId - if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId - if (ev.xUserId) this.xUserId = ev.xUserId - if (ev.amount) this.amount = ev.amount + this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) this.type = EventProtocolType.SEND_TRANSACTION_SEND_EMAIL return this } public setEventSendTransactionReceiveEmail(ev: EventSendTransactionReceiveEmail): Event { - this.setByBasicUser(ev.userId) - if (ev.transactionId) this.transactionId = ev.transactionId - if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId - if (ev.xUserId) this.xUserId = ev.xUserId - if (ev.amount) this.amount = ev.amount + this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) this.type = EventProtocolType.SEND_TRANSACTION_RECEIVE_EMAIL return this } public setEventSendTransactionLinkRedeemEmail(ev: EventSendTransactionLinkRedeemEmail): Event { - this.setByBasicUser(ev.userId) - if (ev.transactionId) this.transactionId = ev.transactionId - if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId - if (ev.xUserId) this.xUserId = ev.xUserId - if (ev.amount) this.amount = ev.amount + this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) this.type = EventProtocolType.SEND_TRANSACTION_LINK_REDEEM_EMAIL return this } public setEventSendAddedContributionEmail(ev: EventSendAddedContributionEmail): Event { - this.setByBasicUser(ev.userId) - if (ev.contributionId) this.contributionId = ev.contributionId + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) this.type = EventProtocolType.SEND_ADDED_CONTRIBUTION_EMAIL return this } public setEventSendContributionConfirmEmail(ev: EventSendContributionConfirmEmail): Event { - this.setByBasicUser(ev.userId) - if (ev.contributionId) this.contributionId = ev.contributionId + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) this.type = EventProtocolType.SEND_CONTRIBUTION_CONFIRM_EMAIL + return this } @@ -312,16 +296,16 @@ export class Event { } public setEventUserCreateContributionMessage(ev: EventUserCreateContributionMessage): Event { - this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + this.setByBasicCtMsg(ev.userId, ev.contributionId, ev.amount, ev.message) this.type = EventProtocolType.USER_CREATE_CONTRIBUTION_MESSAGE - this.message = ev.message + return this } public setEventAdminCreateContributionMessage(ev: EventAdminCreateContributionMessage): Event { - this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + this.setByBasicCtMsg(ev.userId, ev.contributionId, ev.amount, ev.message) this.type = EventProtocolType.ADMIN_CREATE_CONTRIBUTION_MESSAGE - this.message = ev.message + return this } @@ -340,20 +324,14 @@ export class Event { } public setEventContributionConfirm(ev: EventContributionConfirm): Event { - this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) - if (ev.xUserId) this.xUserId = ev.xUserId - if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId + this.setByBasicCtX(ev.userId, ev.xUserId, ev.xCommunityId, ev.contributionId, ev.amount) this.type = EventProtocolType.CONTRIBUTION_CONFIRM return this } public setEventContributionDeny(ev: EventContributionDeny): Event { - this.setByBasicTx(ev.userId) - if (ev.contributionId) this.contributionId = ev.contributionId - if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId - if (ev.xUserId) this.xUserId = ev.xUserId - if (ev.amount) this.amount = ev.amount + this.setByBasicCtX(ev.userId, ev.xUserId, ev.xCommunityId, ev.contributionId, ev.amount) this.type = EventProtocolType.CONTRIBUTION_DENY return this @@ -404,6 +382,34 @@ export class Event { return this } + setByBasicCtMsg( + userId: number, + contributionId: number, + amount?: decimal, + message?: string, + ): Event { + this.setByBasicCt(userId, contributionId, amount) + if (message) this.message = message + + return this + } + + setByBasicCtX( + userId: number, + xUserId?: number, + xCommunityId?: number, + contributionId?: number, + amount?: decimal, + ): Event { + this.setByBasicUser(userId) + if (xUserId) this.xUserId = xUserId + if (xCommunityId) this.xCommunityId = xCommunityId + if (contributionId) this.contributionId = contributionId + if (amount) this.amount = amount + + return this + } + setByBasicRedeem(userId: number, transactionId?: number, contributionId?: number): Event { this.setByBasicUser(userId) if (transactionId) this.transactionId = transactionId diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index b8bbebbd9..199fb6c76 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -137,7 +137,7 @@ describe('ContributionResolver', () => { it('logs the error found', () => { expect(logger.error).toBeCalledWith( 'No information for available creations with the given creationDate=', - new Date('non-valid').toDateString, + 'Invalid Date', ) }) @@ -162,10 +162,9 @@ describe('ContributionResolver', () => { }) it('logs the error found', () => { - const date = new Date() expect(logger.error).toBeCalledWith( 'No information for available creations with the given creationDate=', - new Date(date.setMonth(date.getMonth() - 3).toString()).toDateString, + 'Invalid Date', ) }) }) @@ -560,10 +559,9 @@ describe('ContributionResolver', () => { }) it('logs the error found', () => { - const date = new Date() expect(logger.error).toBeCalledWith( 'No information for available creations with the given creationDate=', - new Date(date.setMonth(date.getMonth() - 3).toString()).toDateString, + 'Invalid Date', ) }) }) diff --git a/backend/src/graphql/resolver/util/creations.ts b/backend/src/graphql/resolver/util/creations.ts index b390e197d..9987dfae6 100644 --- a/backend/src/graphql/resolver/util/creations.ts +++ b/backend/src/graphql/resolver/util/creations.ts @@ -21,7 +21,7 @@ export const validateContribution = ( if (index < 0) { logger.error( 'No information for available creations with the given creationDate=', - creationDate.toDateString, + creationDate.toString(), ) throw new Error('No information for available creations for the given date') } From f05c31f69b90df32e71d424c08a166246dbe277e Mon Sep 17 00:00:00 2001 From: joseji Date: Thu, 29 Sep 2022 12:32:43 +0200 Subject: [PATCH 12/26] removed duplicated code --- backend/src/event/Event.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index ee24c768b..a70df23a2 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -69,9 +69,7 @@ export class EventTransactionReceive extends EventBasicTx {} export class EventTransactionReceiveRedeem extends EventBasicTx {} export class EventContributionCreate extends EventBasicCt {} export class EventUserCreateContributionMessage extends EventBasicCtMsg {} -export class EventAdminCreateContributionMessage extends EventBasicCtMsg { - message: string -} +export class EventAdminCreateContributionMessage extends EventBasicCtMsg {} export class EventContributionDelete extends EventBasicCt {} export class EventContributionUpdate extends EventBasicCt {} export class EventContributionConfirm extends EventBasicCtX {} From 7a21ec12e0ee2817d847dffabf7b55c85ec20f49 Mon Sep 17 00:00:00 2001 From: joseji Date: Tue, 4 Oct 2022 19:26:05 +0200 Subject: [PATCH 13/26] message changed for messageId and some small problems solved --- backend/src/event/Event.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index a70df23a2..3fbaf71f7 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -25,8 +25,6 @@ export class EventBasicCt extends EventBasicUserId { export class EventBasicCtX extends EventBasicCt { xUserId: number xCommunityId: number - contributionId: number - amount: decimal } export class EventBasicRedeem extends EventBasicUserId { @@ -35,7 +33,7 @@ export class EventBasicRedeem extends EventBasicUserId { } export class EventBasicCtMsg extends EventBasicCt { - message: string + messageId: number } export class EventVisitGradido extends EventBasic {} @@ -294,14 +292,14 @@ export class Event { } public setEventUserCreateContributionMessage(ev: EventUserCreateContributionMessage): Event { - this.setByBasicCtMsg(ev.userId, ev.contributionId, ev.amount, ev.message) + this.setByBasicCtMsg(ev.userId, ev.contributionId, ev.amount, ev.messageId) this.type = EventProtocolType.USER_CREATE_CONTRIBUTION_MESSAGE return this } public setEventAdminCreateContributionMessage(ev: EventAdminCreateContributionMessage): Event { - this.setByBasicCtMsg(ev.userId, ev.contributionId, ev.amount, ev.message) + this.setByBasicCtMsg(ev.userId, ev.contributionId, ev.amount, ev.messageId) this.type = EventProtocolType.ADMIN_CREATE_CONTRIBUTION_MESSAGE return this @@ -383,11 +381,11 @@ export class Event { setByBasicCtMsg( userId: number, contributionId: number, - amount?: decimal, - message?: string, + amount: decimal, + messageId: number, ): Event { this.setByBasicCt(userId, contributionId, amount) - if (message) this.message = message + if (messageId) this.messageId = messageId return this } @@ -446,5 +444,5 @@ export class Event { transactionId?: number contributionId?: number amount?: decimal - message?: string + messageId?: number } From 903fd4446e6efdf6f5c7540915d22c0b545deee8 Mon Sep 17 00:00:00 2001 From: joseji Date: Tue, 4 Oct 2022 20:32:10 +0200 Subject: [PATCH 14/26] changed database version --- backend/src/config/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 3e6bafd9f..b622293ad 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -10,7 +10,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0049-add_user_contacts_table', + DB_VERSION: '0050-add_messageId_to_event_protocol', DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info From 4853eea32a6995166ac33adf9c04c77be6f6db63 Mon Sep 17 00:00:00 2001 From: joseji Date: Tue, 4 Oct 2022 20:33:22 +0200 Subject: [PATCH 15/26] fixed wrong non mandatory attributes --- backend/src/event/Event.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 3fbaf71f7..832e61ec5 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -392,16 +392,16 @@ export class Event { setByBasicCtX( userId: number, - xUserId?: number, - xCommunityId?: number, - contributionId?: number, - amount?: decimal, + xUserId: number, + xCommunityId: number, + contributionId: number, + amount: decimal, ): Event { this.setByBasicUser(userId) - if (xUserId) this.xUserId = xUserId - if (xCommunityId) this.xCommunityId = xCommunityId - if (contributionId) this.contributionId = contributionId - if (amount) this.amount = amount + this.xUserId = xUserId + this.xCommunityId = xCommunityId + this.contributionId = contributionId + this.amount = amount return this } From bb3d1caa73ece468a60f68958ae0d393fca603a4 Mon Sep 17 00:00:00 2001 From: joseji Date: Tue, 4 Oct 2022 20:33:50 +0200 Subject: [PATCH 16/26] fixed amount not being initialized in databsae while storing events --- backend/src/graphql/resolver/ContributionResolver.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 9886eeb05..e7d9ecdaa 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -97,6 +97,7 @@ export class ContributionResolver { const eventDeleteContribution = new EventContributionDelete() eventDeleteContribution.userId = user.id eventDeleteContribution.contributionId = contribution.id + eventDeleteContribution.amount = contribution.amount await eventProtocol.writeEvent(event.setEventContributionDelete(eventDeleteContribution)) const res = await contribution.softRemove() @@ -209,6 +210,7 @@ export class ContributionResolver { const eventUpdateContribution = new EventContributionUpdate() eventUpdateContribution.userId = user.id eventUpdateContribution.contributionId = contributionId + eventUpdateContribution.amount = amount await eventProtocol.writeEvent(event.setEventContributionUpdate(eventUpdateContribution)) return new UnconfirmedContribution(contributionToUpdate, user, creations) From 65f53df9390fb617313bba246468875dc7013d85 Mon Sep 17 00:00:00 2001 From: joseji Date: Tue, 4 Oct 2022 20:34:37 +0200 Subject: [PATCH 17/26] added new column to event protocol dabatase table to keep message id --- .../EventProtocol.ts | 42 +++++++++++++++++++ .../0050-add_messageId_to_event_protocol.ts | 12 ++++++ 2 files changed, 54 insertions(+) create mode 100644 database/entity/0050-add_messageId_to_event_protocol/EventProtocol.ts create mode 100644 database/migrations/0050-add_messageId_to_event_protocol.ts diff --git a/database/entity/0050-add_messageId_to_event_protocol/EventProtocol.ts b/database/entity/0050-add_messageId_to_event_protocol/EventProtocol.ts new file mode 100644 index 000000000..d4dbc526f --- /dev/null +++ b/database/entity/0050-add_messageId_to_event_protocol/EventProtocol.ts @@ -0,0 +1,42 @@ +import Decimal from 'decimal.js-light' +import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm' +import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' + +@Entity('event_protocol') +export class EventProtocol extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ length: 100, nullable: false, collation: 'utf8mb4_unicode_ci' }) + type: string + + @Column({ name: 'created_at', type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) + createdAt: Date + + @Column({ name: 'user_id', unsigned: true, nullable: false }) + userId: number + + @Column({ name: 'x_user_id', unsigned: true, nullable: true }) + xUserId: number + + @Column({ name: 'x_community_id', unsigned: true, nullable: true }) + xCommunityId: number + + @Column({ name: 'transaction_id', unsigned: true, nullable: true }) + transactionId: number + + @Column({ name: 'contribution_id', unsigned: true, nullable: true }) + contributionId: number + + @Column({ + type: 'decimal', + precision: 40, + scale: 20, + nullable: true, + transformer: DecimalTransformer, + }) + amount: Decimal + + @Column({ name: 'message_id', unsigned: true, nullable: true }) + messageId: number +} diff --git a/database/migrations/0050-add_messageId_to_event_protocol.ts b/database/migrations/0050-add_messageId_to_event_protocol.ts new file mode 100644 index 000000000..ccef98688 --- /dev/null +++ b/database/migrations/0050-add_messageId_to_event_protocol.ts @@ -0,0 +1,12 @@ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn( + `ALTER TABLE \`event_protocol\` ADD COLUMN \`message_id\` int(10) unsigned NULL DEFAULT NULL;`, + ) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn(`ALTER TABLE \`event_protocol\` DROP COLUMN \`message_id\`;`) +} From 3eae1f60b292f95e20bccd0da96b670ec9631fa8 Mon Sep 17 00:00:00 2001 From: joseji Date: Tue, 4 Oct 2022 21:18:00 +0200 Subject: [PATCH 18/26] applied propper conventions and fixed code duplication --- backend/src/event/Event.ts | 113 ++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 65 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 832e61ec5..94266ebc0 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -11,12 +11,15 @@ export class EventBasicUserId extends EventBasic { } export class EventBasicTx extends EventBasicUserId { - xUserId: number - xCommunityId: number transactionId: number amount: decimal } +export class EventBasicTxX extends EventBasicTx { + xUserId: number + xCommunityId: number +} + export class EventBasicCt extends EventBasicUserId { contributionId: number amount: decimal @@ -28,8 +31,8 @@ export class EventBasicCtX extends EventBasicCt { } export class EventBasicRedeem extends EventBasicUserId { - transactionId?: number - contributionId?: number + transactionId: number + contributionId: number } export class EventBasicCtMsg extends EventBasicCt { @@ -44,9 +47,9 @@ export class EventInactiveAccount extends EventBasicUserId {} export class EventSendConfirmationEmail extends EventBasicUserId {} export class EventSendAccountMultiRegistrationEmail extends EventBasicUserId {} export class EventSendForgotPasswordEmail extends EventBasicUserId {} -export class EventSendTransactionSendEmail extends EventBasicTx {} -export class EventSendTransactionReceiveEmail extends EventBasicTx {} -export class EventSendTransactionLinkRedeemEmail extends EventBasicTx {} +export class EventSendTransactionSendEmail extends EventBasicTxX {} +export class EventSendTransactionReceiveEmail extends EventBasicTxX {} +export class EventSendTransactionLinkRedeemEmail extends EventBasicTxX {} export class EventSendAddedContributionEmail extends EventBasicCt {} export class EventSendContributionConfirmEmail extends EventBasicCt {} export class EventConfirmationEmail extends EventBasicUserId {} @@ -56,15 +59,12 @@ export class EventLogout extends EventBasicUserId {} export class EventRedeemLogin extends EventBasicRedeem {} export class EventActivateAccount extends EventBasicUserId {} export class EventPasswordChange extends EventBasicUserId {} -export class EventTransactionSend extends EventBasicTx {} -export class EventTransactionSendRedeem extends EventBasicTx {} -export class EventTransactionRepeateRedeem extends EventBasicTx {} -export class EventTransactionCreation extends EventBasicUserId { - transactionId: number - amount: decimal -} -export class EventTransactionReceive extends EventBasicTx {} -export class EventTransactionReceiveRedeem extends EventBasicTx {} +export class EventTransactionSend extends EventBasicTxX {} +export class EventTransactionSendRedeem extends EventBasicTxX {} +export class EventTransactionRepeateRedeem extends EventBasicTxX {} +export class EventTransactionCreation extends EventBasicTx {} +export class EventTransactionReceive extends EventBasicTxX {} +export class EventTransactionReceiveRedeem extends EventBasicTxX {} export class EventContributionCreate extends EventBasicCt {} export class EventUserCreateContributionMessage extends EventBasicCtMsg {} export class EventAdminCreateContributionMessage extends EventBasicCtMsg {} @@ -157,21 +157,21 @@ export class Event { } public setEventSendTransactionSendEmail(ev: EventSendTransactionSendEmail): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.SEND_TRANSACTION_SEND_EMAIL return this } public setEventSendTransactionReceiveEmail(ev: EventSendTransactionReceiveEmail): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.SEND_TRANSACTION_RECEIVE_EMAIL return this } public setEventSendTransactionLinkRedeemEmail(ev: EventSendTransactionLinkRedeemEmail): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.SEND_TRANSACTION_LINK_REDEEM_EMAIL return this @@ -241,44 +241,42 @@ export class Event { } public setEventTransactionSend(ev: EventTransactionSend): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.TRANSACTION_SEND return this } public setEventTransactionSendRedeem(ev: EventTransactionSendRedeem): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.TRANSACTION_SEND_REDEEM return this } public setEventTransactionRepeateRedeem(ev: EventTransactionRepeateRedeem): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.TRANSACTION_REPEATE_REDEEM return this } public setEventTransactionCreation(ev: EventTransactionCreation): Event { - this.setByBasicUser(ev.userId) - if (ev.transactionId) this.transactionId = ev.transactionId - if (ev.amount) this.amount = ev.amount + this.setByBasicTx(ev.userId, ev.transactionId, ev.amount) this.type = EventProtocolType.TRANSACTION_CREATION return this } public setEventTransactionReceive(ev: EventTransactionReceive): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.TRANSACTION_RECEIVE return this } public setEventTransactionReceiveRedeem(ev: EventTransactionReceiveRedeem): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.TRANSACTION_RECEIVE_REDEEM return this @@ -354,26 +352,32 @@ export class Event { return this } - setByBasicTx( - userId: number, - xUserId?: number, - xCommunityId?: number, - transactionId?: number, - amount?: decimal, - ): Event { + setByBasicTx(userId: number, transactionId: number, amount: decimal): Event { this.setByBasicUser(userId) - if (xUserId) this.xUserId = xUserId - if (xCommunityId) this.xCommunityId = xCommunityId - if (transactionId) this.transactionId = transactionId - if (amount) this.amount = amount + this.transactionId = transactionId + this.amount = amount return this } - setByBasicCt(userId: number, contributionId: number, amount?: decimal): Event { + setByBasicTxX( + userId: number, + transactionId: number, + amount: decimal, + xUserId: number, + xCommunityId: number, + ): Event { + this.setByBasicTx(userId, transactionId, amount) + this.xUserId = xUserId + this.xCommunityId = xCommunityId + + return this + } + + setByBasicCt(userId: number, contributionId: number, amount: decimal): Event { this.setByBasicUser(userId) - if (contributionId) this.contributionId = contributionId - if (amount) this.amount = amount + this.contributionId = contributionId + this.amount = amount return this } @@ -406,31 +410,10 @@ export class Event { return this } - setByBasicRedeem(userId: number, transactionId?: number, contributionId?: number): Event { + setByBasicRedeem(userId: number, transactionId: number, contributionId: number): Event { this.setByBasicUser(userId) - if (transactionId) this.transactionId = transactionId - if (contributionId) this.contributionId = contributionId - - return this - } - - setByEventTransactionCreation(event: EventTransactionCreation): Event { - this.type = event.type - this.createdAt = event.createdAt - this.userId = event.userId - this.transactionId = event.transactionId - this.amount = event.amount - - return this - } - - setByEventContributionConfirm(event: EventContributionConfirm): Event { - this.type = event.type - this.createdAt = event.createdAt - this.userId = event.userId - this.xUserId = event.xUserId - this.xCommunityId = event.xCommunityId - this.amount = event.amount + this.transactionId = transactionId + this.contributionId = contributionId return this } From ad174e6e0a8a2a8d6b84a401284c9965242bf66e Mon Sep 17 00:00:00 2001 From: joseji Date: Fri, 7 Oct 2022 12:09:09 +0200 Subject: [PATCH 19/26] corrections --- backend/src/event/Event.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 94266ebc0..cec94e5bf 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -31,8 +31,8 @@ export class EventBasicCtX extends EventBasicCt { } export class EventBasicRedeem extends EventBasicUserId { - transactionId: number - contributionId: number + transactionId?: number + contributionId?: number } export class EventBasicCtMsg extends EventBasicCt { @@ -389,31 +389,29 @@ export class Event { messageId: number, ): Event { this.setByBasicCt(userId, contributionId, amount) - if (messageId) this.messageId = messageId + this.messageId = messageId return this } setByBasicCtX( userId: number, - xUserId: number, - xCommunityId: number, contributionId: number, amount: decimal, + xUserId: number, + xCommunityId: number, ): Event { - this.setByBasicUser(userId) + this.setByBasicCt(userId, contributionId, amount) this.xUserId = xUserId this.xCommunityId = xCommunityId - this.contributionId = contributionId - this.amount = amount return this } - setByBasicRedeem(userId: number, transactionId: number, contributionId: number): Event { + setByBasicRedeem(userId: number, transactionId?: number, contributionId?: number): Event { this.setByBasicUser(userId) - this.transactionId = transactionId - this.contributionId = contributionId + if (transactionId) this.transactionId = transactionId + if (contributionId) this.contributionId = contributionId return this } From 84d87bbee6a5bd3b8fa078070c62781bc543ce85 Mon Sep 17 00:00:00 2001 From: joseji Date: Fri, 7 Oct 2022 12:15:49 +0200 Subject: [PATCH 20/26] fixed wrong order on one method call parameters --- backend/src/event/Event.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index cec94e5bf..d86ddf15f 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -318,14 +318,14 @@ export class Event { } public setEventContributionConfirm(ev: EventContributionConfirm): Event { - this.setByBasicCtX(ev.userId, ev.xUserId, ev.xCommunityId, ev.contributionId, ev.amount) + this.setByBasicCtX(ev.userId, ev.contributionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.CONTRIBUTION_CONFIRM return this } public setEventContributionDeny(ev: EventContributionDeny): Event { - this.setByBasicCtX(ev.userId, ev.xUserId, ev.xCommunityId, ev.contributionId, ev.amount) + this.setByBasicCtX(ev.userId, ev.contributionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.CONTRIBUTION_DENY return this From d799eecadaf4c503c5aa92da2e85583066e8efc7 Mon Sep 17 00:00:00 2001 From: joseji Date: Tue, 11 Oct 2022 12:11:18 +0200 Subject: [PATCH 21/26] added contributionId and amount to some tests --- .../resolver/ContributionResolver.test.ts | 38 +++++++++++++------ database/entity/EventProtocol.ts | 2 +- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 199fb6c76..14e4d19b2 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -170,17 +170,21 @@ describe('ContributionResolver', () => { }) describe('valid input', () => { + let contribution: any + + beforeAll(async () => { + contribution = await mutate({ + mutation: createContribution, + variables: { + amount: 100.0, + memo: 'Test env contribution', + creationDate: new Date().toString(), + }, + }) + }) + it('creates contribution', async () => { - await expect( - mutate({ - mutation: createContribution, - variables: { - amount: 100.0, - memo: 'Test env contribution', - creationDate: new Date().toString(), - }, - }), - ).resolves.toEqual( + expect(contribution).toEqual( expect.objectContaining({ data: { createContribution: { @@ -197,6 +201,8 @@ describe('ContributionResolver', () => { await expect(EventProtocol.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_CREATE, + // amount: '100', FAILS even though it is stored correctly in the database, event has 100 stored + contributionId: contribution.data.createContribution.id, userId: bibi.data.login.id, }), ) @@ -592,10 +598,17 @@ describe('ContributionResolver', () => { }) it('stores the update contribution event in the database', async () => { + bibi = await query({ + query: login, + variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, + }) + await expect(EventProtocol.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_UPDATE, + // amount: '10', FAILS even though it is stored correctly in the database, it is 10 in the event contributionId: result.data.createContribution.id, + userId: bibi.data.login.id, }), ) }) @@ -705,9 +718,10 @@ describe('ContributionResolver', () => { }) describe('authenticated', () => { + let peter: any beforeAll(async () => { await userFactory(testEnv, bibiBloxberg) - await userFactory(testEnv, peterLustig) + peter = await userFactory(testEnv, peterLustig) await query({ query: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, @@ -806,6 +820,8 @@ describe('ContributionResolver', () => { expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_DELETE, contributionId: contribution.data.createContribution.id, + // amount: '166', FAILS even though it is stored correctly in the database, it is 166 in the event + userId: peter.id, }), ) }) diff --git a/database/entity/EventProtocol.ts b/database/entity/EventProtocol.ts index 4a73f146c..6ebbd3d68 100644 --- a/database/entity/EventProtocol.ts +++ b/database/entity/EventProtocol.ts @@ -1 +1 @@ -export { EventProtocol } from './0043-add_event_protocol_table/EventProtocol' +export { EventProtocol } from './0050-add_messageId_to_event_protocol/EventProtocol' From cbdb68f3856266e5a871083c971a790496c2d064 Mon Sep 17 00:00:00 2001 From: joseji Date: Mon, 17 Oct 2022 23:22:04 +0200 Subject: [PATCH 22/26] missed 1 decimal check on tests --- backend/src/graphql/resolver/ContributionResolver.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 2a40f2100..323efe5d9 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -203,7 +203,7 @@ describe('ContributionResolver', () => { await expect(EventProtocol.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_CREATE, - // amount: '100', FAILS even though it is stored correctly in the database, event has 100 stored + amount: expect.decimalEqual(100), contributionId: contribution.data.createContribution.id, userId: bibi.data.login.id, }), From 02f9439bd2a3c9844738b0040bd52530b55a2326 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 19 Oct 2022 19:16:21 +0200 Subject: [PATCH 23/26] correctly evaluate to false --- backend/src/config/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index b622293ad..c9543902e 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -67,7 +67,7 @@ const loginServer = { const email = { EMAIL: process.env.EMAIL === 'true' || false, - EMAIL_TEST_MODUS: process.env.EMAIL_TEST_MODUS === 'true' || 'false', + EMAIL_TEST_MODUS: process.env.EMAIL_TEST_MODUS === 'true' || false, EMAIL_TEST_RECEIVER: process.env.EMAIL_TEST_RECEIVER || 'stage1@gradido.net', EMAIL_USERNAME: process.env.EMAIL_USERNAME || 'gradido_email', EMAIL_SENDER: process.env.EMAIL_SENDER || 'info@gradido.net', From e9f40bc63811766d98d3eab0ebb55710fe1a982d Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 20 Oct 2022 09:47:59 +0200 Subject: [PATCH 24/26] fix unit test --- backend/src/mailer/sendEMail.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/mailer/sendEMail.test.ts b/backend/src/mailer/sendEMail.test.ts index a6f4bb62a..5746f1ead 100644 --- a/backend/src/mailer/sendEMail.test.ts +++ b/backend/src/mailer/sendEMail.test.ts @@ -73,7 +73,7 @@ describe('sendEMail', () => { it('calls sendMail of transporter', () => { expect((createTransport as jest.Mock).mock.results[0].value.sendMail).toBeCalledWith({ from: `Gradido (nicht antworten) <${CONFIG.EMAIL_SENDER}>`, - to: `${CONFIG.EMAIL_TEST_RECEIVER}`, + to: 'receiver@mail.org', cc: 'support@gradido.net', subject: 'Subject', text: 'Text text text', From 39df2a4e96c35351fdfb480ad8613abf3072bccc Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 20 Oct 2022 10:21:39 +0200 Subject: [PATCH 25/26] test send email with test modus true --- backend/src/mailer/sendEMail.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/backend/src/mailer/sendEMail.test.ts b/backend/src/mailer/sendEMail.test.ts index 5746f1ead..8e3b0c4a2 100644 --- a/backend/src/mailer/sendEMail.test.ts +++ b/backend/src/mailer/sendEMail.test.ts @@ -29,6 +29,7 @@ describe('sendEMail', () => { let result: boolean describe('config email is false', () => { beforeEach(async () => { + jest.clearAllMocks() result = await sendEMail({ to: 'receiver@mail.org', cc: 'support@gradido.net', @@ -48,6 +49,7 @@ describe('sendEMail', () => { describe('config email is true', () => { beforeEach(async () => { + jest.clearAllMocks() CONFIG.EMAIL = true result = await sendEMail({ to: 'receiver@mail.org', @@ -84,4 +86,28 @@ describe('sendEMail', () => { expect(result).toBeTruthy() }) }) + + describe('with email EMAIL_TEST_MODUS true', () => { + beforeEach(async () => { + jest.clearAllMocks() + CONFIG.EMAIL = true + CONFIG.EMAIL_TEST_MODUS = true + result = await sendEMail({ + to: 'receiver@mail.org', + cc: 'support@gradido.net', + subject: 'Subject', + text: 'Text text text', + }) + }) + + it('calls sendMail of transporter with faked to', () => { + expect((createTransport as jest.Mock).mock.results[0].value.sendMail).toBeCalledWith({ + from: `Gradido (nicht antworten) <${CONFIG.EMAIL_SENDER}>`, + to: CONFIG.EMAIL_TEST_RECEIVER, + cc: 'support@gradido.net', + subject: 'Subject', + text: 'Text text text', + }) + }) + }) }) From 886a8291c9a9a5fad5b609997314e997857b7af4 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 20 Oct 2022 10:56:19 +0200 Subject: [PATCH 26/26] release: Version 1.13.1 --- CHANGELOG.md | 8 ++++++++ admin/package.json | 2 +- backend/package.json | 2 +- database/package.json | 2 +- frontend/package.json | 2 +- package.json | 2 +- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index feb54d798..d4eb48283 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,16 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [1.13.1](https://github.com/gradido/gradido/compare/1.13.0...1.13.1) + +- Fix: correctly evaluate to EMAIL_TEST_MODE to false [`#2273`](https://github.com/gradido/gradido/pull/2273) +- Refactor: Contribution resolver logs and events [`#2231`](https://github.com/gradido/gradido/pull/2231) + #### [1.13.0](https://github.com/gradido/gradido/compare/1.12.1...1.13.0) +> 18 October 2022 + +- release: Version 1.13.0 [`#2269`](https://github.com/gradido/gradido/pull/2269) - fix: Linked User Email in Transaction List [`#2268`](https://github.com/gradido/gradido/pull/2268) - concept capturing alias [`#2148`](https://github.com/gradido/gradido/pull/2148) - fix: 🍰 Daily Redeem Of Contribution Link [`#2265`](https://github.com/gradido/gradido/pull/2265) diff --git a/admin/package.json b/admin/package.json index 3d592361e..2db889771 100644 --- a/admin/package.json +++ b/admin/package.json @@ -3,7 +3,7 @@ "description": "Administraion Interface for Gradido", "main": "index.js", "author": "Moriz Wahl", - "version": "1.13.0", + "version": "1.13.1", "license": "Apache-2.0", "private": false, "scripts": { diff --git a/backend/package.json b/backend/package.json index 57516263c..6cd886735 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "gradido-backend", - "version": "1.13.0", + "version": "1.13.1", "description": "Gradido unified backend providing an API-Service for Gradido Transactions", "main": "src/index.ts", "repository": "https://github.com/gradido/gradido/backend", diff --git a/database/package.json b/database/package.json index 9341b6445..0a97b5135 100644 --- a/database/package.json +++ b/database/package.json @@ -1,6 +1,6 @@ { "name": "gradido-database", - "version": "1.13.0", + "version": "1.13.1", "description": "Gradido Database Tool to execute database migrations", "main": "src/index.ts", "repository": "https://github.com/gradido/gradido/database", diff --git a/frontend/package.json b/frontend/package.json index 0c1cd305c..2fc892f9f 100755 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "bootstrap-vue-gradido-wallet", - "version": "1.13.0", + "version": "1.13.1", "private": true, "scripts": { "start": "node run/server.js", diff --git a/package.json b/package.json index 98f256324..f306a1e06 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gradido", - "version": "1.13.0", + "version": "1.13.1", "description": "Gradido", "main": "index.js", "repository": "git@github.com:gradido/gradido.git",