From e79130ea868198680bd30b9a085f52d143e61e7b Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 9 Mar 2023 12:19:53 +0100 Subject: [PATCH] test all events --- .../src/graphql/resolver/UserResolver.test.ts | 98 ++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index b382b2627..62eea9c0e 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -857,11 +857,25 @@ describe('UserResolver', () => { it('returns true', async () => { await expect(mutate({ mutation: logout })).resolves.toEqual( expect.objectContaining({ - data: { logout: 'true' }, + data: { logout: true }, errors: undefined, }), ) }) + + it('stores the LOGOUT event in the database', async () => { + const userConatct = await UserContact.findOneOrFail( + { email: 'bibi@bloxberg.de' }, + { relations: ['user'] }, + ) + expect(DbEvent.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventType.LOGOUT, + affectedUserId: userConatct.user.id, + actingUserId: userConatct.user.id, + }), + ) + }) }) }) @@ -1017,6 +1031,20 @@ describe('UserResolver', () => { }), }) }) + + it('stores the EMAIL_FORGOT_PASSWORD event in the database', async () => { + const userConatct = await UserContact.findOneOrFail( + { email: 'bibi@bloxberg.de' }, + { relations: ['user'] }, + ) + expect(DbEvent.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventType.EMAIL_FORGOT_PASSWORD, + affectedUserId: userConatct.user.id, + actingUserId: 0, + }), + ) + }) }) describe('request reset password again', () => { @@ -1141,6 +1169,20 @@ describe('UserResolver', () => { }), ) }) + + it('stores the USER_INFO_UPDATE event in the database', async () => { + const userConatct = await UserContact.findOneOrFail( + { email: 'bibi@bloxberg.de' }, + { relations: ['user'] }, + ) + expect(DbEvent.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventType.USER_INFO_UPDATE, + affectedUserId: userConatct.user.id, + actingUserId: userConatct.user.id, + }), + ) + }) }) describe('language is not valid', () => { @@ -1511,6 +1553,24 @@ describe('UserResolver', () => { ) expect(new Date(result.data.setUserRole)).toEqual(expect.any(Date)) }) + + it('stores the ADMIN_USER_ROLE_SET event in the database', async () => { + const userConatct = await UserContact.findOneOrFail( + { email: 'bibi@bloxberg.de' }, + { relations: ['user'] }, + ) + const adminConatct = await UserContact.findOneOrFail( + { email: 'peter@lustig.de' }, + { relations: ['user'] }, + ) + expect(DbEvent.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventType.ADMIN_USER_ROLE_SET, + affectedUserId: userConatct.user.id, + actingUserId: adminConatct.user.id, + }), + ) + }) }) describe('to usual user', () => { @@ -1696,6 +1756,24 @@ describe('UserResolver', () => { expect(new Date(result.data.deleteUser)).toEqual(expect.any(Date)) }) + it('stores the ADMIN_USER_DELETE event in the database', async () => { + const userConatct = await UserContact.findOneOrFail( + { email: 'bibi@bloxberg.de' }, + { relations: ['user'], withDeleted: true }, + ) + const adminConatct = await UserContact.findOneOrFail( + { email: 'peter@lustig.de' }, + { relations: ['user'] }, + ) + expect(DbEvent.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventType.ADMIN_USER_DELETE, + affectedUserId: userConatct.user.id, + actingUserId: adminConatct.user.id, + }), + ) + }) + describe('delete deleted user', () => { it('throws an error', async () => { jest.clearAllMocks() @@ -1971,6 +2049,24 @@ describe('UserResolver', () => { }), ) }) + + it('stores the ADMIN_USER_UNDELETE event in the database', async () => { + const userConatct = await UserContact.findOneOrFail( + { email: 'bibi@bloxberg.de' }, + { relations: ['user'] }, + ) + const adminConatct = await UserContact.findOneOrFail( + { email: 'peter@lustig.de' }, + { relations: ['user'] }, + ) + expect(DbEvent.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventType.ADMIN_USER_UNDELETE, + affectedUserId: userConatct.user.id, + actingUserId: adminConatct.user.id, + }), + ) + }) }) }) })