@@ -687,3 +687,35 @@ 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_log_msg" ),
694+ [
695+ (
696+ {"X-Request-ID" : "test-request-id-123" , "X-Correlation-ID" : "test-correlation-id-456" },
697+ "X-Request-ID: test-request-id-123, X-Correlation-ID: test-correlation-id-456" ,
698+ ),
699+ (
700+ {"X-Request-ID" : "" , "X-Correlation-ID" : "" },
701+ "X-Request-ID: , X-Correlation-ID: " ,
702+ ),
703+ (
704+ {}, # No headers provided
705+ "X-Request-ID: None, X-Correlation-ID: None" ,
706+ ),
707+ ],
708+ )
709+ def test_request_id_and_correlation_id_logging_variants (
710+ app : Flask , client : FlaskClient , caplog , headers , expected_log_msg
711+ ):
712+ with (
713+ get_app_container (app ).override .service (EligibilityService , new = FakeEligibilityService ()),
714+ get_app_container (app ).override .service (AuditService , new = FakeAuditService ()),
715+ ):
716+ with caplog .at_level (logging .INFO ):
717+ response = client .get ("/patient-check/12345" , headers = headers )
718+
719+ log_messages = [record .getMessage () for record in caplog .records ]
720+ assert any (expected_log_msg in message for message in log_messages )
721+ assert response .status_code == HTTPStatus .OK
0 commit comments