mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
tests for the two new events
This commit is contained in:
parent
933e9168bc
commit
fd912fb6c8
@ -15,6 +15,8 @@ import { userFactory } from '@/seeds/factory/user'
|
||||
import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg'
|
||||
import { peterLustig } from '@/seeds/users/peter-lustig'
|
||||
import { sendAddedContributionMessageEmail } from '@/emails/sendEmailVariants'
|
||||
import { EventType } from '@/event/Event'
|
||||
import { Event as DbEvent } from '@entity/Event'
|
||||
|
||||
jest.mock('@/emails/sendEmailVariants', () => {
|
||||
const originalModule = jest.requireActual('@/emails/sendEmailVariants')
|
||||
@ -192,6 +194,18 @@ describe('ContributionMessageResolver', () => {
|
||||
contributionMemo: 'Test env contribution',
|
||||
})
|
||||
})
|
||||
|
||||
it('stores the ADMIN_CONTRIBUTION_MESSAGE_CREATE event in the database', async () => {
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventType.ADMIN_CONTRIBUTION_MESSAGE_CREATE,
|
||||
affectedUserId: expect.any(Number),
|
||||
actingUserId: expect.any(Number),
|
||||
involvedContributionId: result.data.createContribution.id,
|
||||
involvedContributionMessageId: expect.any(Number),
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -317,6 +331,18 @@ describe('ContributionMessageResolver', () => {
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('stores the CONTRIBUTION_MESSAGE_CREATE event in the database', async () => {
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventType.CONTRIBUTION_MESSAGE_CREATE,
|
||||
affectedUserId: expect.any(Number),
|
||||
actingUserId: expect.any(Number),
|
||||
involvedContributionId: result.data.createContribution.id,
|
||||
involvedContributionMessageId: expect.any(Number),
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -3,7 +3,8 @@ import { getConnection } from '@dbTools/typeorm'
|
||||
|
||||
import { ContributionMessage as DbContributionMessage } from '@entity/ContributionMessage'
|
||||
import { Contribution as DbContribution } from '@entity/Contribution'
|
||||
import { UserContact } from '@entity/UserContact'
|
||||
import { UserContact as DbUserContact } from '@entity/UserContact'
|
||||
import { User as DbUser } from '@entity/User'
|
||||
|
||||
import { ContributionMessage, ContributionMessageListResult } from '@model/ContributionMessage'
|
||||
import ContributionMessageArgs from '@arg/ContributionMessageArgs'
|
||||
@ -16,7 +17,10 @@ import { RIGHTS } from '@/auth/RIGHTS'
|
||||
import { Context, getUser } from '@/server/context'
|
||||
import { sendAddedContributionMessageEmail } from '@/emails/sendEmailVariants'
|
||||
import LogError from '@/server/LogError'
|
||||
import { EVENT_CONTRIBUTION_MESSAGE_CREATE } from '@/event/Event'
|
||||
import {
|
||||
EVENT_ADMIN_CONTRIBUTION_MESSAGE_CREATE,
|
||||
EVENT_CONTRIBUTION_MESSAGE_CREATE,
|
||||
} from '@/event/Event'
|
||||
|
||||
@Resolver()
|
||||
export class ContributionMessageResolver {
|
||||
@ -121,7 +125,7 @@ export class ContributionMessageResolver {
|
||||
throw new LogError('Admin can not answer on his own contribution', contributionId)
|
||||
}
|
||||
if (!contribution.user.emailContact) {
|
||||
contribution.user.emailContact = await UserContact.findOneOrFail({
|
||||
contribution.user.emailContact = await DbUserContact.findOneOrFail({
|
||||
where: { id: contribution.user.emailId },
|
||||
})
|
||||
}
|
||||
@ -152,13 +156,18 @@ export class ContributionMessageResolver {
|
||||
contributionMemo: contribution.memo,
|
||||
})
|
||||
await queryRunner.commitTransaction()
|
||||
await EVENT_ADMIN_CONTRIBUTION_MESSAGE_CREATE({id: contribution.userId} as DbUser, moderator, contribution, contributionMessage)
|
||||
await EVENT_ADMIN_CONTRIBUTION_MESSAGE_CREATE(
|
||||
{ id: contribution.userId } as DbUser,
|
||||
moderator,
|
||||
contribution,
|
||||
contributionMessage,
|
||||
)
|
||||
} catch (e) {
|
||||
await queryRunner.rollbackTransaction()
|
||||
throw new LogError(`ContributionMessage was not sent successfully: ${e}`, e)
|
||||
} finally {
|
||||
await queryRunner.release()
|
||||
}
|
||||
return new ContributionMessage(contributionMessage, user)
|
||||
return new ContributionMessage(contributionMessage, moderator)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user