Merge: Safe call operator
[nit.git] / lib / github / tests / test_api.nit
index 235a170..19538e4 100644 (file)
@@ -71,10 +71,13 @@ class MockGithubAPI
                map["/repos/nitlang/nit/issues/events/199674194"] = "repo_issues_events_199674194"
                map["/repos/nitlang/nit/pulls?page=1&per_page=3"] = "repo_pulls_nit"
                map["/repos/nitlang/nit/pulls/1000"] = "repo_pulls_1000"
+               map["/repos/nitlang/nit/pulls/945/comments?page=1&per_page=3"] = "repo_pulls_945_comments"
+               map["/repos/nitlang/nit/pulls/comments/21010363"] = "repo_pulls_comment_21010363"
                map["/repos/nitlang/nit/commits/64ce1f"] = "repo_commits_64ce1f"
+               map["/repos/nitlang/nit/commits/4e3c688d/status"] = "repo_commits_4e3c68_status"
                map["/repos/nitlang/nit/comments/8982707"] = "repo_comments_8982707"
-               map["/repos/nitlang/nit/pulls/comments/21010363"] = "repo_pulls_comment_21010363"
                map["/search/issues?q=foo repo:nitlang/nit&page=1&per_page=3"] = "repo_search_issues_nit"
+               map["/repos/nitlang/nit/stats/contributors"] = "repo_nit_contributors"
                # errors
                map["/users/not_found/not_found"] = "errors_404"
                return map
@@ -219,24 +222,22 @@ class TestGithubAPI
                assert repo.default_branch == "master"
        end
 
-       private var repo: Repo is lazy do return api.get_repo("nitlang/nit").as(not null)
-
        fun test_get_branches is test do
-               var branches = api.get_repo_branches(repo, 1, 2)
+               var branches = api.get_repo_branches("nitlang/nit", 1, 2)
                assert branches.length == 2
                assert branches.first.name == "master"
                assert branches.last.name == "next"
        end
 
        fun test_get_issues is test do
-               var issues = api.get_repo_issues(repo, 1, 3)
+               var issues = api.get_repo_issues("nitlang/nit", 1, 3)
                assert issues.length == 3
                assert issues.first.title == "nitrpg: Move `nitrpg` to its own repository"
                assert issues.last.title == "Mock Github API tests"
        end
 
        fun test_search_issues is test do
-               var results = api.search_repo_issues(repo, "foo", 1, 3)
+               var results = api.search_repo_issues("nitlang/nit", "foo", 1, 3)
                assert results isa SearchResults
                assert results.items.length == 3
                assert results.items.first.as(Issue).title == "Introduction of contracts in Nit"
@@ -244,43 +245,58 @@ class TestGithubAPI
        end
 
        fun test_get_labels is test do
-               var labels = api.get_repo_labels(repo, 1, 3)
+               var labels = api.get_repo_labels("nitlang/nit", 1, 3)
                assert labels.length == 3
                assert labels.first.name == "API"
                assert labels.last.name == "NEP"
        end
 
        fun test_get_milestones is test do
-               var milestones = api.get_repo_milestones(repo, 1, 3)
+               var milestones = api.get_repo_milestones("nitlang/nit", 1, 3)
                assert milestones.length == 3
                assert milestones.first.title == "v1.0prealpha"
                assert milestones.last.title == "nitdoc - Abstraction levels"
        end
 
        fun test_get_pulls is test do
-               var pulls = api.get_repo_pulls(repo, 1, 3)
+               var pulls = api.get_repo_pulls("nitlang/nit", 1, 3)
                assert pulls.length == 3
                assert pulls.first.title == "nitrpg: Move `nitrpg` to its own repository"
                assert pulls.last.title == "Mock Github API tests"
        end
 
-       # TODO contrib_stats
-
        fun test_get_branch is test do
-               var branch = api.get_branch(repo, "master")
+               var branch = api.get_branch("nitlang/nit", "master")
                assert branch isa Branch
                assert branch.name == "master"
        end
 
        fun test_get_commit is test do
-               var commit = api.get_commit(repo, "64ce1f")
+               var commit = api.get_commit("nitlang/nit", "64ce1f")
                assert commit isa Commit
                assert commit.sha == "64ce1f587209024f5de46d06c70526a569ff537f"
                # TODO other fields
        end
 
+       fun test_get_commit_status is test do
+               var status = api.get_commit_status("nitlang/nit", "4e3c688d")
+               assert status isa CommitStatus
+               assert status.state == "failure"
+               assert status.sha == "4e3c688d2c4b875c00f206eb4c4b6f2c4f34c096"
+               assert status.total_count == 1
+
+               var sub = status.statuses.first
+               assert sub.state == "failure"
+               assert sub.description == "Merged pipeline on gitlab: failed"
+               assert sub.context == "gitlab-ci"
+
+               var repo = status.repository
+               assert repo isa Repo
+               assert repo.full_name == "nitlang/nit"
+       end
+
        fun test_get_issue is test do
