Skip to content

Commit

Permalink
Do not include deleted items in all()
Browse files Browse the repository at this point in the history
  • Loading branch information
nkezhaya committed Jun 15, 2019
1 parent 1a0d311 commit 471efff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/stripe_mock/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,15 @@ defmodule StripeMock.Repo do

@impl true
def handle_call({:all, schema}, _from, state) do
case Map.get(state, schema) do
schemas when is_map(schemas) -> {:reply, Map.values(schemas), state}
with schemas when is_map(schemas) <- Map.get(state, schema),
objects <- Map.values(schemas),
not_deleted <-
Enum.filter(objects, fn
%{deleted: true} -> false
_ -> true
end) do
{:reply, not_deleted, state}
else
_ -> {:reply, [], state}
end
end
Expand Down
18 changes: 18 additions & 0 deletions test/stripe_mock_web/controllers/source_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ defmodule StripeMockWeb.SourceControllerTest do

assert response["deleted"]
end

test "deleted cards no longer appear in index", %{conn: conn, card: card} do
%{"data" => data} =
conn
|> get(Routes.customer_source_path(conn, :index, card.customer_id, object: "card"))
|> json_response(200)

assert Enum.find(data, &(&1["id"] == card.id))

delete(conn, Routes.customer_source_path(conn, :delete, card.customer_id, card))

%{"data" => data} =
conn
|> get(Routes.customer_source_path(conn, :index, card.customer_id, object: "card"))
|> json_response(200)

refute Enum.find(data, &(&1["id"] == card.id))
end
end

defp create_card(%{conn: conn, customer: customer}) do
Expand Down

0 comments on commit 471efff

Please sign in to comment.