Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MICHAELMUNAVU83 committed Jan 23, 2024
1 parent 5fe58c2 commit 8b39985
Show file tree
Hide file tree
Showing 36 changed files with 876 additions and 378 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ config :elixir_conf_africa, ElixirConfAfrica.Repo,
config :elixir_conf_africa, ElixirConfAfricaWeb.Endpoint,
# Binding to loopback ipv4 address prevents access from other machines.
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
http: [ip: {127, 0, 0, 1}, port: 4100],
http: [ip: {127, 0, 0, 1}, port: 4000],
check_origin: false,
code_reloader: true,
debug_errors: true,
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_conf_africa/accounts/user.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirConfAfrica.Accounts.User do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset

Expand Down
1 change: 1 addition & 0 deletions lib/elixir_conf_africa/accounts/user_notifier.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirConfAfrica.Accounts.UserNotifier do
@moduledoc false
import Swoosh.Email

alias ElixirConfAfrica.Mailer
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_conf_africa/accounts/user_token.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirConfAfrica.Accounts.UserToken do
@moduledoc false
use Ecto.Schema
import Ecto.Query
alias ElixirConfAfrica.Accounts.UserToken
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_conf_africa/ticket_types/ticket_type.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirConfAfrica.TicketTypes.TicketType do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset

Expand Down
1 change: 1 addition & 0 deletions lib/elixir_conf_africa/tickets/ticket.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirConfAfrica.Tickets.Ticket do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset

Expand Down
4 changes: 2 additions & 2 deletions lib/elixir_conf_africa_web/live/event_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<p class="poppins-bold text-xl">KSH <%= ticket_type.price %></p>
<div class="flex gap-3 poppins-regular items-center">
<.link
navigate={~p"/event/#{ticket_type.id}/buy"}
id="buy-#{ticket_type.id}-tickets"
patch={~p"/event/#{ticket_type.id}/buy"}
id={"buy-#{ticket_type.id}-tickets"}
>
<button class="p-4 border-[1px] w-[87px] text-xs h-[34px] bg-[#AD3989] text-white gap-2 flex items-center justify-center rounded-[4px]">
Get
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir_conf_africa_web/live/home_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="flex gap-4 items-center">
<.link navigate={~p"/event"}>
<button class="text-white bg-[#AD3989] border-[1px] w-[130px] text-sm hover:scale-105 transition-all ease-in-out h-[34px] flex gap-2 items-center justify-center rounded-[4px]">
<p>Buy Ticket</p>
<p>Buy Tickets</p>
</button>
</.link>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div>
<.simple_form
for={@form}
id="event-form"
id="ticket-form"
phx-target={@myself}
phx-change="validate"
phx-submit="save"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule ElixirConfAfricaWeb.TicketTypeLive.FormComponent do
{:noreply,
socket
|> put_flash(:info, "Ticket type updated successfully")
|> push_patch(to: socket.assigns.patch)}
|> push_redirect(to: socket.assigns.patch)}

{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, :changeset, changeset)}
Expand All @@ -46,7 +46,7 @@ defmodule ElixirConfAfricaWeb.TicketTypeLive.FormComponent do
{:noreply,
socket
|> put_flash(:info, "Ticket type created successfully")
|> push_patch(to: socket.assigns.patch)}
|> push_redirect(to: socket.assigns.patch)}

{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Listing Ticket types
<:actions>
<.link patch={~p"/ticket_types/new"}>
<.button>New Ticket type</.button>
<.button>New Ticket Type</.button>
</.link>
</:actions>
</.header>
Expand Down Expand Up @@ -43,7 +43,12 @@

<td>
<div class="flex justify-center items-center gap-2">
<.link patch={~p"/ticket_types/#{ticket_type}/edit"}>Edit</.link>
<.link
id={"ticket_types-#{ticket_type.id}"}
patch={~p"/ticket_types/#{ticket_type}/edit"}
>
Edit
</.link>

<span>
<.link
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_conf_africa_web/user_auth.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirConfAfricaWeb.UserAuth do
@moduledoc false
use ElixirConfAfricaWeb, :verified_routes

import Plug.Conn
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ defmodule ElixirConfAfrica.MixProject do
{:typed_ecto_schema, "~> 0.4.1"},
{:ex_machina, "~> 2.7.0"},
{:httpoison, "~> 2.1"},
{:styler, "~> 0.11", only: [:dev, :test], runtime: false},
{:styler, "~> 0.11", only: [:dev, :test], runtime: false}
]
end

