@@ -3670,41 +3670,39 @@ def test_list_features__with_code_references__returns_counts(
36703670) -> None :
36713671 # Given
36723672 with_project_permissions ([VIEW_PROJECT ]) # type: ignore[call-arg]
3673- with freeze_time ("2099-01-01T10:00:00-0300" ):
3674- github_repository = VCSRepository .objects .create (
3675- project = project ,
3676- url = "https://github.flagsmith.com/backend/" ,
3677- vcs_provider = "github" ,
3678- last_scanned_at = timezone .now (),
3679- )
3680- ScannedCodeReferences .objects .create (
3681- feature = feature ,
3682- repository = github_repository ,
3683- revision = "backend-1" ,
3684- code_references = [
3685- {"file_path" : "path/to/file.py" , "line_number" : 42 },
3686- ],
3687- code_references_hash = "hash-backend-1" ,
3688- )
3689- with freeze_time ("2099-01-02T11:00:00-0300" ):
3690- github_repository .last_scanned_at = timezone .now ()
3691- github_repository .save ()
3692- gitlab_repository = VCSRepository .objects .create (
3693- project = project ,
3694- url = "https://gitlab.flagsmith.com/frontend/" ,
3695- vcs_provider = "github" ,
3696- last_scanned_at = timezone .now (),
3697- )
3698- ScannedCodeReferences .objects .create (
3699- feature = feature ,
3700- repository = gitlab_repository ,
3701- revision = "frontend-2" ,
3702- code_references = [
3703- {"file_path" : "path/to/file.js" , "line_number" : 23 },
3704- {"file_path" : "path/to/another/file.js" , "line_number" : 50 },
3705- ],
3706- code_references_hash = "hash-frontend-2" ,
3707- )
3673+ github_repository = VCSRepository .objects .create (
3674+ project = project ,
3675+ url = "https://github.flagsmith.com/backend/" ,
3676+ vcs_provider = "github" ,
3677+ last_scanned_at = "2099-01-02T14:00:00+00:00" ,
3678+ )
3679+ ScannedCodeReferences .objects .create (
3680+ feature = feature ,
3681+ repository = github_repository ,
3682+ revision = "backend-1" ,
3683+ code_references = [
3684+ {"file_path" : "path/to/file.py" , "line_number" : 42 },
3685+ ],
3686+ code_references_hash = "hash-backend-1" ,
3687+ created_at = "2099-01-01T13:00:00+00:00" ,
3688+ )
3689+ gitlab_repository = VCSRepository .objects .create (
3690+ project = project ,
3691+ url = "https://gitlab.flagsmith.com/frontend/" ,
3692+ vcs_provider = "github" ,
3693+ last_scanned_at = "2099-01-02T14:00:00+00:00" ,
3694+ )
3695+ ScannedCodeReferences .objects .create (
3696+ feature = feature ,
3697+ repository = gitlab_repository ,
3698+ revision = "frontend-2" ,
3699+ code_references = [
3700+ {"file_path" : "path/to/file.js" , "line_number" : 23 },
3701+ {"file_path" : "path/to/another/file.js" , "line_number" : 50 },
3702+ ],
3703+ code_references_hash = "hash-frontend-2" ,
3704+ created_at = "2099-01-02T14:00:00+00:00" ,
3705+ )
37083706
37093707 # When
37103708 response = staff_client .get (f"/api/v1/projects/{ project .pk } /features/" )
@@ -3727,6 +3725,42 @@ def test_list_features__with_code_references__returns_counts(
37273725 ]
37283726
37293727
3728+ def test_list_features__scan_recorded_via_api__count_reflects_references (
3729+ feature : Feature ,
3730+ project : Project ,
3731+ admin_client_new : APIClient ,
3732+ staff_client : APIClient ,
3733+ with_project_permissions : WithProjectPermissionsCallable ,
3734+ ) -> None :
3735+ # Given
3736+ with_project_permissions ([VIEW_PROJECT ]) # type: ignore[call-arg]
3737+ admin_client_new .post (
3738+ f"/api/v1/projects/{ project .pk } /code-references/" ,
3739+ data = {
3740+ "repository_url" : "https://github.flagsmith.com/backend/" ,
3741+ "revision" : "rev-1" ,
3742+ "code_references" : [
3743+ {
3744+ "feature_name" : feature .name ,
3745+ "file_path" : "path/to/file.py" ,
3746+ "line_number" : 42 ,
3747+ },
3748+ ],
3749+ },
3750+ format = "json" ,
3751+ )
3752+
3753+ # When
3754+ response = staff_client .get (f"/api/v1/projects/{ project .pk } /features/" )
3755+
3756+ # Then
3757+ assert response .status_code == status .HTTP_200_OK
3758+ counts = response .json ()["results" ][0 ]["code_references_counts" ]
3759+ assert len (counts ) == 1
3760+ assert counts [0 ]["repository_url" ] == "https://github.flagsmith.com/backend/"
3761+ assert counts [0 ]["count" ] == 1
3762+
3763+
37303764@pytest .mark .usefixtures ("feature" )
37313765def test_list_features__without_code_references__returns_empty_counts (
37323766 environment : Environment ,
0 commit comments