IDs also tested while event saving, added ActivateAccount event when setting password

This commit is contained in:
joseji 2022-09-16 12:22:32 +02:00
parent ded649f342
commit 390bb1db3d
2 changed files with 18 additions and 0 deletions

View File

@ -176,6 +176,7 @@ describe('UserResolver', () => {
expect(EventProtocol.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventProtocolType.SEND_CONFIRMATION_EMAIL,
userId: expect.any(Number), // as it is randomly generated
}),
)
})
@ -255,6 +256,7 @@ describe('UserResolver', () => {
mutation: setPassword,
variables: { code: emailOptIn, password: 'Aa12345_' },
})
// make Peter Lustig Admin
const peter = await User.findOneOrFail({ id: user[0].id })
peter.isAdmin = new Date()
@ -281,6 +283,15 @@ describe('UserResolver', () => {
}),
)
})
it('stores the account activated event in the database', () => {
expect(EventProtocol.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventProtocolType.ACTIVATE_ACCOUNT,
userId: expect.any(Number), // as it is randomly generated
}),
)
})
})
/* A transaction link requires GDD on account
@ -625,6 +636,7 @@ bei Gradidio sei dabei!`,
expect(EventProtocol.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventProtocolType.LOGIN,
userId: expect.any(Number), // as it is randomly generated
}),
)
})

View File

@ -30,6 +30,7 @@ import {
EventRedeemRegister,
EventRegister,
EventSendConfirmationEmail,
EventActivateAccount,
} from '@/event/Event'
import { getUserCreation } from './util/creations'
import { UserRepository } from '@/typeorm/repository/User'
@ -611,6 +612,8 @@ export class UserResolver {
await queryRunner.connect()
await queryRunner.startTransaction('READ UNCOMMITTED')
const event = new Event()
try {
// Save user
await queryRunner.manager.save(user).catch((error) => {
@ -619,6 +622,9 @@ export class UserResolver {
})
await queryRunner.commitTransaction()
const eventActivateAccount = new EventActivateAccount()
eventActivateAccount.userId = user.id
eventProtocol.writeEvent(event.setEventActivateAccount(eventActivateAccount))
logger.info('User data written successfully...')
} catch (e) {
await queryRunner.rollbackTransaction()