Skip to content

Commit c7eb8e3

Browse files
author
Takayuki Oda
committed
Merge pull request #53 from code-check/email-to-option
Email to option
2 parents b61df6f + 8601f64 commit c7eb8e3

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import org.json4s.JsonDSL._
77
case class User(value: JValue) extends AbstractJson(value) {
88
def login: String = get("login")
99
def id: Long = get("id").toLong
10-
def email: String = get("email")
11-
def name: String = get("name")
12-
def blog: String = get("blog")
13-
def company: String = get("company")
14-
def location: String = get("location")
15-
def hireable: Boolean = boolean("hireable")
10+
def email: Option[String] = opt("email")
11+
def name: Option[String] = opt("name")
12+
def blog: Option[String] = opt("blog")
13+
def company: Option[String] = opt("company")
14+
def location: Option[String] = opt("location")
15+
def hireable: Boolean = booleanOpt("hireable").getOrElse(false)
1616
def bio: Option[String] = opt("bio")
1717
}
1818

@@ -25,4 +25,4 @@ case class UserInput (
2525
location: Option[String] = None,
2626
hireable: Option[Boolean] = None,
2727
bio: Option[String] = None
28-
) extends AbstractInput
28+
) extends AbstractInput

src/main/scala/codecheck/github/operations/MilestoneOp.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ trait MilestoneOp {
1616
self: GitHubAPI =>
1717

1818
def listMilestones(
19-
owner: String,
20-
repo: String,
19+
owner: String,
20+
repo: String,
2121
option: MilestoneListOption = MilestoneListOption()
2222
): Future[List[Milestone]] = {
2323
val path = s"/repos/$owner/$repo/milestones?state=${option.state}&sort=${option.sort}&direction=${option.direction}"
24-
exec("GET", path).map(
24+
exec("GET", path).map(
2525
_.body match {
2626
case JArray(arr) => arr.map(v => Milestone(v))
2727
case _ => throw new IllegalStateException()

src/test/scala/UserOpSpec.scala

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,23 @@ import scala.concurrent.Await
88
import scala.concurrent.ExecutionContext.Implicits.global
99
import codecheck.github.models.UserInput
1010

11-
class UserOpSpec extends FunSpec
12-
with Constants
11+
class UserOpSpec extends FunSpec
12+
with Constants
1313
with BeforeAndAfterAll
1414
{
1515
val origin = Await.result(api.getAuthenticatedUser, TIMEOUT)
1616

1717
override def afterAll() {
1818
val input = UserInput(
19-
Some(origin.name),
20-
Some(origin.email),
21-
Some(origin.blog),
22-
Some(origin.company),
23-
Some(origin.location),
19+
origin.name.orElse(Some("")),
20+
origin.email.orElse(Some("")),
21+
origin.blog.orElse(Some("")),
22+
origin.company.orElse(Some("")),
23+
origin.location.orElse(Some("")),
2424
Some(origin.hireable),
25-
origin.bio
25+
origin.bio.orElse(Some(""))
2626
)
2727
val user = Await.result(api.updateAuthenticatedUser(input), TIMEOUT)
28-
println("AFTER: " + user)
2928
}
3029
describe("getUser") {
3130
it("with valid username should succeed") {
@@ -52,12 +51,11 @@ class UserOpSpec extends FunSpec
5251
Some("bio")
5352
)
5453
val res = Await.result(api.updateAuthenticatedUser(input), TIMEOUT)
55-
println("TEST: " + res)
56-
assert(res.name == input.name.get)
57-
assert(res.email == input.email.get)
58-
assert(res.blog == input.blog.get)
59-
assert(res.company == input.company.get)
60-
assert(res.location == input.location.get)
54+
assert(res.name.get == input.name.get)
55+
assert(res.email.getOrElse("") == input.email.get)
56+
assert(res.blog.get == input.blog.get)
57+
assert(res.company.get == input.company.get)
58+
assert(res.location.get == input.location.get)
6159
assert(res.bio.get == input.bio.get)
6260
}
6361
}
@@ -77,4 +75,4 @@ class UserOpSpec extends FunSpec
7775
assert((res{0}.id).toLong == userOpGet.id)
7876
}
7977
}
80-
}
78+
}

0 commit comments

Comments
 (0)