Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
267 additions
and
49 deletions.
There are no files selected for viewing
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
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
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
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
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,14 @@ | ||
defmodule Comment.BodyReader do | ||
@moduledoc """ | ||
Used for store a raw copy of the request body before be | ||
processed by Plug.Parsers to be used in the signature verification. | ||
""" | ||
alias Plug.Conn | ||
|
||
@spec read_body(Conn.t(), Keyword.t()) :: {:ok, binary, Conn.t()} | {:error, Conn.term()} | ||
def read_body(%Conn{} = conn, opts) do | ||
{:ok, body, conn} = Conn.read_body(conn, opts) | ||
conn = update_in(conn.assigns[:raw_body], &[body | &1 || []]) | ||
{:ok, body, conn} | ||
end | ||
end |
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
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
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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,20 +1,17 @@ | ||
defmodule Comment.Models.InstallationTest do | ||
use Comment.RepoCase | ||
import Comment.Factory | ||
alias Comment.Installation | ||
|
||
@invalid_attributes %{installation_id: "NaN", account_id: "not a number"} | ||
@valid_attributes %{ | ||
installation_id: 984, | ||
account_login: "random_user", | ||
account_id: 6535, | ||
account_type: "User" | ||
} | ||
|
||
test "a valid installation" do | ||
assert {:ok, %Installation{}} = Installation.create(@valid_attributes) | ||
assert {:ok, %Installation{}} = | ||
params_for(:installation) | ||
|> Installation.create([]) | ||
end | ||
|
||
test "an invalid installation" do | ||
assert {:error, %Ecto.Changeset{}} = Installation.create(@invalid_attributes) | ||
assert {:error, %Ecto.Changeset{}} = | ||
params_for(:installation, installation_id: nil) | ||
|> Installation.create([]) | ||
end | ||
end |
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,23 @@ | ||
defmodule Comment.Models.RepositoryTest do | ||
use Comment.RepoCase | ||
import Comment.Factory | ||
alias Comment.Repository | ||
|
||
test "a valid installation with repositories" do | ||
installation = insert(:installation) | ||
|
||
repo = params_for(:repository, installation_id: installation.id) | ||
|
||
{:ok, repository} = | ||
repo | ||
|> Repository.create() | ||
|
||
assert %Repository{} = repository | ||
end | ||
|
||
test "invalid repositories" do | ||
assert {:error, %Ecto.Changeset{}} = | ||
params_for(:repository, name: nil) | ||
|> Repository.create() | ||
end | ||
end |
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,25 @@ | ||
defmodule Comment.ServerTest do | ||
use ExUnit.Case, async: true | ||
use Comment.RepoCase | ||
use Plug.Test | ||
|
||
alias Comment.{Server} | ||
|
||
@opts Server.init([]) | ||
|
||
test "Github webhook installation create" do | ||
body = File.read!("test/fixtures/webhook/github.installation.create.json") | ||
params = Jason.decode!(body) | ||
|
||
conn = | ||
conn(:post, "/webhook/github", params) | ||
|> put_req_header("x-hub-signature", "sha1=0b586799339e68bacb2f3bfd51e1b341ef04aa36") | ||
|> put_req_header("x-github-event", "installation") | ||
|> Plug.Conn.assign(:raw_body, body) | ||
|
||
conn = Server.call(conn, @opts) | ||
|
||
assert conn.state == :sent | ||
assert conn.status == 200 | ||
end | ||
end |
Oops, something went wrong.