@@ -76,6 +76,60 @@ def test_create_code_reference__valid_payload__returns_201_with_accepted_referen
7676 ]
7777
7878
79+ def test_create_code_reference__empty_references__returns_201_and_clears_previous_references (
80+ admin_client_new : APIClient ,
81+ feature : Feature ,
82+ project : Project ,
83+ log : StructuredLogCapture ,
84+ ) -> None :
85+ # Given
86+ with freezegun .freeze_time ("2099-06-01T12:00:00+00:00" ):
87+ admin_client_new .post (
88+ f"/api/v1/projects/{ project .pk } /code-references/" ,
89+ data = {
90+ "repository_url" : "https://github.flagsmith.com/" ,
91+ "revision" : "rev-1" ,
92+ "code_references" : [
93+ {
94+ "feature_name" : feature .name ,
95+ "file_path" : "path/to/file.py" ,
96+ "line_number" : 1 ,
97+ },
98+ ],
99+ },
100+ format = "json" ,
101+ )
102+ assert ScannedCodeReferences .objects .filter (feature = feature ).exists ()
103+
104+ # When
105+ with freezegun .freeze_time ("2099-06-02T12:00:00+00:00" ):
106+ response = admin_client_new .post (
107+ f"/api/v1/projects/{ project .pk } /code-references/" ,
108+ data = {
109+ "repository_url" : "https://github.flagsmith.com/" ,
110+ "revision" : "rev-2" ,
111+ "code_references" : [],
112+ },
113+ format = "json" ,
114+ )
115+
116+ # Then
117+ assert response .status_code == 201
118+ assert response .data ["code_references" ] == []
119+ references_response = admin_client_new .get (
120+ f"/api/v1/projects/{ project .pk } /features/{ feature .pk } /code-references/" ,
121+ )
122+ assert references_response .status_code == 200
123+ assert references_response .json () == []
124+ assert log .events [- 1 ] == {
125+ "event" : "scan.created" ,
126+ "level" : "info" ,
127+ "organisation__id" : project .organisation_id ,
128+ "code_references__count" : 0 ,
129+ "feature__count" : 0 ,
130+ }
131+
132+
79133def test_create_code_reference__not_authenticated__returns_401 (
80134 client : APIClient ,
81135 project : Project ,
0 commit comments