Skip to content

Commit f9f26b2

Browse files
committed
Add E2E tests to verify we can get and put data to and from repositories
1 parent 449f875 commit f9f26b2

File tree

4 files changed

+78
-2
lines changed

4 files changed

+78
-2
lines changed

.github/workflows/examples.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,34 @@ jobs:
103103
id: script
104104
with:
105105
script: |
106-
{200, user, _resp} = Tentacat.Users.find(client, "gaggle")
106+
{200, user, _} = Tentacat.Users.find(client, "gaggle")
107107
user["login"]
108108
109109
- name: Get result
110110
run: echo "${{steps.script.outputs.result}}"
111+
112+
can-grab-information-via-the-github-api:
113+
runs-on: ubuntu-latest
114+
steps:
115+
- uses: gaggle/elixir_script@v0
116+
id: script
117+
with:
118+
script: |
119+
{200, stargazers, _} = Tentacat.Users.Starring.stargazers(client, "gaggle", "elixir_script")
120+
IO.inspect(Enum.map_join(stargazers, ", ", & &1["login"]), label: "Stargazers")
121+
122+
- name: Get result
123+
run: echo "${{steps.script.outputs.result}}"
124+
125+
can-interact-with-repositories-via-github-api:
126+
runs-on: ubuntu-latest
127+
steps:
128+
- uses: gaggle/elixir_script@v0
129+
id: script
130+
with:
131+
script: |
132+
{204, _, _} = Tentacat.Users.Starring.star(client, "gaggle", "elixir_script")
133+
:ok
134+
135+
- name: Get result
136+
run: echo "${{steps.script.outputs.result}}"

test/e2e_data.exs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,23 @@
4848
%{
4949
name: "Can use the GitHub API via Tentacat",
5050
script: """
51-
{200, user, _resp} = Tentacat.Users.find(client, "gaggle")
51+
{200, user, _} = Tentacat.Users.find(client, "gaggle")
5252
user["login"]
5353
""",
5454
expected: "gaggle"
55+
},
56+
%{
57+
name: "Can grab information via the GitHub API",
58+
script: """
59+
{200, stargazers, _} = Tentacat.Users.Starring.stargazers(client, "gaggle", "elixir_script")
60+
IO.inspect(Enum.map_join(stargazers, ", ", & &1["login"]), label: "Stargazers")
61+
"""
62+
},
63+
%{
64+
name: "Can interact with repositories via GitHub API",
65+
script: """
66+
{204, _, _} = Tentacat.Users.Starring.star(client, "gaggle", "elixir_script")
67+
:ok
68+
"""
5569
}
5670
]

test/e2e_test.exs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ defmodule ElixirScript.E2eTest.EndToEndTest do
9494
Plug.Conn.resp(conn, 200, File.read!(fixture_path))
9595
end)
9696

97+
Bypass.expect(bypass, "GET", "/repos/gaggle/elixir_script/stargazers", fn conn ->
98+
fixture_path =
99+
Path.join(
100+
__DIR__,
101+
"fixtures/api.github.com/repos/gaggle/elixir_script/stargazers/GET.200.json"
102+
)
103+
104+
Plug.Conn.resp(conn, 200, File.read!(fixture_path))
105+
end)
106+
107+
Bypass.expect(bypass, "PUT", "/user/starred/gaggle/elixir_script", fn conn ->
108+
Plug.Conn.resp(conn, 204, "")
109+
end)
110+
97111
stub(TentacatMock.ClientMock, :new, fn ->
98112
Tentacat.Client.new("http://localhost:#{bypass.port}")
99113
end)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"login": "octocat",
4+
"id": 1,
5+
"node_id": "MDQ6VXNlcjE=",
6+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
7+
"gravatar_id": "",
8+
"url": "https://api.github.com/users/octocat",
9+
"html_url": "https://github.com/octocat",
10+
"followers_url": "https://api.github.com/users/octocat/followers",
11+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
12+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
13+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
14+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
15+
"organizations_url": "https://api.github.com/users/octocat/orgs",
16+
"repos_url": "https://api.github.com/users/octocat/repos",
17+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
18+
"received_events_url": "https://api.github.com/users/octocat/received_events",
19+
"type": "User",
20+
"site_admin": false
21+
}
22+
]

0 commit comments

Comments
 (0)