Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for extra event functions #35

Merged
merged 27 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a05a90f
Added tests for extra event functions
MICHAELMUNAVU83 Oct 26, 2023
945f0d2
added formatting to files
MICHAELMUNAVU83 Oct 26, 2023
efe5121
Used test libraries
MICHAELMUNAVU83 Oct 30, 2023
aade95b
Fixed spec error
MICHAELMUNAVU83 Oct 30, 2023
e39bc06
Fixed get elixir conf function
MICHAELMUNAVU83 Oct 30, 2023
4739798
Added factories
MICHAELMUNAVU83 Oct 30, 2023
e5a2187
Added factories
MICHAELMUNAVU83 Oct 30, 2023
e27e8ad
Added module doc false
MICHAELMUNAVU83 Oct 30, 2023
4f0007e
Renamed get all available tickets and removed dead code
MICHAELMUNAVU83 Oct 31, 2023
67ddc23
Added tests for extra event functions
MICHAELMUNAVU83 Oct 26, 2023
aced203
added formatting to files
MICHAELMUNAVU83 Oct 26, 2023
5288196
Used test libraries
MICHAELMUNAVU83 Oct 30, 2023
e04dd7c
Fixed spec error
MICHAELMUNAVU83 Oct 30, 2023
951f074
Fixed get elixir conf function
MICHAELMUNAVU83 Oct 30, 2023
a5032a4
Added factories
MICHAELMUNAVU83 Oct 30, 2023
15531cd
Added factories
MICHAELMUNAVU83 Oct 30, 2023
4977205
Added module doc false
MICHAELMUNAVU83 Oct 30, 2023
8d9f09b
Renamed get all available tickets and removed dead code
MICHAELMUNAVU83 Oct 31, 2023
be7f141
refactor:
okothkongo Nov 14, 2023
1c1b516
fix lints
okothkongo Nov 14, 2023
e2a55e0
Merge branch 'testing-event-functions' of https://github.com/beamkeny…
MICHAELMUNAVU83 Nov 14, 2023
6daa68e
fixed linters errors
MICHAELMUNAVU83 Nov 14, 2023
4dfbf7c
Removed static id of 1 from event map
MICHAELMUNAVU83 Nov 14, 2023
eb4ea01
refactor:
okothkongo Nov 14, 2023
be0b057
ensure correct specs
okothkongo Nov 15, 2023
1df6440
add removed func
okothkongo Nov 15, 2023
207c6a6
be more stricter
okothkongo Nov 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/elixir_conf_africa/events.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ defmodule ElixirConfAfrica.Events do
|> Repo.preload(:ticket_types)
end

defp get_elixir_conf_event do
@spec get_elixir_conf_event() :: any()
MICHAELMUNAVU83 marked this conversation as resolved.
Show resolved Hide resolved
def get_elixir_conf_event do
Repo.get_by(Event, name: "ElixirConf Africa 2024")
end

Expand All @@ -41,6 +42,7 @@ defmodule ElixirConfAfrica.Events do
Repo.one(query)
end

@spec get_event!(any()) :: any()
@doc """
Gets a single event.

Expand Down
66 changes: 66 additions & 0 deletions test/elixir_conf_africa/events_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
use ElixirConfAfrica.DataCase

alias ElixirConfAfrica.Events
alias ElixirConfAfrica.TicketTypes.TicketType
alias ElixirConfAfrica.TicketTypes

describe "events" do
alias ElixirConfAfrica.Events.Event
Expand All @@ -22,11 +24,75 @@
assert Events.list_events() == [event]
end

test "get_elixir_conf_event /0 returns the elixir conf event" do
valid_attrs = %{
name: "ElixirConf Africa 2024",
description: "some description",
location: "some location",
event_type: "some event_type",
start_date: ~N[2023-10-05 06:18:00],
end_date: ~N[2023-10-05 06:18:00]
}

assert {:ok, %Event{} = event} = Events.create_event(valid_attrs)
assert Events.get_elixir_conf_event() == event
end

test "get_event!/1 returns the event with given id" do
event = event_fixture()
assert Events.get_event!(event.id) == event
end

test "get_elixir_conf_event_and_ticket_types/0 returns the elixir conf event with ticket types" do
valid_attrs = %{
name: "ElixirConf Africa 2024",
description: "some description",
location: "some location",
event_type: "some event_type",
start_date: ~N[2023-10-05 06:18:00],
end_date: ~N[2023-10-05 06:18:00]
}

assert {:ok, %Event{} = event} = Events.create_event(valid_attrs)
MICHAELMUNAVU83 marked this conversation as resolved.
Show resolved Hide resolved
assert Events.get_elixir_conf_event() == event

ticket_type_attr = %{
event_id: event.id,
name: "some name",
description: "some description",
price: "120.5",
number: "357"
}

assert {:ok, %TicketType{} = ticket_type} = TicketTypes.create_ticket_type(ticket_type_attr)
assert Events.get_elixir_conf_event_and_ticket_types().ticket_types == [ticket_type]
end

test "get_all_available_tickets/0 returns the number of available tickets" do
valid_attrs = %{
name: "ElixirConf Africa 2024",
description: "some description",
location: "some location",
event_type: "some event_type",
start_date: ~N[2023-10-05 06:18:00],
end_date: ~N[2023-10-05 06:18:00]
}

assert {:ok, %Event{} = event} = Events.create_event(valid_attrs)
assert Events.get_elixir_conf_event() == event

ticket_type_attr = %{
event_id: event.id,
name: "some name",
description: "some description",
price: "120.5",
number: "357"
}

assert {:ok, %TicketType{} = ticket_type} = TicketTypes.create_ticket_type(ticket_type_attr)

Check warning on line 92 in test/elixir_conf_africa/events_test.exs

View workflow job for this annotation

GitHub Actions / Test

variable "ticket_type" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 92 in test/elixir_conf_africa/events_test.exs

View workflow job for this annotation

GitHub Actions / Test

variable "ticket_type" is unused (if the variable is not meant to be used, prefix it with an underscore)
assert Events.get_all_available_tickets() == 357
end

test "create_event/1 with valid data creates a event" do
valid_attrs = %{
name: "some name",
Expand Down
Loading