-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing unit test #137
Merged
Merged
Missing unit test #137
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0eb36c2
finish docs
d5deb49
Fixes in docs
a0e4f20
minor fixes
17f0a7e
wip create unit test
e2bd894
create auth unit test
63d0e15
create GHAuth unit test
7d4993d
ready to do user test
572195d
create user and gist unit test
47212ee
delete repeat test
51f6f77
minor fix in microsite
d9e9654
minor change
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious as to why you had to specify the whole url?