Skip to content

Commit 6c365dd

Browse files
author
Rafa Paradela
committed
Merge pull request #5 from 47deg/rafa-fix-unit-tests
Fixes test
2 parents fa7bf93 + db65758 commit 6c365dd

8 files changed

Lines changed: 71 additions & 55 deletions

File tree

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ language: scala
22
scala:
33
- 2.11.8
44
jdk:
5-
- oraclejdk8
5+
- oraclejdk8
6+
script:
7+
- sbt -Dtoken=$GITHUB4S_ACCESS_TOKEN test

src/main/scala/com/fortysevendeg/github4s/GithubAPIs.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class GHUsers(accessToken : Option[String] = None)(implicit O : UserOps[GitHub4s
1717

1818
class GHRepos(accessToken : Option[String] = None)(implicit O : RepositoryOps[GitHub4s]){
1919

20-
def get(owner : String, repo: String): GHIO[GHResponse[Repository]] = O.getRepo(owner, repo)
20+
def get(owner : String, repo: String): GHIO[GHResponse[Repository]] = O.getRepo(owner, repo, accessToken)
2121

2222
def listCommits(
2323
owner: String,
@@ -28,7 +28,7 @@ class GHRepos(accessToken : Option[String] = None)(implicit O : RepositoryOps[Gi
2828
since: Option[String] = None,
2929
until: Option[String] = None,
3030
pagination: Option[Pagination] = None): GHIO[GHResponse[List[Commit]]] =
31-
O.listCommits(owner, repo, sha, path, author, since, until, pagination)
31+
O.listCommits(owner, repo, sha, path, author, since, until, pagination, accessToken)
3232

3333
}
3434

src/main/scala/com/fortysevendeg/github4s/free/domain/Repository.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ package com.fortysevendeg.github4s.free.domain
22

33
case class Repository(
44
id: Int,
5-
//owner: Collaborator,
65
name: String)

src/test/scala/GHReposSpec.scala

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/test/scala/testUtils.scala renamed to src/test/scala/com.fortysevendeg.github4s/TestUtils.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
package com.fortysevendeg.github4s
2+
13
trait TestUtils {
4+
5+
val accessToken = sys.props.get("token")
6+
27
val validUsername = "rafaparadela"
38
val invalidUsername = "GHInvalidaUserName"
49
val invalidPassword = "invalidPassword"
@@ -16,5 +21,8 @@ trait TestUtils {
1621
val validSinceInt = 100
1722
val invalidSinceInt = -1
1823

19-
val statusCodeOK = 200
24+
val okStatusCode = 200
25+
val unauthorizedStatusCode = 401
26+
val notFoundStatusCode = 404
27+
2028
}

src/test/scala/GHAuthSpec.scala renamed to src/test/scala/com.fortysevendeg.github4s/integration/GHAuthSpec.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
package com.fortysevendeg.github4s.integration
2+
13
import cats.Id
4+
import cats.scalatest.{XorMatchers, XorValues}
5+
import com.fortysevendeg.github4s.Github._
26
import com.fortysevendeg.github4s.GithubResponses._
37
import com.fortysevendeg.github4s.free.interpreters.IdInterpreters._
4-
import com.fortysevendeg.github4s.Github
5-
import com.fortysevendeg.github4s.Github._
8+
import com.fortysevendeg.github4s.{Github, TestUtils}
69
import org.scalatest._
7-
import cats.scalatest.{XorValues, XorMatchers}
810

911
class GHAuthSpec extends FlatSpec with Matchers with XorMatchers with XorValues with TestUtils {
1012

@@ -17,7 +19,7 @@ class GHAuthSpec extends FlatSpec with Matchers with XorMatchers with XorValues
1719
val response = Github().auth.authorizeUrl(validClientId, validRedirectUri, validScopes).exec[Id]
1820
response shouldBe right
1921
response.value.entity.url.contains(validRedirectUri) shouldBe true
20-
response.value.statusCode shouldBe statusCodeOK
22+
response.value.statusCode shouldBe okStatusCode
2123
}
2224

2325
"Auth >> GetAccessToken" should "return error on Left for invalid code value" in {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.fortysevendeg.github4s.integration
2+
3+
import cats.Id
4+
import cats.scalatest.{XorMatchers, XorValues}
5+
import com.fortysevendeg.github4s.Github._
6+
import com.fortysevendeg.github4s.GithubResponses._
7+
import com.fortysevendeg.github4s.free.interpreters.IdInterpreters._
8+
import com.fortysevendeg.github4s.{Github, TestUtils}
9+
import org.scalatest.{Matchers, FlatSpec}
10+
11+
12+
class GHReposSpec extends FlatSpec with Matchers with XorMatchers with XorValues with TestUtils {
13+
14+
"Repos >> Get" should "return the expected name when valid repo is provided" in {
15+
16+
val response = Github(accessToken).repos.get(validRepoOwner, validRepoName).exec[Id]
17+
response shouldBe right
18+
response.value.entity.name shouldBe validRepoName
19+
response.value.statusCode shouldBe okStatusCode
20+
}
21+
22+
it should "return error when an invalid repo name is passed" in {
23+
val response = Github(accessToken).repos.get(validRepoOwner, invalidRepoName).exec[Id]
24+
response shouldBe left
25+
}
26+
27+
"Repos >> ListCommits" should "return the expected list of commits for valid data" in {
28+
val response = Github(accessToken).repos.listCommits(validRepoOwner, validRepoName).exec[Id]
29+
response shouldBe right
30+
response.value.entity.nonEmpty shouldBe true
31+
response.value.statusCode shouldBe okStatusCode
32+
}
33+
34+
it should "return error for invalid repo name" in {
35+
val response = Github(accessToken).repos.listCommits(invalidRepoName, validRepoName).exec[Id]
36+
response shouldBe left
37+
}
38+
39+
}

src/test/scala/GHUsersSpec.scala renamed to src/test/scala/com.fortysevendeg.github4s/integration/GHUsersSpec.scala

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1+
package com.fortysevendeg.github4s.integration
2+
13
import cats.Id
4+
import cats.scalatest.{XorMatchers, XorValues}
5+
import com.fortysevendeg.github4s.Github._
26
import com.fortysevendeg.github4s.GithubResponses._
37
import com.fortysevendeg.github4s.free.interpreters.IdInterpreters._
4-
import com.fortysevendeg.github4s.Github
5-
import com.fortysevendeg.github4s.Github._
8+
import com.fortysevendeg.github4s.{Github, TestUtils}
69
import org.scalatest._
7-
import cats.scalatest.{XorValues, XorMatchers}
810

911

1012
class GHUsersSpec extends FlatSpec with Matchers with XorMatchers with XorValues with TestUtils {
1113

1214
"Users >> Get" should "return the expected login for a valid username" in {
13-
val response = Github().users.get(validUsername).exec[Id]
15+
val response = Github(accessToken).users.get(validUsername).exec[Id]
1416
response shouldBe right
1517
response.value.entity.login shouldBe validUsername
16-
response.value.statusCode shouldBe statusCodeOK
18+
response.value.statusCode shouldBe okStatusCode
1719
}
1820

1921
it should "return error on Left for invalid username" in {
20-
val response = Github().users.get(invalidUsername).exec[Id]
22+
val response = Github(accessToken).users.get(invalidUsername).exec[Id]
2123
response shouldBe left
2224
}
2325

@@ -27,17 +29,17 @@ class GHUsersSpec extends FlatSpec with Matchers with XorMatchers with XorValues
2729
}
2830

2931
"Users >> GetUsers" should "return users for a valid since value" in {
30-
val response = Github().users.getUsers(validSinceInt).exec[Id]
32+
val response = Github(accessToken).users.getUsers(validSinceInt).exec[Id]
3133
response shouldBe right
3234
response.value.entity.nonEmpty shouldBe true
33-
response.value.statusCode shouldBe statusCodeOK
35+
response.value.statusCode shouldBe okStatusCode
3436
}
3537

3638
it should "return error on Left when a invalid since value is provided" in {
37-
val response = Github().users.getUsers(invalidSinceInt).exec[Id]
39+
val response = Github(accessToken).users.getUsers(invalidSinceInt).exec[Id]
3840
response shouldBe right
3941
response.value.entity.nonEmpty shouldBe true
40-
response.value.statusCode shouldBe statusCodeOK
42+
response.value.statusCode shouldBe okStatusCode
4143
}
4244

4345
}

0 commit comments

Comments
 (0)