diff --git a/tests/test_pr_review_merge_scheduler.py b/tests/test_pr_review_merge_scheduler.py index d72be85..a9564ed 100644 --- a/tests/test_pr_review_merge_scheduler.py +++ b/tests/test_pr_review_merge_scheduler.py @@ -52,3 +52,87 @@ def test_error_path(capsys, monkeypatch): captured = capsys.readouterr() assert "Command failed" in captured.err assert "fake error message" in captured.err + + +def test_has_current_head_approval_true_from_review_state(): + pr = { + "headRefOid": "commit123", + "reviewDecision": "REVIEW_REQUIRED", + "reviews": { + "nodes": [ + { + "state": "APPROVED", + "author": {"login": "opencode-agent"}, + "commit": {"oid": "commit123"}, + } + ] + } + } + assert pr_review_merge_scheduler.has_current_head_approval(pr) is True + + +def test_has_current_head_approval_true_from_review_decision(): + pr = { + "headRefOid": "commit123", + "reviewDecision": "APPROVED", + "reviews": { + "nodes": [] + } + } + assert pr_review_merge_scheduler.has_current_head_approval(pr) is True + + +def test_has_current_head_approval_false(): + pr = { + "headRefOid": "commit123", + "reviewDecision": "REVIEW_REQUIRED", + "reviews": { + "nodes": [ + { + "state": "CHANGES_REQUESTED", + "author": {"login": "opencode-agent"}, + "commit": {"oid": "commit123"}, + } + ] + } + } + assert pr_review_merge_scheduler.has_current_head_approval(pr) is False + + +def test_has_current_head_approval_wrong_commit(): + pr = { + "headRefOid": "commit123", + "reviewDecision": "REVIEW_REQUIRED", + "reviews": { + "nodes": [ + { + "state": "APPROVED", + "author": {"login": "opencode-agent"}, + "commit": {"oid": "oldcommit456"}, + } + ] + } + } + assert pr_review_merge_scheduler.has_current_head_approval(pr) is False + + +def test_has_current_head_approval_wrong_author(): + pr = { + "headRefOid": "commit123", + "reviewDecision": "REVIEW_REQUIRED", + "reviews": { + "nodes": [ + { + "state": "APPROVED", + "author": {"login": "some-other-user"}, + "commit": {"oid": "commit123"}, + } + ] + } + } + assert pr_review_merge_scheduler.has_current_head_approval(pr) is False + + +def test_has_current_head_approval_missing_keys(): + pr = {} + assert pr_review_merge_scheduler.has_current_head_approval(pr) is False