|
| 1 | + |
1 | 2 | import org.scalatest.FunSpec
|
2 | 3 | import scala.concurrent.Await
|
| 4 | +import org.joda.time.DateTime |
| 5 | +import org.joda.time.DateTimeZone |
| 6 | + |
| 7 | +import codecheck.github.models.IssueListOption |
| 8 | +import codecheck.github.models.IssueFilter |
| 9 | +import codecheck.github.models.IssueListOption4Repository |
| 10 | +import codecheck.github.models.IssueState |
| 11 | +import codecheck.github.models.Issue |
| 12 | +import codecheck.github.models.IssueInput |
3 | 13 |
|
4 | 14 | class IssueOpSpec extends FunSpec with Constants {
|
5 | 15 |
|
6 | 16 | val number = 1
|
| 17 | + var nUser: Long = 0 |
| 18 | + var nOrg: Long = 0 |
| 19 | + var createdUser: DateTime = DateTime.now |
| 20 | + var createdOrg: DateTime = DateTime.now |
7 | 21 |
|
8 |
| - describe("assign operations") { |
9 |
| - it("assign should succeed") { |
10 |
| - val result = Await.result(api.assign(organization, repo, number, user), TIMEOUT) |
11 |
| - showResponse(result) |
12 |
| - assert(result.get("assignee.login") == user) |
| 22 | + describe("createIssue(owner, repo, input)") { |
| 23 | + val input = IssueInput(Some("test issue"), Some("testing"), Some(user), Some(1), Seq("question")) |
| 24 | + |
| 25 | + it("should create issue for user's own repo.") { |
| 26 | + val result = Await.result(api.createIssue(user, userRepo, input), TIMEOUT) |
| 27 | + //showResponse(result) |
| 28 | + nUser = result.number |
| 29 | + assert(result.url == "https://api.github.com/repos/" + user + "/" + userRepo + "/issues/" + nUser) |
| 30 | + assert(result.labels_url == "https://api.github.com/repos/" + user + "/" + userRepo + "/issues/" + nUser + "/labels{/name}") |
| 31 | + assert(result.comments_url == "https://api.github.com/repos/" + user + "/" + userRepo + "/issues/" + nUser + "/comments") |
| 32 | + assert(result.events_url == "https://api.github.com/repos/" + user + "/" + userRepo + "/issues/" + nUser + "/events") |
| 33 | + assert(result.html_url == "https://github.com/" + user + "/" + userRepo + "/issues/" + nUser) |
| 34 | + assert(result.title == "test issue") |
| 35 | + assert(result.user.login == user) |
| 36 | + assert(result.labels.head.name == "question") |
| 37 | + assert(result.state == "open") |
| 38 | + assert(result.locked == false) |
| 39 | + assert(result.assignee.get.login == user) |
| 40 | + assert(result.milestone.get.number == 1) |
| 41 | + assert(result.comments == 0) |
| 42 | + assert(result.created_at.toDateTime(DateTimeZone.UTC).getMillis() - DateTime.now(DateTimeZone.UTC).getMillis() <= 5000) |
| 43 | + assert(result.updated_at.toDateTime(DateTimeZone.UTC).getMillis() - DateTime.now(DateTimeZone.UTC).getMillis() <= 5000) |
| 44 | + createdUser = result.created_at |
| 45 | + assert(result.closed_at.isEmpty) |
| 46 | + assert(result.body.get == "testing") |
| 47 | + assert(result.closed_by.isEmpty) |
| 48 | + } |
| 49 | + |
| 50 | + it("should create issue for organization's repo.") { |
| 51 | + val result = Await.result(api.createIssue(organization, repo, input), TIMEOUT) |
| 52 | + nOrg = result.number |
| 53 | + assert(result.url == "https://api.github.com/repos/" + organization + "/" + repo + "/issues/" + nOrg) |
| 54 | + assert(result.labels_url == "https://api.github.com/repos/" + organization + "/" + repo + "/issues/" + nOrg + "/labels{/name}") |
| 55 | + assert(result.comments_url == "https://api.github.com/repos/" + organization + "/" + repo + "/issues/" + nOrg + "/comments") |
| 56 | + assert(result.events_url == "https://api.github.com/repos/" + organization + "/" + repo + "/issues/" + nOrg + "/events") |
| 57 | + assert(result.html_url == "https://github.com/" + organization + "/" + repo + "/issues/" + nOrg) |
| 58 | + assert(result.title == "test issue") |
| 59 | + assert(result.user.login == user) |
| 60 | + assert(result.labels.head.name == "question") |
| 61 | + assert(result.state == "open") |
| 62 | + assert(result.locked == false) |
| 63 | + assert(result.assignee.get.login == user) |
| 64 | + assert(result.milestone.get.number == 1) |
| 65 | + assert(result.comments == 0) |
| 66 | + assert(result.created_at.toDateTime(DateTimeZone.UTC).getMillis() - DateTime.now(DateTimeZone.UTC).getMillis() <= 5000) |
| 67 | + assert(result.updated_at.toDateTime(DateTimeZone.UTC).getMillis() - DateTime.now(DateTimeZone.UTC).getMillis() <= 5000) |
| 68 | + createdOrg = result.created_at |
| 69 | + assert(result.closed_at.isEmpty) |
| 70 | + assert(result.body.get == "testing") |
| 71 | + assert(result.closed_by.isEmpty) |
13 | 72 | }
|
| 73 | + } |
| 74 | + |
| 75 | + describe("getIssue(owner, repo, number)") { |
| 76 | + it("should return issue from user's own repo.") { |
| 77 | + val result = Await.result(api.getIssue(user, userRepo, nUser), TIMEOUT) |
| 78 | + assert(result.get.title == "test issue") |
| 79 | + } |
| 80 | + |
| 81 | + it("should return issue from organization's repo.") { |
| 82 | + val result = Await.result(api.getIssue(organization, repo, nOrg), TIMEOUT) |
| 83 | + assert(result.get.title == "test issue") |
| 84 | + } |
| 85 | + } |
14 | 86 |
|
15 |
| - it("unassign should succeed") { |
16 |
| - val result = Await.result(api.unassign(organization, repo, number), TIMEOUT) |
| 87 | + describe("unassign(owner, repo, number)") { |
| 88 | + it("should succeed with valid inputs on issues in user's own repo.") { |
| 89 | + val result = Await.result(api.unassign(user, userRepo, nUser), TIMEOUT) |
17 | 90 | assert(result.opt("assignee").isEmpty)
|
18 | 91 | }
|
| 92 | + |
| 93 | + it("should succeed with valid inputs on issues in organization's repo.") { |
| 94 | + val result = Await.result(api.unassign(organization, repo, nOrg), TIMEOUT) |
| 95 | + assert(result.opt("assignee").isEmpty) |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + describe("assign(owner, repo, number, assignee)") { |
| 100 | + it("should succeed with valid inputs on issues in user's own repo.") { |
| 101 | + val result = Await.result(api.assign(user, userRepo, nUser, user), TIMEOUT) |
| 102 | + assert(result.get("assignee.login") == user) |
| 103 | + } |
| 104 | + |
| 105 | + it("should succeed with valid inputs on issues in organization's repo.") { |
| 106 | + val result = Await.result(api.assign(organization, repo, nOrg, user), TIMEOUT) |
| 107 | + assert(result.get("assignee.login") == user) |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + describe("listAllIssues(option)") { |
| 112 | + it("shold return at least one issue.") { |
| 113 | + val result = Await.result(api.listAllIssues(), TIMEOUT) |
| 114 | + assert(result.length > 0) |
| 115 | + } |
| 116 | + |
| 117 | + it("shold return only one issue.") { |
| 118 | + val option = IssueListOption(IssueFilter.all, IssueState.open, since=Some(createdUser)) |
| 119 | + val result = Await.result(api.listAllIssues(option), TIMEOUT) |
| 120 | + assert(result.length == 1) |
| 121 | + assert(result.head.title == "test issue") |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + describe("listUserIssues(option)") { |
| 126 | + it("shold return at least one issue.") { |
| 127 | + val result = Await.result(api.listUserIssues(), TIMEOUT) |
| 128 | + assert(result.length > 0) |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + describe("listOrgIssues(org, option)") { |
| 133 | + it("should return at least one issue.") { |
| 134 | + val result = Await.result(api.listOrgIssues(organization), TIMEOUT) |
| 135 | + assert(result.length > 0) |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + describe("listRepositoryIssues(owner, repo, option)") { |
| 140 | + it("should return at least one issue.") { |
| 141 | + val result = Await.result(api.listRepositoryIssues(organization, repo), TIMEOUT) |
| 142 | + assert(result.length > 0) |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + describe("listRepositoryIssues") { |
| 147 | + it("is just testing.") { |
| 148 | + val input = new IssueListOption4Repository(state=IssueState.all) |
| 149 | + val result = Await.result(api.listRepositoryIssues(organization, repo, input), TIMEOUT) |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + describe("editIssue(owner, repo, number, input)") { |
| 154 | + val input = IssueInput(Some("test issue edited"), Some("testing again"), Some(user), Some(2), Seq("question", "bug"), Some(IssueState.closed)) |
| 155 | + |
| 156 | + it("should edit the issue in user's own repo.") { |
| 157 | + val result = Await.result(api.editIssue(user, userRepo, nUser, input), TIMEOUT) |
| 158 | + assert(result.title == "test issue edited") |
| 159 | + assert(result.body.get == "testing again") |
| 160 | + assert(result.milestone.get.number == 2) |
| 161 | + assert(result.labels.head.name == "bug") |
| 162 | + assert(result.state == "closed") |
| 163 | + assert(result.updated_at.toDateTime(DateTimeZone.UTC).getMillis() - DateTime.now(DateTimeZone.UTC).getMillis() <= 5000) |
| 164 | + } |
| 165 | + |
| 166 | + it("should edit the issue in organization's repo.") { |
| 167 | + val result = Await.result(api.editIssue(organization, repo, nOrg, input), TIMEOUT) |
| 168 | + assert(result.title == "test issue edited") |
| 169 | + assert(result.body.get == "testing again") |
| 170 | + assert(result.milestone.get.number == 2) |
| 171 | + assert(result.labels.head.name == "bug") |
| 172 | + assert(result.state == "closed") |
| 173 | + assert(result.updated_at.toDateTime(DateTimeZone.UTC).getMillis() - DateTime.now(DateTimeZone.UTC).getMillis() <= 5000) |
| 174 | + } |
19 | 175 | }
|
20 | 176 | }
|
0 commit comments