elixir-todo-list/test/todo/cache_test.exs

37 lines
904 B
Elixir

defmodule Todo.TestCache do
use ExUnit.Case
alias Todo.Cache
alias Todo.Server
test "different names get different servers" do
{:ok, pid} = Cache.start()
{:ok, alice_server} = Cache.server_process(pid, "Alice")
{:ok, bob_server} = Cache.server_process(pid, "Bob")
assert alice_server != bob_server
end
test "same name gets same server" do
{:ok, pid} = Cache.start()
{:ok, alice_server} = Cache.server_process(pid, "Alice")
{:ok, alice_server2} = Cache.server_process(pid, "Alice")
assert alice_server == alice_server2
end
test "simple usage" do
{:ok, pid} = Cache.start()
{:ok, alice_server} = Cache.server_process(pid, "Alice")
Server.add(alice_server, %{date: ~D[2024-08-04], title: "Learn Elixir"})
assert [%{date: ~D[2024-08-04], title: "Learn Elixir"}] =
Server.entries(alice_server, ~D[2024-08-04])
end
end