@@ -13,32 +13,24 @@ import {
13
13
} from "../../../util/test" ;
14
14
import { UsersController } from "./users.controller" ;
15
15
import { POST_USER_STRUCTURE_BODY } from "../../../_common/mocks" ;
16
- import { TESTS_USERS_STRUCTURE } from "../../../_tests" ;
16
+ import { TESTS_USERS_STRUCTURE , TestUserStructure } from "../../../_tests" ;
17
17
import { usersDeletor } from "../services/users-deletor.service" ;
18
18
import { MailsModule } from "../../mails/mails.module" ;
19
19
import { AppLogsService } from "../../app-logs/app-logs.service" ;
20
- import { userStructureRepository } from "../../../database" ;
20
+ import { appLogsRepository } from "../../../database" ;
21
21
22
22
describe ( "Users Controller" , ( ) => {
23
23
let controller : UsersController ;
24
24
let context : AppTestContext ;
25
- let appLogService : AppLogsService ;
25
+ let authInfo : TestUserStructure ;
26
26
beforeAll ( async ( ) => {
27
- appLogService = {
28
- create : jest . fn ( ) ,
29
- } ;
30
27
context = await AppTestHelper . bootstrapTestApp ( {
31
28
controllers : [ UsersController ] ,
32
29
imports : [ MailsModule , StructuresModule , UsagersModule , HttpModule ] ,
33
- providers : [
34
- {
35
- provide : AppLogsService ,
36
- useValue : appLogService ,
37
- } ,
38
- ] ,
30
+ providers : [ AppLogsService ] ,
39
31
} ) ;
40
32
41
- const authInfo =
33
+ authInfo =
42
34
TESTS_USERS_STRUCTURE . BY_EMAIL [ "preprod.domifa@fabrique.social.gouv.fr" ] ;
43
35
await AppTestHelper . authenticateStructure ( authInfo , { context } ) ;
44
36
controller = context . module . get < UsersController > ( UsersController ) ;
@@ -49,6 +41,10 @@ describe("Users Controller", () => {
49
41
await AppTestHelper . tearDownTestApp ( context ) ;
50
42
} ) ;
51
43
44
+ beforeEach ( async ( ) => {
45
+ await appLogsRepository . clear ( ) ;
46
+ } ) ;
47
+
52
48
describe ( "> Register user" , ( ) => {
53
49
describe ( "Nominal case" , ( ) => {
54
50
it ( "should be defined" , async ( ) => {
@@ -65,19 +61,16 @@ describe("Users Controller", () => {
65
61
structure : { ...POST_USER_STRUCTURE_BODY . structure , id : 1 } ,
66
62
} ,
67
63
} ) ;
68
-
69
- const user = await userStructureRepository . findOneByOrFail ( {
70
- email : "test@test.com" ,
71
- } ) ;
72
- expect ( appLogService . create ) . toHaveBeenCalledWith ( {
73
- action : "USER_CREATE" ,
74
- userId : context . user . userId ,
75
- context : {
76
- role : POST_USER_STRUCTURE_BODY . role ,
77
- structureId : 1 ,
78
- userId : user . id ,
64
+ const logs = await appLogsRepository . find ( {
65
+ where : {
66
+ userId : authInfo . id ,
67
+ action : "USER_CREATE" ,
79
68
} ,
80
69
} ) ;
70
+ expect ( logs . length ) . toEqual ( 1 ) ;
71
+ expect ( logs [ 0 ] . action ) . toEqual ( "USER_CREATE" ) ;
72
+ expect ( logs [ 0 ] . role ) . toEqual ( authInfo . role ) ;
73
+ expect ( logs [ 0 ] . userId ) . toEqual ( authInfo . id ) ;
81
74
expect ( response . status ) . toBe ( 200 ) ;
82
75
expect ( response . text ) . toBe ( '{"message":"OK"}' ) ;
83
76
} ) ;
0 commit comments