mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
added tests for events
This commit is contained in:
parent
33eeab344f
commit
0f1f9baa8d
@ -41,6 +41,8 @@ import { Contribution } from '@entity/Contribution'
|
|||||||
import { Transaction as DbTransaction } from '@entity/Transaction'
|
import { Transaction as DbTransaction } from '@entity/Transaction'
|
||||||
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
|
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
|
||||||
import { sendContributionConfirmedEmail } from '@/mailer/sendContributionConfirmedEmail'
|
import { sendContributionConfirmedEmail } from '@/mailer/sendContributionConfirmedEmail'
|
||||||
|
import { EventProtocol } from '@entity/EventProtocol'
|
||||||
|
import { EventProtocolType } from '@/event/EventProtocolType'
|
||||||
|
|
||||||
// mock account activation email to avoid console spam
|
// mock account activation email to avoid console spam
|
||||||
jest.mock('@/mailer/sendAccountActivationEmail', () => {
|
jest.mock('@/mailer/sendAccountActivationEmail', () => {
|
||||||
@ -1037,6 +1039,15 @@ describe('AdminResolver', () => {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('stores the create contribution event in the database', async () => {
|
||||||
|
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
type: EventProtocolType.CONTRIBUTION_CREATE,
|
||||||
|
userId: admin.id,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('second creation surpasses the available amount ', () => {
|
describe('second creation surpasses the available amount ', () => {
|
||||||
@ -1451,6 +1462,14 @@ describe('AdminResolver', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('stores the contribution confirm event in the database', async () => {
|
||||||
|
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
type: EventProtocolType.CONTRIBUTION_CONFIRM,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it('creates a transaction', async () => {
|
it('creates a transaction', async () => {
|
||||||
const transaction = await DbTransaction.find()
|
const transaction = await DbTransaction.find()
|
||||||
expect(transaction[0].amount.toString()).toBe('450')
|
expect(transaction[0].amount.toString()).toBe('450')
|
||||||
@ -1475,6 +1494,14 @@ describe('AdminResolver', () => {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('stores the send confirmation email event in the database', async () => {
|
||||||
|
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
type: EventProtocolType.SEND_CONFIRMATION_EMAIL,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('confirm two creations one after the other quickly', () => {
|
describe('confirm two creations one after the other quickly', () => {
|
||||||
|
|||||||
@ -67,7 +67,12 @@ import { ContributionMessage } from '@model/ContributionMessage'
|
|||||||
import { sendContributionConfirmedEmail } from '@/mailer/sendContributionConfirmedEmail'
|
import { sendContributionConfirmedEmail } from '@/mailer/sendContributionConfirmedEmail'
|
||||||
import { sendAddedContributionMessageEmail } from '@/mailer/sendAddedContributionMessageEmail'
|
import { sendAddedContributionMessageEmail } from '@/mailer/sendAddedContributionMessageEmail'
|
||||||
import { eventProtocol } from '@/event/EventProtocolEmitter'
|
import { eventProtocol } from '@/event/EventProtocolEmitter'
|
||||||
import { Event, EventContributionConfirm, EventContributionCreate, EventContributionLinkDefine, EventSendConfirmationEmail } from '@/event/Event'
|
import {
|
||||||
|
Event,
|
||||||
|
EventContributionConfirm,
|
||||||
|
EventContributionCreate,
|
||||||
|
EventSendConfirmationEmail,
|
||||||
|
} from '@/event/Event'
|
||||||
|
|
||||||
// const EMAIL_OPT_IN_REGISTER = 1
|
// const EMAIL_OPT_IN_REGISTER = 1
|
||||||
// const EMAIL_OPT_UNKNOWN = 3 // elopage?
|
// const EMAIL_OPT_UNKNOWN = 3 // elopage?
|
||||||
@ -514,13 +519,6 @@ export class AdminResolver {
|
|||||||
contributionAmount: contribution.amount,
|
contributionAmount: contribution.amount,
|
||||||
overviewURL: CONFIG.EMAIL_LINK_OVERVIEW,
|
overviewURL: CONFIG.EMAIL_LINK_OVERVIEW,
|
||||||
})
|
})
|
||||||
|
|
||||||
const event = new Event()
|
|
||||||
const eventContributionConfirm = new EventContributionConfirm()
|
|
||||||
eventContributionConfirm.xUserId = user.id
|
|
||||||
eventContributionConfirm.amount = contribution.amount
|
|
||||||
eventContributionConfirm.contributionId = contribution.id
|
|
||||||
await eventProtocol.writeEvent(event.setEventContributionConfirm(eventContributionConfirm))
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await queryRunner.rollbackTransaction()
|
await queryRunner.rollbackTransaction()
|
||||||
logger.error(`Creation was not successful: ${e}`)
|
logger.error(`Creation was not successful: ${e}`)
|
||||||
@ -528,6 +526,13 @@ export class AdminResolver {
|
|||||||
} finally {
|
} finally {
|
||||||
await queryRunner.release()
|
await queryRunner.release()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const event = new Event()
|
||||||
|
const eventContributionConfirm = new EventContributionConfirm()
|
||||||
|
eventContributionConfirm.userId = user.id
|
||||||
|
eventContributionConfirm.amount = contribution.amount
|
||||||
|
eventContributionConfirm.contributionId = contribution.id
|
||||||
|
await eventProtocol.writeEvent(event.setEventContributionConfirm(eventContributionConfirm))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -693,13 +698,6 @@ export class AdminResolver {
|
|||||||
dbContributionLink.maxAmountPerMonth = maxAmountPerMonth
|
dbContributionLink.maxAmountPerMonth = maxAmountPerMonth
|
||||||
dbContributionLink.maxPerCycle = maxPerCycle
|
dbContributionLink.maxPerCycle = maxPerCycle
|
||||||
await dbContributionLink.save()
|
await dbContributionLink.save()
|
||||||
|
|
||||||
const event = new Event()
|
|
||||||
const eventContributionLinkDefine = new EventContributionLinkDefine()
|
|
||||||
await eventProtocol.writeEvent(
|
|
||||||
event.setEventContributionLinkDefine(eventContributionLinkDefine),
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.debug(`createContributionLink successful!`)
|
logger.debug(`createContributionLink successful!`)
|
||||||
return new ContributionLink(dbContributionLink)
|
return new ContributionLink(dbContributionLink)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user