@@ -687,3 +687,43 @@ def test_build_response_include_values_that_are_not_null(client: FlaskClient):
687687 assert action ["description" ] == "Contact GP"
688688 assert action ["urlLink" ] == "https://example.dummy/"
689689 assert action ["urlLabel" ] == "GP contact"
690+
691+
692+ @pytest .mark .parametrize (
693+ ("headers" , "expected_request_id" ),
694+ [
695+ ({"X-Request-ID" : "test-request-id-123" }, "test-request-id-123" ),
696+ (
697+ {"X-Request-ID" : "" },
698+ "" ,
699+ ),
700+ (
701+ {}, # No headers provided
702+ None ,
703+ ),
704+ ],
705+ )
706+ def test_request_id_from_header_logging_variants (
707+ app : Flask , client : FlaskClient , caplog , headers : dict [str , str ], expected_request_id : str
708+ ):
709+ """
710+ This test checks that the x-request-ID is logged so that it can be used to correlate logs
711+ with that of the logs from api-gateway
712+ """
713+ with (
714+ get_app_container (app ).override .service (EligibilityService , new = FakeEligibilityService ()),
715+ get_app_container (app ).override .service (AuditService , new = FakeAuditService ()),
716+ ):
717+ with caplog .at_level (logging .INFO ):
718+ response = client .get ("/patient-check/12345" , headers = headers )
719+
720+ request_id_logged = False
721+ for record in caplog .records :
722+ request_id = getattr (record , "X-Request-ID" , None )
723+
724+ if request_id == expected_request_id :
725+ request_id_logged = True
726+ break
727+
728+ assert request_id_logged
729+ assert response .status_code == HTTPStatus .OK
0 commit comments