@@ -35,11 +35,13 @@ function (Request $request) use (&$captured): Response {
3535
3636 expect ($ context )
3737 ->toBeArray ()
38- ->toHaveKeys (['userId ' , 'ip ' , 'traceId ' ]);
38+ ->toHaveKeys (['ip ' , 'traceId ' , 'parentTraceId ' ])
39+ ->not
40+ ->toHaveKey ('userId ' );
3941
40- expect ($ context ['userId ' ])->toBeEmpty ();
4142 expect ($ context ['ip ' ])->toBe ('198.51.100.42 ' );
42- expect ($ context ['traceId ' ])->toBe ($ trace );
43+ expect ($ context ['traceId ' ])->toBeUuid ()->toBe ($ trace );
44+ expect ($ context ['parentTraceId ' ])->toBeUuid ();
4345});
4446
4547it ('uses authenticated user id when available ' , function () {
@@ -76,8 +78,8 @@ function (Request $request) use (&$captured): Response {
7678 $ middleware = new RequestTrackerMiddleware ;
7779
7880 $ existing = [
79- 'X-Tracker-User-Id ' => '777 ' ,
80- 'X-Tracker-Ip ' => '192.0.2.55 ' ,
81+ 'X-Tracker-User-Id ' => '777 ' ,
82+ 'X-Tracker-Ip ' => '192.0.2.55 ' ,
8183 'X-Tracker-Trace-Id ' => (string ) Str::uuid (),
8284 ];
8385
@@ -101,4 +103,5 @@ function (Request $request) use (&$captured): Response {
101103 expect ($ context ['userId ' ])->toBe ('777 ' );
102104 expect ($ context ['ip ' ])->toBe ('192.0.2.55 ' );
103105 expect ($ context ['traceId ' ])->toBe ($ existing ['X-Tracker-Trace-Id ' ]);
106+ expect ($ context ['parentTraceId ' ])->toBeUuid ();
104107});
0 commit comments