Skip to content

Commit

Permalink
Add user test
Browse files Browse the repository at this point in the history
  • Loading branch information
nmenag committed Nov 26, 2023
1 parent 2a7473b commit e1e5699
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ jobs:
run: mix ecto.migrate
- name: Run coverage
run: |
MIX_ENV=test mix coveralls --no-start --trace
MIX_ENV=test mix coveralls
services:
pg:
image: postgres:16
Expand Down
13 changes: 0 additions & 13 deletions apps/core/lib/core.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,4 @@ defmodule Core do
@moduledoc """
Documentation for `Core`.
"""

@doc """
Hello world.
## Examples
iex> Core.hello()
:world
"""
def hello do
:world
end
end
1 change: 0 additions & 1 deletion apps/core/lib/core/schema/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ defmodule GoEscuelaLms.Core.Schema.User do
|> cast(attrs, [:full_name, :email, :birth_date, :role, :password_hash])
|> validate_required([:full_name, :password_hash])
|> validate_format(:email, ~r/^[^\s]+@[^\s]+$/, message: "must have the @ sign and no spaces")
|> validate_length(:email, max: 160)
|> put_password_hash()
end

Expand Down
3 changes: 1 addition & 2 deletions apps/core/test/core/schema/course_test.exs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
defmodule Core.CourseTest do
use ExUnit.Case
use Core.DataCase

alias GoEscuelaLms.Core.Schema.Course

describe "courses" do
@valid_attrs %{name: "Course I", description: "lorem ipsum", enabled: true}
@invalid_attrs %{name: nil, description: nil}

test "create_course/1 with valid data creates a user" do
test "create/1 with valid data creates a course" do
assert {:ok, %Course{} = course} = Course.create(@valid_attrs)
assert course.name == "Course I"
assert course.description == "lorem ipsum"
Expand Down
31 changes: 31 additions & 0 deletions apps/core/test/core/schema/user_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
defmodule Core.UserTest do
use ExUnit.Case

alias GoEscuelaLms.Core.Schema.User

describe "users" do
@valid_attrs %{
full_name: "Jhon doe",
email: "[email protected]",
password_hash: "pass123",
role: "student"
}
@invalid_attrs %{}

test "create/1 with valid data creates a user" do
assert {:ok, %User{} = user} = User.create(@valid_attrs)
assert user.full_name == "Jhon doe"
assert user.email == "[email protected]"
end

test "create_user/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = User.create(@invalid_attrs)
end

test "email must be valid" do
attrs = %{@valid_attrs | email: "example"}
changeset = User.changeset(%User{}, attrs)
refute changeset.valid?
end
end
end
4 changes: 0 additions & 4 deletions apps/core/test/core_test.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
defmodule CoreTest do
use ExUnit.Case
doctest Core

test "greets the world" do
assert Core.hello() == :world
end
end
46 changes: 0 additions & 46 deletions apps/core/test/support/data_case.ex

This file was deleted.

0 comments on commit e1e5699

Please sign in to comment.