Skip to content

Commit a97f35f

Browse files
asaphkoclaude
andcommitted
test(gitlab): cover final 3 lines for 100% diff coverage
Add tests for: no-IID URL, no-project-path URL, and reverse work_items/issues URL variant lookup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5a0a60a commit a97f35f

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,39 @@ def test_tag_feature_per_gitlab_event__work_items_url_variant__finds_feature(
265265
assert gitlab_tags.first().label == GitLabTag.ISSUE_CLOSED.value # type: ignore[union-attr]
266266

267267

268+
@pytest.mark.django_db
269+
def test_tag_feature_per_gitlab_event__issues_url_stored_work_items_webhook__finds_feature(
270+
project: Project,
271+
feature: Feature,
272+
gitlab_configuration: GitLabConfiguration,
273+
) -> None:
274+
# Given — resource stored as issues URL
275+
FeatureExternalResource.objects.create(
276+
url="https://gitlab.example.com/testgroup/testrepo/-/issues/5",
277+
type=ResourceType.GITLAB_ISSUE,
278+
feature=feature,
279+
metadata='{"state": "opened"}',
280+
)
281+
# Webhook sends work_items URL
282+
payload = {
283+
"object_kind": "issue",
284+
"project": {"path_with_namespace": "testgroup/testrepo"},
285+
"object_attributes": {
286+
"action": "close",
287+
"url": "https://gitlab.example.com/testgroup/testrepo/-/work_items/5",
288+
},
289+
}
290+
291+
# When
292+
handle_gitlab_webhook_event(event_type="issue", payload=payload)
293+
294+
# Then
295+
feature.refresh_from_db()
296+
gitlab_tags = feature.tags.filter(type=TagType.GITLAB.value)
297+
assert gitlab_tags.count() == 1
298+
assert gitlab_tags.first().label == GitLabTag.ISSUE_CLOSED.value # type: ignore[union-attr]
299+
300+
268301
@pytest.mark.django_db
269302
def test_dispatch_gitlab_comment__valid_feature__dispatches_task(
270303
project: Project,

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,16 @@
3535
"https://gitlab.example.com/unknown/path/to/resource",
3636
None,
3737
),
38+
(
39+
"https://gitlab.example.com/group/project/-/issues/",
40+
None,
41+
),
42+
(
43+
"https://gitlab.example.com/-/issues/5",
44+
None,
45+
),
3846
],
39-
ids=["mr", "issue", "work-item", "nested-group", "unknown-format"],
47+
ids=["mr", "issue", "work-item", "nested-group", "unknown-format", "no-iid", "no-project-path"],
4048
)
4149
def test_parse_resource_url__various_urls__returns_correct_tuple(
4250
url: str,

0 commit comments

Comments
 (0)