Skip to content

Commit 79a65ff

Browse files
committed
Attempt to test Sentry calls
1 parent 1a5bdaf commit 79a65ff

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

test/lib/code_corps/github/webhook/handler_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ defmodule CodeCorps.GitHub.Webhook.HandlerTest do
44
use CodeCorps.DbAccessCase
55

66
import CodeCorps.GitHub.TestHelpers
7+
import CodeCorps.TestEnvironmentHelper
78

89
alias CodeCorps.{
910
GithubEvent,
@@ -260,6 +261,18 @@ defmodule CodeCorps.GitHub.Webhook.HandlerTest do
260261
changeset = Task.update_changeset(task, %{title: "New title", updated_from: "codecorps"})
261262
Repo.update!(changeset)
262263

264+
bypass = Bypass.open
265+
Bypass.expect bypass, fn conn ->
266+
{:ok, body, conn} = Plug.Conn.read_body(conn)
267+
assert body =~ "RuntimeError"
268+
assert body =~ "ExampleApp"
269+
assert conn.request_path == "/api/1/store/"
270+
assert conn.method == "POST"
271+
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
272+
end
273+
274+
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
275+
263276
{:ok, %GithubEvent{} = event} = Handler.handle_supported("issues", "abc-456", edited_payload)
264277

265278
assert event.action == "edited"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
defmodule CodeCorps.TestEnvironmentHelper do
2+
def modify_env(app, overrides) do
3+
original_env = Application.get_all_env(app)
4+
Enum.each(overrides, fn {key, value} -> Application.put_env(app, key, value) end)
5+
6+
ExUnit.Callbacks.on_exit(fn ->
7+
Enum.each overrides, fn {key, _} ->
8+
if Keyword.has_key?(original_env, key) do
9+
Application.put_env(app, key, Keyword.fetch!(original_env, key))
10+
else
11+
Application.delete_env(app, key)
12+
end
13+
end
14+
end)
15+
end
16+
end

0 commit comments

Comments
 (0)