Expand Down
Binary file added test/.DS_Store
Binary file not shown.
48 changes: 34 additions & 14 deletions test/elixir_conf_africa/accounts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ defmodule ElixirConfAfrica.AccountsTest do
end

test "validates email and password when given" do
{:error, changeset} = Accounts.register_user(%{email: "not valid", password: "not valid"})
{:error, changeset} = Accounts.register_user(%{email: "not valid", password: "poor"})

assert %{
email: ["must have the @ sign and no spaces"],
password: ["should be at least 12 character(s)"]
password: ["should be at least 6 character(s)"]
} = errors_on(changeset)
end

Expand Down Expand Up @@ -152,9 +152,9 @@ defmodule ElixirConfAfrica.AccountsTest do

test "validates email uniqueness", %{user: user} do
%{email: email} = user_fixture()
password = valid_user_password()

{:error, changeset} = Accounts.apply_user_email(user, password, %{email: email})
{:error, changeset} =
Accounts.apply_user_email(user, valid_user_password(), %{email: email})

assert "has already been taken" in errors_on(changeset).email
end
Expand All @@ -174,15 +174,15 @@ defmodule ElixirConfAfrica.AccountsTest do
end
end

describe "deliver_user_update_email_instructions/3" do
describe "deliver_update_email_instructions/3" do
setup do
%{user: user_fixture()}
end

test "sends token through notification", %{user: user} do
token =
extract_user_token(fn url ->
Accounts.deliver_user_update_email_instructions(user, "current@example.com", url)
Accounts.deliver_update_email_instructions(user, "current@example.com", url)
end)

{:ok, token} = Base.url_decode64(token, padding: false)
Expand All @@ -200,7 +200,7 @@ defmodule ElixirConfAfrica.AccountsTest do

token =
extract_user_token(fn url ->
Accounts.deliver_user_update_email_instructions(%{user | email: email}, user.email, url)
Accounts.deliver_update_email_instructions(%{user | email: email}, user.email, url)
end)

%{user: user, token: token, email: email}
Expand Down Expand Up @@ -262,12 +262,12 @@ defmodule ElixirConfAfrica.AccountsTest do
test "validates password", %{user: user} do
{:error, changeset} =
Accounts.update_user_password(user, valid_user_password(), %{
password: "not valid",
password: "poor",
password_confirmation: "another"
})

assert %{
password: ["should be at least 12 character(s)"],
password: ["should be at least 6 character(s)"],
password_confirmation: ["does not match password"]
} = errors_on(changeset)
end
Expand Down Expand Up @@ -353,11 +353,11 @@ defmodule ElixirConfAfrica.AccountsTest do
end
end

describe "delete_user_session_token/1" do
describe "delete_session_token/1" do
test "deletes the token" do
user = user_fixture()
token = Accounts.generate_user_session_token(user)
assert Accounts.delete_user_session_token(token) == :ok
assert Accounts.delete_session_token(token) == :ok
refute Accounts.get_user_by_session_token(token)
end
end
Expand Down Expand Up @@ -471,12 +471,12 @@ defmodule ElixirConfAfrica.AccountsTest do
test "validates password", %{user: user} do
{:error, changeset} =
Accounts.reset_user_password(user, %{
password: "not valid",
password: "poor",
password_confirmation: "another"
})

assert %{
password: ["should be at least 12 character(s)"],
password: ["should be at least 6 character(s)"],
password_confirmation: ["does not match password"]
} = errors_on(changeset)
end
Expand All @@ -500,7 +500,27 @@ defmodule ElixirConfAfrica.AccountsTest do
end
end

describe "inspect/2 for the User module" do
describe "update a user role/2" do
setup do
%{user: user_fixture()}
end

test "you can update a user's role" do
{:ok, user} = Accounts.register_user(valid_user_attributes())
assert user.role == "user"
{:ok, user} = Accounts.update_user_role(user, "admin")
assert user.role == "admin"
end

test "you can only give the roles 'user' , 'admin' or 'scanner'" do
{:ok, user} = Accounts.register_user(valid_user_attributes())
assert user.role == "user"
{:error, _} = Accounts.update_user_role(user, "not a role")
assert user.role == "user"
end
end

describe "inspect/2" do
test "does not include password" do
refute inspect(%User{password: "123456"}) =~ "password: \"123456\""
end
Expand Down
110 changes: 0 additions & 110 deletions test/elixir_conf_africa/events_test.exs

This file was deleted.

Loading

0 comments on commit 8b39985

Please sign in to comment.