defmodule MyApp.SubmapUsageTest do use MyApp.ConnCase import MapHelpers, only: [deep_submap?: 2] test "API response match test", %{conn: conn, user: user} do conn = conn |> get("/users/#{user.id}") # response = %{ # "id": "1772493858641", # "name": "alice", # "profile": %{ # "icon" => "http://avatar.example.com/users/1772493858641", # "description" => "...(long description)" # } # } assert response = json_response(conn, :ok) # Write a helper function that returns an exmaple response, and # we can check the response matches an example with `deep_submap?/2`. assert deep_submap?(user_response(user), response) end defp user_response(user) do # We don't want to check `profile.description`, so omit the field. %{ "id": to_string(user.id), "name": user.name, "profile" => %{ "icon" => "http://avatar.example.com/users/#{user.id}" } } end end