diff --git a/lib/stripe_mock/repo.ex b/lib/stripe_mock/repo.ex index 29b537f..32cf666 100644 --- a/lib/stripe_mock/repo.ex +++ b/lib/stripe_mock/repo.ex @@ -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 diff --git a/test/stripe_mock_web/controllers/source_controller_test.exs b/test/stripe_mock_web/controllers/source_controller_test.exs index 11c7496..731b5ed 100644 --- a/test/stripe_mock_web/controllers/source_controller_test.exs +++ b/test/stripe_mock_web/controllers/source_controller_test.exs @@ -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