From 90bd161afe3fab2a1ffbdc7f79162fcbac9cd006 Mon Sep 17 00:00:00 2001 From: SimonLab Date: Tue, 21 Apr 2020 14:59:12 +0100 Subject: [PATCH] add timer tests, #14 --- lib/app_api/timers.ex | 13 ------------ test/app_api/timers_test.exs | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 test/app_api/timers_test.exs diff --git a/lib/app_api/timers.ex b/lib/app_api/timers.ex index ae118f5..1eee9c3 100644 --- a/lib/app_api/timers.ex +++ b/lib/app_api/timers.ex @@ -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. diff --git a/test/app_api/timers_test.exs b/test/app_api/timers_test.exs new file mode 100644 index 0000000..fe5c2fe --- /dev/null +++ b/test/app_api/timers_test.exs @@ -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