-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathIssueOpSpec.scala
226 lines (195 loc) · 10.2 KB
/
IssueOpSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import org.scalatest.FunSpec
import org.scalatest.BeforeAndAfterAll
import scala.concurrent.Await
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import codecheck.github.models.IssueListOption
import codecheck.github.models.IssueFilter
import codecheck.github.models.IssueListOption4Repository
import codecheck.github.models.IssueState
import codecheck.github.models.Issue
import codecheck.github.models.IssueInput
import codecheck.github.models.MilestoneSearchOption
import codecheck.github.models.MilestoneInput
import codecheck.github.models.MilestoneListOption
import codecheck.github.models.MilestoneState
import codecheck.github.models.Milestone
class IssueOpSpec extends FunSpec with Constants with BeforeAndAfterAll {
val number = 1
var nUser: Long = 0
var nOrg: Long = 0
var nTime: DateTime = DateTime.now().toDateTime(DateTimeZone.UTC)
val tRepo = repo + "2"
override def beforeAll() {
val userMilestones = Await.result(api.listMilestones(user, userRepo, MilestoneListOption(state=MilestoneState.all)), TIMEOUT)
userMilestones.foreach { m =>
Await.result(api.removeMilestone(user, userRepo, m.number), TIMEOUT)
}
val orgMilestones = Await.result(api.listMilestones(organization, tRepo, MilestoneListOption(state=MilestoneState.all)), TIMEOUT)
orgMilestones.foreach { m =>
Await.result(api.removeMilestone(organization, tRepo, m.number), TIMEOUT)
}
val nInput = new MilestoneInput(Some("test milestone"))
val nInput2 = new MilestoneInput(Some("test milestone 2"))
Await.result(api.createMilestone(user, userRepo, nInput), TIMEOUT)
Await.result(api.createMilestone(user, userRepo, nInput2), TIMEOUT)
Await.result(api.createMilestone(organization, tRepo, nInput), TIMEOUT)
Await.result(api.createMilestone(organization, tRepo, nInput2), TIMEOUT)
}
describe("createIssue(owner, repo, input)") {
val input = IssueInput(Some("test issue"), Some("testing"), Some(user), Some(1), Seq("question"))
it("should create issue for user's own repo.") {
val result = Await.result(api.createIssue(user, userRepo, input), TIMEOUT)
nUser = result.number
assert(result.url == "https://api.github.com/repos/" + user + "/" + userRepo + "/issues/" + nUser)
assert(result.labels_url == "https://api.github.com/repos/" + user + "/" + userRepo + "/issues/" + nUser + "/labels{/name}")
assert(result.comments_url == "https://api.github.com/repos/" + user + "/" + userRepo + "/issues/" + nUser + "/comments")
assert(result.events_url == "https://api.github.com/repos/" + user + "/" + userRepo + "/issues/" + nUser + "/events")
assert(result.html_url == "https://github.com/" + user + "/" + userRepo + "/issues/" + nUser)
assert(result.title == "test issue")
assert(result.user.login == user)
assert(result.labels.head.name == "question")
assert(result.state == "open")
assert(result.locked == false)
assert(result.assignee.get.login == user)
assert(result.milestone.get.number == 1)
assert(result.comments == 0)
assert(result.created_at.toDateTime(DateTimeZone.UTC).getMillis() - DateTime.now(DateTimeZone.UTC).getMillis() <= 5000)
assert(result.updated_at.toDateTime(DateTimeZone.UTC).getMillis() - DateTime.now(DateTimeZone.UTC).getMillis() <= 5000)
assert(result.closed_at.isEmpty)
assert(result.body.get == "testing")
assert(result.closed_by.isEmpty)
}
it("should create issue for organization's repo.") {
val result = Await.result(api.createIssue(organization, tRepo, input), TIMEOUT)
nOrg = result.number
assert(result.url == "https://api.github.com/repos/" + organization + "/" + tRepo + "/issues/" + nOrg)
assert(result.labels_url == "https://api.github.com/repos/" + organization + "/" + tRepo + "/issues/" + nOrg + "/labels{/name}")
assert(result.comments_url == "https://api.github.com/repos/" + organization + "/" + tRepo+ "/issues/" + nOrg + "/comments")
assert(result.events_url == "https://api.github.com/repos/" + organization + "/" + tRepo + "/issues/" + nOrg + "/events")
assert(result.html_url == "https://github.com/" + organization + "/" + tRepo + "/issues/" + nOrg)
assert(result.title == "test issue")
assert(result.user.login == user)
assert(result.labels.head.name == "question")
assert(result.state == "open")
assert(result.locked == false)
assert(result.assignee.get.login == user)
assert(result.milestone.get.number == 1)
assert(result.comments == 0)
assert(result.created_at.toDateTime(DateTimeZone.UTC).getMillis() - DateTime.now(DateTimeZone.UTC).getMillis() <= 5000)
assert(result.updated_at.toDateTime(DateTimeZone.UTC).getMillis() - DateTime.now(DateTimeZone.UTC).getMillis() <= 5000)
assert(result.body.get == "testing")
assert(result.closed_by.isEmpty)
}
}
describe("getIssue(owner, repo, number)") {
it("should return issue from user's own repo.") {
val result = Await.result(api.getIssue(user, userRepo, nUser), TIMEOUT)
assert(result.get.title == "test issue")
}
it("should return issue from organization's repo.") {
val result = Await.result(api.getIssue(organization, tRepo, nOrg), TIMEOUT)
assert(result.get.title == "test issue")
}
}
describe("unassign(owner, repo, number)") {
it("should succeed with valid inputs on issues in user's own repo.") {
val result = Await.result(api.unassign(user, userRepo, nUser), TIMEOUT)
assert(result.opt("assignee").isEmpty)
}
it("should succeed with valid inputs on issues in organization's repo.") {
val result = Await.result(api.unassign(organization, tRepo, nOrg), TIMEOUT)
assert(result.opt("assignee").isEmpty)
}
}
describe("assign(owner, repo, number, assignee)") {
it("should succeed with valid inputs on issues in user's own repo.") {
val result = Await.result(api.assign(user, userRepo, nUser, user), TIMEOUT)
assert(result.get("assignee.login") == user)
}
it("should succeed with valid inputs on issues in organization's repo.") {
val result = Await.result(api.assign(organization, tRepo, nOrg, user), TIMEOUT)
assert(result.get("assignee.login") == user)
}
}
describe("listAllIssues(option)") {
it("shold return at least one issue.") {
val result = Await.result(api.listAllIssues(), TIMEOUT)
assert(result.length > 0)
}
it("shold return only two issues when using options.") {
val option = IssueListOption(IssueFilter.created, IssueState.open, Seq("question"), since=Some(nTime))
val result = Await.result(api.listAllIssues(option), TIMEOUT)
assert(result.length == 2)
assert(result.head.title == "test issue")
}
}
describe("listUserIssues(option)") {
it("shold return at least one issue.") {
val result = Await.result(api.listUserIssues(), TIMEOUT)
assert(result.length > 0)
}
it("shold return only one issues when using options.") {
val option = IssueListOption(IssueFilter.created, IssueState.open, Seq("question"), since=Some(nTime))
val result = Await.result(api.listUserIssues(option), TIMEOUT)
assert(result.length == 1)
assert(result.head.title == "test issue")
}
}
describe("listOrgIssues(org, option)") {
it("should return at least one issue.") {
val result = Await.result(api.listOrgIssues(organization), TIMEOUT)
assert(result.length > 0)
}
it("shold return only one issues when using options.") {
val option = IssueListOption(IssueFilter.created, IssueState.open, Seq("question"), since=Some(nTime))
val result = Await.result(api.listOrgIssues(organization, option), TIMEOUT)
assert(result.length == 1)
assert(result.head.title == "test issue")
}
}
describe("listRepositoryIssues(owner, repo, option)") {
it("should return at least one issue from user's own repo.") {
val result = Await.result(api.listRepositoryIssues(user, userRepo), TIMEOUT)
assert(result.length > 0)
}
it("should return at least one issue from organization's repo.") {
val result = Await.result(api.listRepositoryIssues(organization, tRepo), TIMEOUT)
assert(result.length > 0)
}
it("should return only one issue from user's own repo when using options.") {
val option = new IssueListOption4Repository(Some(MilestoneSearchOption(1)), IssueState.open, Some(user), Some(user), labels=Seq("question"), since=Some(nTime))
val result = Await.result(api.listRepositoryIssues(user, userRepo, option), TIMEOUT)
//showResponse(option.q)
assert(result.length == 1)
assert(result.head.title == "test issue")
}
it("should return only one issue from organization's repo when using options.") {
val option = new IssueListOption4Repository(Some(MilestoneSearchOption(1)), IssueState.open, Some(user), Some(user), labels=Seq("question"), since=Some(nTime))
val result = Await.result(api.listRepositoryIssues(organization, tRepo, option), TIMEOUT)
assert(result.length == 1)
assert(result.head.title == "test issue")
}
}
describe("editIssue(owner, repo, number, input)") {
val input = IssueInput(Some("test issue edited"), Some("testing again"), Some(user), Some(2), Seq("question", "bug"), Some(IssueState.closed))
it("should edit the issue in user's own repo.") {
val result = Await.result(api.editIssue(user, userRepo, nUser, input), TIMEOUT)
assert(result.title == "test issue edited")
assert(result.body.get == "testing again")
assert(result.milestone.get.number == 2)
assert(result.labels.head.name == "bug")
assert(result.state == "closed")
assert(result.updated_at.toDateTime(DateTimeZone.UTC).getMillis() - DateTime.now(DateTimeZone.UTC).getMillis() <= 5000)
}
it("should edit the issue in organization's repo.") {
val result = Await.result(api.editIssue(organization, tRepo, nOrg, input), TIMEOUT)
assert(result.title == "test issue edited")
assert(result.body.get == "testing again")
assert(result.milestone.get.number == 2)
assert(result.labels.head.name == "bug")
assert(result.state == "closed")
assert(result.updated_at.toDateTime(DateTimeZone.UTC).getMillis() - DateTime.now(DateTimeZone.UTC).getMillis() <= 5000)
}
}
}