Skip to content

Commit

Permalink
add test/app/org_test.exs for #13
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Jun 8, 2024
1 parent 614bfa3 commit e51f32e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 15 deletions.
3 changes: 2 additions & 1 deletion lib/app/github.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ defmodule App.GitHub do
"""
def repository(owner, reponame) do
Logger.info "Fetching repository #{owner}/#{reponame}"
{_status, data, _res} = Tentacat.Repositories.repo_get(@client, owner, reponame)
{_status, data, _res} =
Tentacat.Repositories.repo_get(@client, owner, reponame)
data |> Useful.atomize_map_keys()
end

Expand Down
21 changes: 16 additions & 5 deletions lib/app/org.ex
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
defmodule App.Org do
alias App.{Repo}
use Ecto.Schema
import Ecto.Changeset
require Logger
alias __MODULE__

schema "orgs" do
field :name, :string
field :avatar_url, :string
field :blog, :string
field :company, :string
field :description, :string
field :followers, :integer
field :location, :string
field :login, :string
field :avatar_url, :string
field :company, :string
field :name, :string
field :public_repos, :integer
field :followers, :integer

timestamps()
end
Expand All @@ -22,5 +26,12 @@ defmodule App.Org do
|> validate_required([:login, :avatar_url, :name, :company, :public_repos, :description, :followers])
end


@doc """
Creates an `org`.
"""
def create(attrs) do
%Org{}
|> changeset(attrs)
|> Repo.insert()
end
end
2 changes: 0 additions & 2 deletions lib/app/repository.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,4 @@ defmodule App.Repository do
|> Repo.insert()
end



end
2 changes: 1 addition & 1 deletion priv/repo/migrations/20221005213110_create_users.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ defmodule App.Repo.Migrations.CreateUsers do

def change do
create table(:users) do
add :login, :string
add :avatar_url, :string
add :login, :string
add :name, :string
add :company, :string
add :bio, :string
Expand Down
10 changes: 6 additions & 4 deletions priv/repo/migrations/20240608112859_create_orgs.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ defmodule App.Repo.Migrations.CreateOrgs do

def change do
create table(:orgs) do
add :login, :string
add :avatar_url, :string
add :name, :string
add :blog, :string
add :company, :string
add :public_repos, :integer
add :location, :string
add :created_at, :string
add :description, :string
add :followers, :integer
add :location, :string
add :login, :string
add :name, :string
add :public_repos, :integer

timestamps()
end
Expand Down
4 changes: 2 additions & 2 deletions test/app/github_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule App.GitHubTest do
owner = "dwyl"
reponame = "start-here"

GitHub.repository(owner, reponame) |> IO.inspect
GitHub.repository(owner, reponame) # |> IO.inspect
# assert html_response(conn, 200) =~ "LiveView App Page"
end

Expand All @@ -15,4 +15,4 @@ defmodule App.GitHubTest do
GitHub.user(user) # |> IO.inspect
# assert html_response(conn, 200) =~ "LiveView App Page"
end
end
end
20 changes: 20 additions & 0 deletions test/app/org_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
defmodule App.OrgTest do
use App.DataCase

test "App.Org.create/1" do
org = %{
avatar_url: "https://avatars.githubusercontent.com/u/4185328?v=4",
blog: "https://blog.dwyl.com",
company: "@dwyl",
created_at: "2013-04-17T21:10:06Z",
description: "the dwyl org",
followers: 378,
location: "London, UK",
login: "dwyl",
name: "dwyl",
public_repos: 31
}
assert {:ok, inserted_org} = App.Org.create(org)
assert inserted_org.name == org.name
end
end

0 comments on commit e51f32e

Please sign in to comment.