Skip to content

Commit

Permalink
Merge pull request #5 from 47deg/rafa-fix-unit-tests
Browse files Browse the repository at this point in the history
Fixes test
  • Loading branch information
Rafa Paradela committed May 12, 2016
2 parents fa7bf93 + db65758 commit 6c365dd
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 55 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -2,4 +2,6 @@ language: scala
scala:
- 2.11.8
jdk:
- oraclejdk8
- oraclejdk8
script:
- sbt -Dtoken=$GITHUB4S_ACCESS_TOKEN test
4 changes: 2 additions & 2 deletions src/main/scala/com/fortysevendeg/github4s/GithubAPIs.scala
Expand Up @@ -17,7 +17,7 @@ class GHUsers(accessToken : Option[String] = None)(implicit O : UserOps[GitHub4s

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

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

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

}

Expand Down
Expand Up @@ -2,5 +2,4 @@ package com.fortysevendeg.github4s.free.domain

case class Repository(
id: Int,
//owner: Collaborator,
name: String)
36 changes: 0 additions & 36 deletions src/test/scala/GHReposSpec.scala

This file was deleted.

@@ -1,4 +1,9 @@
package com.fortysevendeg.github4s

trait TestUtils {

val accessToken = sys.props.get("token")

val validUsername = "rafaparadela"
val invalidUsername = "GHInvalidaUserName"
val invalidPassword = "invalidPassword"
Expand All @@ -16,5 +21,8 @@ trait TestUtils {
val validSinceInt = 100
val invalidSinceInt = -1

val statusCodeOK = 200
val okStatusCode = 200
val unauthorizedStatusCode = 401
val notFoundStatusCode = 404

}
@@ -1,10 +1,12 @@
package com.fortysevendeg.github4s.integration

import cats.Id
import cats.scalatest.{XorMatchers, XorValues}
import com.fortysevendeg.github4s.Github._
import com.fortysevendeg.github4s.GithubResponses._
import com.fortysevendeg.github4s.free.interpreters.IdInterpreters._
import com.fortysevendeg.github4s.Github
import com.fortysevendeg.github4s.Github._
import com.fortysevendeg.github4s.{Github, TestUtils}
import org.scalatest._
import cats.scalatest.{XorValues, XorMatchers}

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

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

"Auth >> GetAccessToken" should "return error on Left for invalid code value" in {
Expand Down
@@ -0,0 +1,39 @@
package com.fortysevendeg.github4s.integration

import cats.Id
import cats.scalatest.{XorMatchers, XorValues}
import com.fortysevendeg.github4s.Github._
import com.fortysevendeg.github4s.GithubResponses._
import com.fortysevendeg.github4s.free.interpreters.IdInterpreters._
import com.fortysevendeg.github4s.{Github, TestUtils}
import org.scalatest.{Matchers, FlatSpec}


class GHReposSpec extends FlatSpec with Matchers with XorMatchers with XorValues with TestUtils {

"Repos >> Get" should "return the expected name when valid repo is provided" in {

val response = Github(accessToken).repos.get(validRepoOwner, validRepoName).exec[Id]
response shouldBe right
response.value.entity.name shouldBe validRepoName
response.value.statusCode shouldBe okStatusCode
}

it should "return error when an invalid repo name is passed" in {
val response = Github(accessToken).repos.get(validRepoOwner, invalidRepoName).exec[Id]
response shouldBe left
}

"Repos >> ListCommits" should "return the expected list of commits for valid data" in {
val response = Github(accessToken).repos.listCommits(validRepoOwner, validRepoName).exec[Id]
response shouldBe right
response.value.entity.nonEmpty shouldBe true
response.value.statusCode shouldBe okStatusCode
}

it should "return error for invalid repo name" in {
val response = Github(accessToken).repos.listCommits(invalidRepoName, validRepoName).exec[Id]
response shouldBe left
}

}
@@ -1,23 +1,25 @@
package com.fortysevendeg.github4s.integration

import cats.Id
import cats.scalatest.{XorMatchers, XorValues}
import com.fortysevendeg.github4s.Github._
import com.fortysevendeg.github4s.GithubResponses._
import com.fortysevendeg.github4s.free.interpreters.IdInterpreters._
import com.fortysevendeg.github4s.Github
import com.fortysevendeg.github4s.Github._
import com.fortysevendeg.github4s.{Github, TestUtils}
import org.scalatest._
import cats.scalatest.{XorValues, XorMatchers}


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

"Users >> Get" should "return the expected login for a valid username" in {
val response = Github().users.get(validUsername).exec[Id]
val response = Github(accessToken).users.get(validUsername).exec[Id]
response shouldBe right
response.value.entity.login shouldBe validUsername
response.value.statusCode shouldBe statusCodeOK
response.value.statusCode shouldBe okStatusCode
}

it should "return error on Left for invalid username" in {
val response = Github().users.get(invalidUsername).exec[Id]
val response = Github(accessToken).users.get(invalidUsername).exec[Id]
response shouldBe left
}

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

"Users >> GetUsers" should "return users for a valid since value" in {
val response = Github().users.getUsers(validSinceInt).exec[Id]
val response = Github(accessToken).users.getUsers(validSinceInt).exec[Id]
response shouldBe right
response.value.entity.nonEmpty shouldBe true
response.value.statusCode shouldBe statusCodeOK
response.value.statusCode shouldBe okStatusCode
}

it should "return error on Left when a invalid since value is provided" in {
val response = Github().users.getUsers(invalidSinceInt).exec[Id]
val response = Github(accessToken).users.getUsers(invalidSinceInt).exec[Id]
response shouldBe right
response.value.entity.nonEmpty shouldBe true
response.value.statusCode shouldBe statusCodeOK
response.value.statusCode shouldBe okStatusCode
}

}

0 comments on commit 6c365dd

Please sign in to comment.