-               var issue = api.get_issue(repo, 1000)
+               var issue = api.get_issue("nitlang/nit", 1000)
                assert issue isa Issue
                assert issue.number == 1000
                assert issue.title == "Raise nitc from the dead"
@@ -294,26 +310,22 @@ class TestGithubAPI
        end
 
        fun test_get_issue_comments is test do
-               var issue = api.get_issue(repo, 1000)
-               assert issue isa Issue
-               var comments = api.get_issue_comments(repo, issue, 1, 3)
+               var comments = api.get_issue_comments("nitlang/nit", 1000, 1, 3)
                assert comments.length == 3
                assert comments.first.user.login == "R4PaSs"
                assert comments.last.user.login == "xymus"
        end
 
        fun test_get_issue_events is test do
-               var issue = api.get_issue(repo, 1000)
-               assert issue isa Issue
-               var events = api.get_issue_events(repo, issue, 1, 3)
+               var events = api.get_issue_events("nitlang/nit", 1000, 1, 3)
                assert events.length == 3
                assert events.first.actor.login == "privat"
                assert events.last.actor.login == "xymus"
        end
 
        fun test_get_pull is test do
-               var pull = api.get_pull(repo, 1000)
-               assert pull isa Issue
+               var pull = api.get_pull("nitlang/nit", 1000)
+               assert pull isa PullRequest
                assert pull.number == 1000
                assert pull.title == "Raise nitc from the dead"
                assert pull.user.as(User).login == "privat"
@@ -324,21 +336,36 @@ class TestGithubAPI
                assert pull.body == "Raise dead on `nitc`.\nIt's super effective...\n"
        end
 
+       fun test_get_pull_comments is test do
+               var comments = api.get_pull_comments("nitlang/nit", 945, 1, 3)
+               assert comments.length == 2
+               assert comments.first.path == "src/modelize/modelize_property.nit"
+       end
+
+       fun test_get_pull_comment is test do
+               var comment = api.get_pull_comment("nitlang/nit", 21010363)
+               assert comment isa PullComment
+               assert comment.path == "src/modelize/modelize_property.nit"
+               assert comment.original_position == 26
+               assert comment.pull_number == 945
+               # TODO other fields
+       end
+
        fun test_get_label is test do
-               var labl = api.get_label(repo, "ok_will_merge")
+               var labl = api.get_label("nitlang/nit", "ok_will_merge")
                assert labl isa Label
                assert labl.name == "ok_will_merge"
        end
 
        fun test_get_milestone is test do
-               var milestone = api.get_milestone(repo, 4)
+               var milestone = api.get_milestone("nitlang/nit", 4)
                assert milestone isa Milestone
                assert milestone.title == "v1.0prealpha"
                # TODO other fields
        end
 
        fun test_get_issue_event is test do
-               var event = api.get_issue_event(repo, 199674194)
+               var event = api.get_issue_event("nitlang/nit", 199674194)
                assert event isa IssueEvent
                assert event.actor.login == "privat"
                assert event.event == "labeled"
@@ -346,7 +373,7 @@ class TestGithubAPI
        end
 
        fun test_get_issue_comment is test do
-               var comment = api.get_issue_comment(repo, 6020149)
+               var comment = api.get_issue_comment("nitlang/nit", 6020149)
                assert comment isa IssueComment
                assert comment.user.login == "privat"
                assert comment.created_at.to_s == "2012-05-30T20:16:54Z"
@@ -354,18 +381,17 @@ class TestGithubAPI
        end
 
        fun test_get_comment is test do
-               var comment = api.get_commit_comment(repo, 8982707)
+               var comment = api.get_commit_comment("nitlang/nit", 8982707)
                assert comment isa CommitComment
                assert comment.user.login == "Morriar"
                assert comment.body == "For testing purposes...\n"
                assert comment.commit_id == "7eacb86d1e24b7e72bc9ac869bf7182c0300ceca"
        end
 
-       fun test_get_review_comments is test do
-               var comment = api.get_review_comment(repo, 21010363)
-               assert comment isa ReviewComment
-               assert comment.path == "src/modelize/modelize_property.nit"
-               assert comment.original_position == 26
-               assert comment.pull_number == 945
+       fun test_contributor_stats is test do
+               var stats = api.get_repo_contrib_stats("nitlang/nit")
+               assert stats.last.author.login == "privat"
+               assert stats.last.total == 4536
+               assert stats.last.weeks.length == 575
        end
 end