-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Fixing test and adding UsersTable test. #1
- Loading branch information
1 parent
c75aa24
commit 584a317
Showing
9 changed files
with
110 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,3 +74,4 @@ npm-debug.log | |
# Env files | ||
.env | ||
cache.dets | ||
cache_test.dets |
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 @@ | ||
{ | ||
"coverage_options": { | ||
"minimum_coverage": 100 | ||
}, | ||
"skip_files": [ | ||
"test/", | ||
"lib/app/application.ex", | ||
"lib/app/release.ex", | ||
"lib/app_web.ex", | ||
"lib/app_web/gettext.ex", | ||
"lib/app_web/components/", | ||
"lib/app_web/telemetry.ex" | ||
] | ||
} |
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,25 @@ | ||
defmodule App.UsersTest do | ||
|
||
use ExUnit.Case | ||
|
||
# "Cache_test.dets" has one user | ||
|
||
setup_all do | ||
UsersTable.init() | ||
UsersTable.create_user(%{stripe_id: 1, person_id: 1, status: true}) | ||
UsersTable.create_user(%{stripe_id: 2, person_id: 2, status: false}) | ||
|
||
:ok | ||
end | ||
|
||
test "fetch user of person_id 1" do | ||
user = UsersTable.fetch_user(1) | ||
assert Map.get(user, :stripe_id) == 1 | ||
end | ||
|
||
test "create user of person_id 3" do | ||
UsersTable.create_user(%{stripe_id: 3, person_id: 3, status: true}) | ||
user = UsersTable.fetch_user(3) | ||
assert Map.get(user, :stripe_id) == 3 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
defmodule App.DataCase do | ||
@moduledoc """ | ||
This module defines the setup for tests requiring | ||
access to the application's data layer. | ||
You may define functions here to be used as helpers in | ||
your tests. | ||
Finally, if the test case interacts with the database, | ||
we enable the SQL sandbox, so changes done to the database | ||
are reverted at the end of every test. If you are using | ||
PostgreSQL, you can even run database tests asynchronously | ||
by setting `use App.DataCase, async: true`, although | ||
this option is not recommended for other databases. | ||
""" | ||
|
||
use ExUnit.CaseTemplate | ||
|
||
using do | ||
quote do | ||
import Ecto | ||
end | ||
end | ||
|
||
setup tags do | ||
App.DataCase.setup_sandbox(tags) | ||
:ok | ||
end | ||
|
||
@doc """ | ||
Sets up the sandbox based on the test tags. | ||
""" | ||
def setup_sandbox(tags) do | ||
end | ||
|
||
@doc """ | ||
A helper that transforms changeset errors into a map of messages. | ||
assert {:error, changeset} = Accounts.create_user(%{password: "short"}) | ||
assert "password is too short" in errors_on(changeset).password | ||
assert %{password: ["password is too short"]} = errors_on(changeset) | ||
""" | ||
def errors_on(changeset) do | ||
end | ||
end |