Skip to content

Commit

Permalink
add timer tests, #14
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonLab committed Apr 21, 2020
1 parent f210730 commit 90bd161
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
13 changes: 0 additions & 13 deletions lib/app_api/timers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,6 @@ defmodule AppApi.Timers do

alias AppApi.Timers.Timer

@doc """
Returns the list of timers.
## Examples
iex> list_timers()
[%Timer{}, ...]
"""
def list_timers do
Repo.all(Timer)
end

@doc """
Gets a single timer.
Expand Down
40 changes: 40 additions & 0 deletions test/app_api/timers_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
defmodule AppApi.TimersTest do
use AppApi.DataCase

alias AppApi.Timers
alias AppApi.Captures
describe "tags" do
@valid_attrs_capture %{completed: true, id_person: 42, text: "some text", tags: "tag1, tag2"}
@valid_attrs %{started_at: DateTime.utc_now(), stopped_at: nil}

def capture_fixture(attrs \\ %{}) do
attrs
|> Enum.into(@valid_attrs_capture)
|> Captures.create_capture()
end

def timer_fixture(attrs \\ %{}) do
capture = capture_fixture()

timer_attrs = attrs
|> Enum.into(@valid_attrs)

{:ok, timer} = Timers.create_timer(capture, timer_attrs)
timer
end

test "stop timer" do
timer = timer_fixture()
assert is_nil(timer.stopped_at)
timer_updated = Timers.stop_timer(timer.id)
assert is_nil(timer_updated.stopped_at) == false
end

test "get capture' timers" do
capture = capture_fixture()
assert Timers.get_capture_timers(capture.id) == []
{:ok, timer} = Timers.create_timer(capture, @valid_attrs)
assert Enum.count(Timers.get_capture_timers(capture.id)) == 1
end
end
end

0 comments on commit 90bd161

Please sign in to comment.