Skip to content

Commit 5a0a60a

Browse files
asaphkoclaude
andcommitted
test(gitlab): cover remaining service edge cases for coverage
Add tests for: no linked feature, no config for project path, and null tag for MR update without draft. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 84dbc70 commit 5a0a60a

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

api/tests/unit/integrations/gitlab/test_unit_gitlab_services.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,91 @@ def test_dispatch_gitlab_comment__with_feature_states__maps_and_dispatches(
346346
assert len(call_kwargs["feature_states"]) == 1
347347
assert call_kwargs["segment_name"] == "beta_users"
348348
assert call_kwargs["feature_states"][0]["environment_name"] == environment.name
349+
350+
351+
@pytest.mark.django_db
352+
def test_tag_feature_per_gitlab_event__no_linked_feature__returns_early(
353+
project: Project,
354+
gitlab_configuration: GitLabConfiguration,
355+
) -> None:
356+
# Given — no FeatureExternalResource exists
357+
payload = {
358+
"object_kind": "merge_request",
359+
"project": {"path_with_namespace": "testgroup/testrepo"},
360+
"object_attributes": {
361+
"action": "merge",
362+
"url": "https://gitlab.example.com/testgroup/testrepo/-/merge_requests/99",
363+
"state": "merged",
364+
"work_in_progress": False,
365+
},
366+
}
367+
368+
# When
369+
handle_gitlab_webhook_event(event_type="merge_request", payload=payload)
370+
371+
# Then
372+
assert True # no error, returns early
373+
374+
375+
@pytest.mark.django_db
376+
def test_tag_feature_per_gitlab_event__no_config_for_path__returns_early(
377+
project: Project,
378+
feature: Feature,
379+
gitlab_configuration: GitLabConfiguration,
380+
) -> None:
381+
# Given — resource exists but config project_name doesn't match
382+
FeatureExternalResource.objects.create(
383+
url="https://gitlab.example.com/other/repo/-/merge_requests/1",
384+
type=ResourceType.GITLAB_MR,
385+
feature=feature,
386+
metadata='{"state": "opened"}',
387+
)
388+
payload = {
389+
"object_kind": "merge_request",
390+
"project": {"path_with_namespace": "other/repo"},
391+
"object_attributes": {
392+
"action": "merge",
393+
"url": "https://gitlab.example.com/other/repo/-/merge_requests/1",
394+
"state": "merged",
395+
"work_in_progress": False,
396+
},
397+
}
398+
399+
# When
400+
handle_gitlab_webhook_event(event_type="merge_request", payload=payload)
401+
402+
# Then
403+
feature.refresh_from_db()
404+
assert feature.tags.filter(type=TagType.GITLAB.value).count() == 0
405+
406+
407+
@pytest.mark.django_db
408+
def test_tag_feature_per_gitlab_event__null_tag_for_update__does_not_tag(
409+
project: Project,
410+
feature: Feature,
411+
gitlab_configuration: GitLabConfiguration,
412+
) -> None:
413+
# Given — MR update without draft returns None tag
414+
FeatureExternalResource.objects.create(
415+
url="https://gitlab.example.com/testgroup/testrepo/-/merge_requests/1",
416+
type=ResourceType.GITLAB_MR,
417+
feature=feature,
418+
metadata='{"state": "opened"}',
419+
)
420+
payload = {
421+
"object_kind": "merge_request",
422+
"project": {"path_with_namespace": "testgroup/testrepo"},
423+
"object_attributes": {
424+
"action": "update",
425+
"url": "https://gitlab.example.com/testgroup/testrepo/-/merge_requests/1",
426+
"state": "opened",
427+
"work_in_progress": False,
428+
},
429+
}
430+
431+
# When
432+
handle_gitlab_webhook_event(event_type="merge_request", payload=payload)
433+
434+
# Then
435+
feature.refresh_from_db()
436+
assert feature.tags.filter(type=TagType.GITLAB.value).count() == 0

0 commit comments

Comments
 (0)