-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMilestoneOpSpec.scala
195 lines (179 loc) · 6.53 KB
/
MilestoneOpSpec.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
package codecheck.github
package operations
import exceptions._
import models._
import org.scalatest.path.FunSpec
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.Implicits.global
import org.joda.time.DateTime
class MilestoneOpSpec extends FunSpec
with api.Constants
{
private def removeAll = {
val list = Await.result(api.listMilestones(user, userRepo, MilestoneListOption(state=MilestoneState.all)), TIMEOUT)
list.foreach { m =>
Await.result(api.removeMilestone(user, userRepo, m.number), TIMEOUT)
}
}
private def create(input: MilestoneInput): Milestone = {
Await.result(api.createMilestone(user, userRepo, input), TIMEOUT)
}
describe("createMilestone") {
removeAll
val gName = generateRandomString
val gDescription = generateRandomString
val d1 = DateTime.now().plusMonths(1).withMillisOfSecond(0)
it("without description and due_on should succeed") {
val input = MilestoneInput(gName)
val m = Await.result(api.createMilestone(user, userRepo, input), TIMEOUT)
assert(m.title == gName)
assert(m.state == MilestoneState.open)
assert(m.description.isEmpty)
assert(m.due_on.isEmpty)
}
it("without due_on should succeed") {
val input = MilestoneInput(gName, gDescription)
val m = Await.result(api.createMilestone(user, userRepo, input), TIMEOUT)
assert(m.title == gName)
assert(m.state == MilestoneState.open)
assert(m.description.get == gDescription)
assert(m.due_on.isEmpty)
}
it("without description should succeed") {
val input = MilestoneInput(gName, d1)
val m = Await.result(api.createMilestone(user, userRepo, input), TIMEOUT)
assert(m.title == gName)
assert(m.state == MilestoneState.open)
assert(m.description.isEmpty)
// assert(m.due_on.get == d1)
}
it("with description and due_on should succeed") {
val input = MilestoneInput(gName, gDescription, d1)
val m = Await.result(api.createMilestone(user, userRepo, input), TIMEOUT)
assert(m.title == gName)
assert(m.state == MilestoneState.open)
assert(m.description.get == gDescription)
// assert(m.due_on.get == d1)
}
it("with wrong reponame should fail") {
val input = MilestoneInput(gName, gDescription, d1)
val ex = Await.result(api.createMilestone(user, repoInvalid, input).failed, TIMEOUT)
ex match {
case e: NotFoundException =>
case _ => fail
}
}
}
describe("getMilestone") {
removeAll
val gName = generateRandomString
val gDescription = generateRandomString
val d1 = DateTime.now().plusMonths(1).withMillisOfSecond(0)
val m1 = create(MilestoneInput(gName, gDescription, d1))
it("should succeed") {
Await.result(api.getMilestone(user, userRepo, m1.number), TIMEOUT).map { m =>
assert(m.url == m1.url)
assert(m.id == m1.id)
assert(m.number == m1.number)
assert(m.state == MilestoneState.open)
assert(m.title == gName)
assert(m.description.get == gDescription)
assert(m.creator.login == m1.creator.login)
assert(m.open_issues == 0)
assert(m.closed_issues == 0)
assert(m.created_at != null)
assert(m.updated_at != null)
assert(m.closed_at.isEmpty)
// assert(m.due_on.get == d1)
}
}
it("should be None") {
assert(Await.result(api.getMilestone(user, userRepo, 999), TIMEOUT).isEmpty)
}
}
describe("updateMilestone") {
val gName1 = generateRandomString
val gDescription1 = generateRandomString
val d1 = DateTime.now().plusMonths(1).withMillisOfSecond(0)
val gName2 = generateRandomString
val gDescription2 = generateRandomString
val d2 = d1.plusMonths(1)
removeAll
val m1 = create(MilestoneInput(gName1, gDescription1, d1))
it("should succeed") {
val input = MilestoneInput(
title=Some(gName2),
state=Some(MilestoneState.closed),
description=Some(gDescription2),
due_on=Some(d2)
)
val m = Await.result(api.updateMilestone(user, userRepo, m1.number, input), TIMEOUT)
assert(m.id == m1.id)
assert(m.number == m1.number)
assert(m.state == MilestoneState.closed)
assert(m.title == gName2)
assert(m.description.get == gDescription2)
assert(m.closed_at.isDefined)
// assert(m.due_on.get == d2)
Await.result(api.getMilestone(user, userRepo, m.number), TIMEOUT).map { m2=>
assert(m2.id == m1.id)
assert(m2.number == m1.number)
assert(m2.state == MilestoneState.closed)
assert(m2.title == gName2)
assert(m2.description.get == gDescription2)
assert(m2.closed_at.isDefined)
// assert(m2.due_on.get == d2)
}
}
}
describe("listMilestones") {
val gName1 = generateRandomString
val gDescription1 = generateRandomString
val d1 = DateTime.now().plusMonths(1).withMillisOfSecond(0)
val gName2 = generateRandomString
val gDescription2 = generateRandomString
val d2 = d1.plusMonths(1)
removeAll
val m1 = create(MilestoneInput(gName1, gDescription1, d1))
val m2 = create(MilestoneInput(gName2, gDescription2, d2))
it("should succeed") {
val list = Await.result(api.listMilestones(user, userRepo), TIMEOUT)
assert(list.size == 2)
val m = list.head
assert(m.title == gName1)
// assert(m.due_on.get == d1)
}
it("with sort desc should succeed") {
val option = MilestoneListOption(direction=SortDirection.desc)
val list = Await.result(api.listMilestones(user, userRepo, option), TIMEOUT)
assert(list.size == 2)
val m = list.head
assert(m.title == gName2)
// assert(m.due_on.get == d2)
}
it("with wrong reponame should fail") {
val ex = Await.result(api.listMilestones(user, repoInvalid).failed, TIMEOUT)
ex match {
case e: NotFoundException =>
case _ => fail
}
}
}
describe("removeMilestone") {
val gName = generateRandomString
val gDescription = generateRandomString
val d1 = DateTime.now().plusMonths(1).withMillisOfSecond(0)
removeAll
val m1 = create(MilestoneInput(gName, gDescription, d1))
it("should succeed") {
val b = Await.result(api.removeMilestone(user, userRepo, m1.number), TIMEOUT)
assert(b)
assert(Await.result(api.getMilestone(user, userRepo, m1.number), TIMEOUT).isEmpty)
val ex = Await.result(api.removeMilestone(user, userRepo, m1.number).failed, TIMEOUT)
ex match {
case e: NotFoundException =>
case _ => fail
}
}
}
}