Skip to content

Commit 064b149

Browse files
committed
[WIP] #3 - Fixed query string generator. Created more tests for issue listing methods.
1 parent eabba6c commit 064b149

File tree

2 files changed

+51
-36
lines changed

2 files changed

+51
-36
lines changed

src/main/scala/codecheck/github/models/Issue.scala

+13-21
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,14 @@ object IssueSort {
5555
def fromString(str: String) = values.filter(_.name == str).head
5656
}
5757

58-
sealed abstract class MilestoneSearchOption {
59-
58+
sealed abstract class MilestoneSearchOption(val name: String) {
59+
override def toString = name
6060
}
6161

6262
object MilestoneSearchOption {
63-
case object all extends MilestoneSearchOption {
64-
val value = JString("*")
65-
}
66-
67-
case object none extends MilestoneSearchOption {
68-
val value = JString("none")
69-
}
70-
71-
case class Specified(number: Int) extends MilestoneSearchOption {
72-
val value = JInt(number)
73-
}
63+
case object all extends MilestoneSearchOption("*")
64+
case object none extends MilestoneSearchOption("none")
65+
case class Specified(number: Int) extends MilestoneSearchOption(number.toString())
7466

7567
def apply(number: Int) = Specified(number)
7668
}
@@ -84,8 +76,8 @@ case class IssueListOption(
8476
since: Option[DateTime] = None
8577
) {
8678
def q = s"?filter=$filter&state=$state&sort=$sort&direction=$direction" +
87-
(if (labels.length == 0) "" else "&labels=" + labels.mkString(",")) +
88-
since.map("&since=" + _.toString("yyyy-MM-dd'T'HH:mm:ssZ"))
79+
(if (!labels.isEmpty) "&labels=" + labels.mkString(",") else "") +
80+
(if (!since.isEmpty) (since map ("&since=" + _.toString("yyyy-MM-dd'T'HH:mm:ss'Z'"))).get else "")
8981
}
9082

9183
case class IssueListOption4Repository(
@@ -99,15 +91,15 @@ case class IssueListOption4Repository(
9991
direction: SortDirection = SortDirection.desc,
10092
since: Option[DateTime] = None
10193
) {
102-
def q: String = "?" + (if (!milestone.isEmpty) milestone map (t => s"milestone=$t&")) +
94+
def q: String = "?" + (if (!milestone.isEmpty) (milestone map (t => s"milestone=$t&")).get else "") +
10395
s"state=$state" +
104-
(if (!assignee.isEmpty) assignee map (t => s"&assignee=$t")) +
105-
(if (!creator.isEmpty) creator map (t => s"&creator=$t")) +
106-
(if (!mentioned.isEmpty) mentioned map (t => s"&mentioned=$t")) +
107-
(if (!labels.isEmpty) "&labels=" + labels.mkString(",")) +
96+
(if (!assignee.isEmpty) (assignee map (t => s"&assignee=$t")).get else "") +
97+
(if (!creator.isEmpty) (creator map (t => s"&creator=$t")).get else "") +
98+
(if (!mentioned.isEmpty) (mentioned map (t => s"&mentioned=$t")).get else "") +
99+
(if (!labels.isEmpty) "&labels=" + labels.mkString(",") else "") +
108100
s"&sort=$sort" +
109101
s"&direction=$direction" +
110-
(if (!since.isEmpty) since map ("&since=" + _.toString("yyyy-MM-dd'T'HH:mm:ssZ")))
102+
(if (!since.isEmpty) (since map ("&since=" + _.toString("yyyy-MM-dd'T'HH:mm:ss'Z'"))).get else "")
111103
}
112104

113105
case class IssueInput(

src/test/scala/IssueOpSpec.scala

+38-15
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@ import codecheck.github.models.IssueListOption4Repository
1010
import codecheck.github.models.IssueState
1111
import codecheck.github.models.Issue
1212
import codecheck.github.models.IssueInput
13+
import codecheck.github.models.MilestoneSearchOption
1314

1415
class IssueOpSpec extends FunSpec with Constants {
1516

1617
val number = 1
1718
var nUser: Long = 0
1819
var nOrg: Long = 0
19-
var createdUser: DateTime = DateTime.now
20-
var createdOrg: DateTime = DateTime.now
20+
var nTime: DateTime = DateTime.now()
2121

2222
describe("createIssue(owner, repo, input)") {
2323
val input = IssueInput(Some("test issue"), Some("testing"), Some(user), Some(1), Seq("question"))
2424

2525
it("should create issue for user's own repo.") {
2626
val result = Await.result(api.createIssue(user, userRepo, input), TIMEOUT)
27-
//showResponse(result)
2827
nUser = result.number
2928
assert(result.url == "https://api.github.com/repos/" + user + "/" + userRepo + "/issues/" + nUser)
3029
assert(result.labels_url == "https://api.github.com/repos/" + user + "/" + userRepo + "/issues/" + nUser + "/labels{/name}")
@@ -41,7 +40,6 @@ class IssueOpSpec extends FunSpec with Constants {
4140
assert(result.comments == 0)
4241
assert(result.created_at.toDateTime(DateTimeZone.UTC).getMillis() - DateTime.now(DateTimeZone.UTC).getMillis() <= 5000)
4342
assert(result.updated_at.toDateTime(DateTimeZone.UTC).getMillis() - DateTime.now(DateTimeZone.UTC).getMillis() <= 5000)
44-
createdUser = result.created_at
4543
assert(result.closed_at.isEmpty)
4644
assert(result.body.get == "testing")
4745
assert(result.closed_by.isEmpty)
@@ -65,8 +63,6 @@ class IssueOpSpec extends FunSpec with Constants {
6563
assert(result.comments == 0)
6664
assert(result.created_at.toDateTime(DateTimeZone.UTC).getMillis() - DateTime.now(DateTimeZone.UTC).getMillis() <= 5000)
6765
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)
7066
assert(result.body.get == "testing")
7167
assert(result.closed_by.isEmpty)
7268
}
@@ -114,10 +110,10 @@ class IssueOpSpec extends FunSpec with Constants {
114110
assert(result.length > 0)
115111
}
116112

117-
it("shold return only one issue.") {
118-
val option = IssueListOption(IssueFilter.all, IssueState.open, since=Some(createdUser))
113+
it("shold return only two issues when using options.") {
114+
val option = IssueListOption(IssueFilter.created, IssueState.open, Seq("question"), since=Some(nTime))
119115
val result = Await.result(api.listAllIssues(option), TIMEOUT)
120-
assert(result.length == 1)
116+
assert(result.length == 2)
121117
assert(result.head.title == "test issue")
122118
}
123119
}
@@ -127,26 +123,53 @@ class IssueOpSpec extends FunSpec with Constants {
127123
val result = Await.result(api.listUserIssues(), TIMEOUT)
128124
assert(result.length > 0)
129125
}
126+
127+
it("shold return only one issues when using options.") {
128+
val option = IssueListOption(IssueFilter.created, IssueState.open, Seq("question"), since=Some(nTime))
129+
val result = Await.result(api.listUserIssues(option), TIMEOUT)
130+
assert(result.length == 1)
131+
assert(result.head.title == "test issue")
132+
}
130133
}
131134

132135
describe("listOrgIssues(org, option)") {
133136
it("should return at least one issue.") {
134137
val result = Await.result(api.listOrgIssues(organization), TIMEOUT)
135138
assert(result.length > 0)
136139
}
140+
141+
it("shold return only one issues when using options.") {
142+
val option = IssueListOption(IssueFilter.created, IssueState.open, Seq("question"), since=Some(nTime))
143+
val result = Await.result(api.listOrgIssues(organization, option), TIMEOUT)
144+
assert(result.length == 1)
145+
assert(result.head.title == "test issue")
146+
}
137147
}
138148

139149
describe("listRepositoryIssues(owner, repo, option)") {
140-
it("should return at least one issue.") {
150+
it("should return at least one issue from user's own repo.") {
141151
val result = Await.result(api.listRepositoryIssues(organization, repo), TIMEOUT)
142152
assert(result.length > 0)
143153
}
144-
}
145154

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)
155+
it("should return at least one issue from organization's repo.") {
156+
val result = Await.result(api.listRepositoryIssues(organization, repo), TIMEOUT)
157+
assert(result.length > 0)
158+
}
159+
160+
it("should return only one issue from user's own repo when using options.") {
161+
val option = new IssueListOption4Repository(Some(MilestoneSearchOption(1)), IssueState.open, Some(user), Some(user), labels=Seq("question"), since=Some(nTime))
162+
val result = Await.result(api.listRepositoryIssues(user, userRepo), TIMEOUT)
163+
//showResponse(result)
164+
assert(result.length == 1)
165+
}
166+
167+
it("should return only one issue from organization's repo when using options.") {
168+
val option = IssueListOption4Repository(Some(MilestoneSearchOption.all), IssueState.open, Some(user), Some(user), labels=Seq("question"), since=Some(nTime))
169+
val result = Await.result(api.listRepositoryIssues(organization, repo, option), TIMEOUT)
170+
showResponse(option.q)
171+
showResponse(result)
172+
//assert(result.length == 1)
150173
}
151174
}
152175

0 commit comments

Comments
 (0)