@@ -16,7 +16,13 @@ describe('index.test.ts', () => {
16
16
sendAuditMessage : sendAuditMessageMock ,
17
17
} ) )
18
18
19
+ jest . mock ( 'uuid' , ( ) => ( {
20
+ v1 : jest . fn ( ( ) => 'mocked-uuid' ) ,
21
+ } ) )
22
+
19
23
beforeEach ( ( ) => {
24
+ jest . clearAllMocks ( )
25
+ jest . resetAllMocks ( )
20
26
app = appWithAllRoutes ( { } )
21
27
jest . spyOn ( auditService , 'sendAuditMessage' ) . mockResolvedValue ( { } as never )
22
28
} )
@@ -34,14 +40,6 @@ describe('index.test.ts', () => {
34
40
} )
35
41
36
42
it ( 'GET /triggered-event' , ( ) => {
37
- const mockPublishedEvent = {
38
- action : 'TEST_EVENT' ,
39
- who : 'user1' ,
40
- subjectId : 'some user ID' ,
41
- subjectType : 'USER_ID' ,
42
- details : JSON . stringify ( { testField : 'some value' } ) ,
43
- }
44
-
45
43
return request ( app )
46
44
. get ( '/triggered-event' )
47
45
. expect ( 'Content-Type' , / h t m l / )
@@ -60,12 +58,22 @@ describe('index.test.ts', () => {
60
58
'<b>Subject Type:</b> The type of subject ID we are using. This is most commonly a user ID.' ,
61
59
)
62
60
expect ( res . text ) . toContain ( '<b>Service:</b> Which service performed this action?' )
61
+ expect ( res . text ) . toContain ( '<b>Correlation ID:</b> An optional ID used to link multiple correlated events.' )
63
62
expect ( res . text ) . toContain (
64
63
'<b>Details:</b> Any additional details specific to this action that may be relevant can go here.' ,
65
64
)
66
65
} )
67
66
. expect ( ( ) => {
68
- expect ( auditService . sendAuditMessage ) . toBeCalledWith ( mockPublishedEvent )
67
+ expect ( auditService . sendAuditMessage ) . toBeCalledWith (
68
+ expect . objectContaining ( {
69
+ action : 'TEST_EVENT' ,
70
+ who : 'user1' ,
71
+ subjectId : 'some user ID' ,
72
+ subjectType : 'USER_ID' ,
73
+ correlationId : expect . stringMatching ( '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' ) ,
74
+ details : JSON . stringify ( { testField : 'some value' } ) ,
75
+ } ) ,
76
+ )
69
77
} )
70
78
} )
71
79
} )
0 commit comments