Skip to content

Commit

Permalink
add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
vermaxik committed Jun 2, 2020
1 parent 97c020b commit 54d29d1
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/fixture/vcr_cassettes/starring#stargazers_failed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"request": {
"body": "\"\\\"\\\"\"",
"headers": {
"User-agent": "tentacat",
"Authorization": "token yourtokencomeshere"
},
"method": "get",
"options": [],
"request_body": "",
"url": "https://api.github.com/repos/elixir-lang/elixir/stargazers"
},
"response": {
"binary": false,
"body": "{\"message\":\"Bad credentials\",\"documentation_url\":\"https://developer.github.com/v3\"}",
"headers": {
"Date": "Tue, 02 Jun 2020 20:31:18 GMT",
"Content-Type": "application/json; charset=utf-8",
"Content-Length": "83",
"Server": "GitHub.com",
"Status": "401 Unauthorized",
"X-GitHub-Media-Type": "github.v3; format=json",
"X-RateLimit-Limit": "60",
"X-RateLimit-Remaining": "59",
"X-RateLimit-Reset": "1591133478",
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset",
"Access-Control-Allow-Origin": "*",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"Vary": "Accept-Encoding, Accept, X-Requested-With",
"X-GitHub-Request-Id": "BDB7:3CF31:AED450E:D058229:5ED6B716"
},
"status_code": 401,
"type": "ok"
}
}
]
46 changes: 46 additions & 0 deletions test/fixture/vcr_cassettes/starring#stargazers_success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"request": {
"body": "\"\\\"\\\"\"",
"headers": {
"User-agent": "tentacat",
"Authorization": "token yourtokencomeshere"
},
"method": "get",
"options": [],
"request_body": "",
"url": "https://api.github.com/repos/elixir-lang/elixir/stargazers"
},
"response": {
"binary": false,
"body": "[{\"login\":\"login1\",\"id\":163304,\"node_id\":\"MDQ6VXNlcjE2NTY0NQ==\",\"avatar_url\":\"https://avatars3.githubusercontent.com/u/163304?v=4\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/login1\",\"html_url\":\"https://github.com/login1\",\"followers_url\":\"https://api.github.com/users/login1/followers\",\"following_url\":\"https://api.github.com/users/login1/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/login1/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/login1/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/login1/subscriptions\",\"organizations_url\":\"https://api.github.com/users/login1/orgs\",\"repos_url\":\"https://api.github.com/users/login1/repos\",\"events_url\":\"https://api.github.com/users/login1/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/login1/received_events\",\"type\":\"User\",\"site_admin\":false},{\"login\":\"login2\",\"id\":1013335,\"node_id\":\"MDQ6VXNlcjEwMTU1Nzc=\",\"avatar_url\":\"https://avatars3.githubusercontent.com/u/1013335?v=4\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/login2\",\"html_url\":\"https://github.com/login2\",\"followers_url\":\"https://api.github.com/users/login2/followers\",\"following_url\":\"https://api.github.com/users/login2/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/login2/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/login2/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/login2/subscriptions\",\"organizations_url\":\"https://api.github.com/users/login2/orgs\",\"repos_url\":\"https://api.github.com/users/login2/repos\",\"events_url\":\"https://api.github.com/users/login2/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/login2/received_events\",\"type\":\"User\",\"site_admin\":false}]",
"headers": {
"Date": "Tue, 02 Jun 2020 09:53:27 GMT",
"Content-Type": "application/json; charset=utf-8",
"Content-Length": "1777",
"Server": "GitHub.com",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4999",
"X-RateLimit-Reset": "1591095207",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
"ETag": "\"68d356810a8286d10d8137b3a721eb27\"",
"X-OAuth-Scopes": "admin:repo_hook",
"X-Accepted-OAuth-Scopes": "",
"X-GitHub-Media-Type": "github.v3; format=json",
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset",
"Access-Control-Allow-Origin": "*",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "BDBF:33B7A:8196FCC:99E29CA:5ED62197"
},
"status_code": 200,
"type": "ok"
}
}
]
12 changes: 12 additions & 0 deletions test/starring_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ defmodule Tentacat.Users.StarringTest do
HTTPoison.start()
end

test "stargazers/3" do
use_cassette "starring#stargazers_success" do
assert [%{"login" => "login1"}, %{"login" => "login2"}] =
elem(stargazers(@client, "elixir-lang", "elixir"), 1)
end

use_cassette "starring#stargazers_failed" do
{status_code, _, _} = stargazers(@bad_client, "elixir-lang", "elixir")
assert status_code == 401
end
end

test "starred?/3" do
use_cassette "starring#starred_/1" do
assert elem(starred?(@client, "elixir-lang", "elixir"), 1) == true
Expand Down

0 comments on commit 54d29d1

Please sign in to comment.