-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* finish docs set default pagination * Fixes in docs delete default pagination * minor fixes * wip create unit test * create auth unit test * create GHAuth unit test minor fixes * ready to do user test * create user and gist unit test * delete repeat test * minor fix in microsite * minor change
- Loading branch information
1 parent
02be2ca
commit fa439da
Showing
12 changed files
with
467 additions
and
37 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
github4s/shared/src/test/scala/github4s/unit/AuthSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright 2016-2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package github4s.unit | ||
|
||
import cats.Id | ||
import github4s.GithubResponses.{GHResponse, GHResult} | ||
import github4s.HttpClient | ||
import github4s.api.Auth | ||
import github4s.free.domain._ | ||
import github4s.utils.BaseSpec | ||
import com.github.marklister.base64.Base64.Encoder | ||
|
||
class AuthSpec extends BaseSpec { | ||
|
||
"Auth.newAuth" should "call to httpClient.postAuth with the right parameters" in { | ||
|
||
val response: GHResponse[Authorization] = | ||
Right(GHResult(authorization, okStatusCode, Map.empty)) | ||
|
||
val request = | ||
""" | ||
|{ | ||
|"scopes": ["public_repo"], | ||
|"note": "New access token", | ||
|"client_id": "e8e39175648c9db8c280", | ||
|"client_secret": "1234567890" | ||
|}""".stripMargin | ||
|
||
val httpClientMock = httpClientMockPostAuth[Authorization]( | ||
url = "authorizations", | ||
headers = | ||
Map("Authorization" → s"Basic ${s"rafaparadela:invalidPassword".getBytes.toBase64}"), | ||
json = request, | ||
response = response | ||
) | ||
|
||
val auth = new Auth[String, Id] { | ||
override val httpClient: HttpClient[String, Id] = httpClientMock | ||
} | ||
|
||
auth.newAuth( | ||
validUsername, | ||
invalidPassword, | ||
validScopes, | ||
validNote, | ||
validClientId, | ||
invalidClientSecret, | ||
headerUserAgent) | ||
} | ||
|
||
"Auth.getAccessToken" should "call to httpClient.postOAuth with the right parameters" in { | ||
|
||
val response: GHResponse[OAuthToken] = | ||
Right(GHResult(oAuthToken, okStatusCode, Map.empty)) | ||
|
||
val request = | ||
s""" | ||
|{ | ||
|"client_id": "e8e39175648c9db8c280", | ||
|"client_secret": "1234567890", | ||
|"code": "code", | ||
|"redirect_uri": "http://localhost:9000/_oauth-callback", | ||
|"state": "$validAuthState" | ||
|}""".stripMargin | ||
|
||
val httpClientMock = httpClientMockPostOAuth[OAuthToken]( | ||
url = "http://127.0.0.1:9999/login/oauth/access_token", | ||
json = request, | ||
response = response | ||
) | ||
|
||
val auth = new Auth[String, Id] { | ||
override val httpClient: HttpClient[String, Id] = httpClientMock | ||
} | ||
|
||
auth.getAccessToken( | ||
validClientId, | ||
invalidClientSecret, | ||
validCode, | ||
validRedirectUri, | ||
validAuthState, | ||
headerUserAgent) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
github4s/shared/src/test/scala/github4s/unit/GHAuthSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2016-2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package github4s.unit | ||
|
||
import cats.free.Free | ||
import github4s.GithubResponses.{GHResponse, GHResult} | ||
import github4s.{GHAuth, HttpClient} | ||
import github4s.app.GitHub4s | ||
import github4s.free.domain._ | ||
import github4s.utils.BaseSpec | ||
|
||
class GHAuthSpec extends BaseSpec { | ||
|
||
"Auth.newAuth" should "call to AuthOps with the right parameters" in { | ||
|
||
val response: Free[GitHub4s, GHResponse[Authorization]] = | ||
Free.pure(Right(GHResult(authorization, okStatusCode, Map.empty))) | ||
|
||
val authOps = mock[AuthOpsTest] | ||
(authOps.newAuth _) | ||
.expects( | ||
validUsername, | ||
invalidPassword, | ||
validScopes, | ||
validNote, | ||
validClientId, | ||
invalidClientSecret) | ||
.returns(response) | ||
|
||
val ghAuth = new GHAuth(None)(authOps) | ||
ghAuth.newAuth( | ||
validUsername, | ||
invalidPassword, | ||
validScopes, | ||
validNote, | ||
validClientId, | ||
invalidClientSecret) | ||
} | ||
|
||
"Auth.getAccessToken" should "call to AuthOps with the right parameters" in { | ||
|
||
val response: Free[GitHub4s, GHResponse[OAuthToken]] = | ||
Free.pure(Right(GHResult(oAuthToken, okStatusCode, Map.empty))) | ||
|
||
val authOps = mock[AuthOpsTest] | ||
(authOps.getAccessToken _) | ||
.expects(validClientId, invalidClientSecret, validCode, validRedirectUri, validAuthState) | ||
.returns(response) | ||
|
||
val ghAuth = new GHAuth(None)(authOps) | ||
ghAuth.getAccessToken( | ||
validClientId, | ||
invalidClientSecret, | ||
validCode, | ||
validRedirectUri, | ||
validAuthState) | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
github4s/shared/src/test/scala/github4s/unit/GHGistSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2016-2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package github4s.unit | ||
|
||
import cats.free.Free | ||
import github4s.GithubResponses.{GHResponse, GHResult} | ||
import github4s.{GHGists, HttpClient} | ||
import github4s.app.GitHub4s | ||
import github4s.free.domain._ | ||
import github4s.utils.BaseSpec | ||
|
||
class GHGistSpec extends BaseSpec { | ||
|
||
"Gist.newGist" should "call to GistOps with the right parameters" in { | ||
|
||
val response: Free[GitHub4s, GHResponse[Gist]] = | ||
Free.pure(Right(GHResult(gist, okStatusCode, Map.empty))) | ||
|
||
val gistOps = mock[GistOpsTest] | ||
(gistOps.newGist _) | ||
.expects( | ||
validGistDescription, | ||
validGistPublic, | ||
Map(validGistFilename → GistFile(validGistFileContent)), | ||
sampleToken) | ||
.returns(response) | ||
|
||
val ghGists = new GHGists(sampleToken)(gistOps) | ||
ghGists.newGist( | ||
validGistDescription, | ||
validGistPublic, | ||
Map(validGistFilename → GistFile(validGistFileContent))) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
github4s/shared/src/test/scala/github4s/unit/GHUserSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright 2016-2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package github4s.unit | ||
|
||
import cats.free.Free | ||
import github4s.GithubResponses.{GHResponse, GHResult} | ||
import github4s.{GHUsers, HttpClient} | ||
import github4s.app.GitHub4s | ||
import github4s.free.domain._ | ||
import github4s.utils.BaseSpec | ||
|
||
class GHUserSpec extends BaseSpec { | ||
|
||
"User.getUser" should "call to UserOps with the right parameters" in { | ||
|
||
val response: Free[GitHub4s, GHResponse[User]] = | ||
Free.pure(Right(GHResult(user, okStatusCode, Map.empty))) | ||
|
||
val userOps = mock[UserOpsTest] | ||
(userOps.getUser _) | ||
.expects(validUsername, sampleToken) | ||
.returns(response) | ||
|
||
val ghUsers = new GHUsers(sampleToken)(userOps) | ||
ghUsers.get(validUsername) | ||
} | ||
|
||
"User.getAuthUser" should "call to UserOps with the right parameters" in { | ||
|
||
val response: Free[GitHub4s, GHResponse[User]] = | ||
Free.pure(Right(GHResult(user, okStatusCode, Map.empty))) | ||
|
||
val userOps = mock[UserOpsTest] | ||
(userOps.getAuthUser _) | ||
.expects(sampleToken) | ||
.returns(response) | ||
|
||
val ghUsers = new GHUsers(sampleToken)(userOps) | ||
ghUsers.getAuth | ||
} | ||
|
||
"User.getUsers" should "call to UserOps with the right parameters" in { | ||
|
||
val response: Free[GitHub4s, GHResponse[List[User]]] = | ||
Free.pure(Right(GHResult(List(user), okStatusCode, Map.empty))) | ||
|
||
val userOps = mock[UserOpsTest] | ||
(userOps.getUsers _) | ||
.expects(1, None, sampleToken) | ||
.returns(response) | ||
|
||
val ghUsers = new GHUsers(sampleToken)(userOps) | ||
ghUsers.getUsers(1) | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
github4s/shared/src/test/scala/github4s/unit/GistSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2016-2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package github4s.unit | ||
|
||
import cats.Id | ||
import github4s.GithubResponses.{GHResponse, GHResult} | ||
import github4s.HttpClient | ||
import github4s.api.Gists | ||
import github4s.free.domain._ | ||
import github4s.utils.BaseSpec | ||
|
||
class GistSpec extends BaseSpec { | ||
|
||
"Gist.newGist" should "call to httpClient.post with the right parameters" in { | ||
|
||
val response: GHResponse[Gist] = | ||
Right(GHResult(gist, okStatusCode, Map.empty)) | ||
|
||
val request = | ||
""" | ||
|{ | ||
| "description": "A Gist", | ||
| "public": true, | ||
| "files": { | ||
| "test.scala": { | ||
| "content": "val meaningOfLife = 42" | ||
| } | ||
| } | ||
|}""".stripMargin | ||
|
||
val httpClientMock = httpClientMockPost[Gist]( | ||
url = "gists", | ||
json = request, | ||
response = response | ||
) | ||
|
||
val gists = new Gists[String, Id] { | ||
override val httpClient: HttpClient[String, Id] = httpClientMock | ||
} | ||
|
||
gists.newGist( | ||
validGistDescription, | ||
validGistPublic, | ||
Map(validGistFilename → GistFile(validGistFileContent)), | ||
headerUserAgent, | ||
sampleToken | ||
) | ||
} | ||
|
||
} |
Oops, something went wrong.