From adaf9bb9eaeb3400674d8a2cdd5bc8b6d34573a3 Mon Sep 17 00:00:00 2001 From: rob Date: Wed, 7 Aug 2024 10:28:20 +0100 Subject: [PATCH] Use keys: :atoms when JSON decoding in tests --- .../storage_implementations_test.exs | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/packages/sync-service/test/electric/shape_cache/storage_implementations_test.exs b/packages/sync-service/test/electric/shape_cache/storage_implementations_test.exs index 094ff7f854..41952e8ec6 100644 --- a/packages/sync-service/test/electric/shape_cache/storage_implementations_test.exs +++ b/packages/sync-service/test/electric/shape_cache/storage_implementations_test.exs @@ -89,18 +89,18 @@ defmodule Electric.ShapeCache.StorageImplimentationsTest do assert [ %{ - "offset" => @snapshot_offset_encoded, - "value" => %{"id" => "00000000-0000-0000-0000-000000000001", "title" => "row1"}, - "key" => ~S|"public"."the-table"/"00000000-0000-0000-0000-000000000001"|, - "headers" => %{"action" => "insert"} + offset: @snapshot_offset_encoded, + value: %{id: "00000000-0000-0000-0000-000000000001", title: "row1"}, + key: ~S|"public"."the-table"/"00000000-0000-0000-0000-000000000001"|, + headers: %{action: "insert"} }, %{ - "offset" => @snapshot_offset_encoded, - "value" => %{"id" => "00000000-0000-0000-0000-000000000002", "title" => "row2"}, - "key" => ~S|"public"."the-table"/"00000000-0000-0000-0000-000000000002"|, - "headers" => %{"action" => "insert"} + offset: @snapshot_offset_encoded, + value: %{id: "00000000-0000-0000-0000-000000000002", title: "row2"}, + key: ~S|"public"."the-table"/"00000000-0000-0000-0000-000000000002"|, + headers: %{action: "insert"} } - ] = Enum.map(stream, &Jason.decode!/1) + ] = Enum.map(stream, &Jason.decode!(&1, keys: :atoms)) end test "does not leak results from other snapshots", %{module: storage, opts: opts} do @@ -123,18 +123,18 @@ defmodule Electric.ShapeCache.StorageImplimentationsTest do assert [ %{ - "offset" => @snapshot_offset_encoded, - "value" => %{"id" => "00000000-0000-0000-0000-000000000001", "title" => "row1"}, - "key" => ~S|"public"."the-table"/"00000000-0000-0000-0000-000000000001"|, - "headers" => %{"action" => "insert"} + offset: @snapshot_offset_encoded, + value: %{id: "00000000-0000-0000-0000-000000000001", title: "row1"}, + key: ~S|"public"."the-table"/"00000000-0000-0000-0000-000000000001"|, + headers: %{action: "insert"} }, %{ - "offset" => @snapshot_offset_encoded, - "value" => %{"id" => "00000000-0000-0000-0000-000000000002", "title" => "row2"}, - "key" => ~S|"public"."the-table"/"00000000-0000-0000-0000-000000000002"|, - "headers" => %{"action" => "insert"} + offset: @snapshot_offset_encoded, + value: %{id: "00000000-0000-0000-0000-000000000002", title: "row2"}, + key: ~S|"public"."the-table"/"00000000-0000-0000-0000-000000000002"|, + headers: %{action: "insert"} } - ] = Enum.map(stream, &Jason.decode!/1) + ] = Enum.map(stream, &Jason.decode!(&1, keys: :atoms)) end test "returns snapshot offset when shape does exist", %{module: storage, opts: opts} do @@ -188,16 +188,16 @@ defmodule Electric.ShapeCache.StorageImplimentationsTest do assert [ %{ - "key" => ~S|"public"."test_table"/"123"|, - "value" => %{"id" => "123", "name" => "Test"}, - "offset" => offset |> LogOffset.to_iolist() |> :erlang.iolist_to_binary(), - "headers" => %{ - "action" => "insert", - "txid" => 1, - "relation" => ["public", "test_table"] + key: ~S|"public"."test_table"/"123"|, + value: %{id: "123", name: "Test"}, + offset: offset |> LogOffset.to_iolist() |> :erlang.iolist_to_binary(), + headers: %{ + action: "insert", + txid: 1, + relation: ["public", "test_table"] } } - ] == Enum.map(stream, &Jason.decode!/1) + ] == Enum.map(stream, &Jason.decode!(&1, keys: :atoms)) end end @@ -243,12 +243,12 @@ defmodule Electric.ShapeCache.StorageImplimentationsTest do :ok = storage.append_to_log!(shape_id, log_items2, opts) stream = storage.get_log_stream(shape_id, LogOffset.first(), LogOffset.last(), opts) - entries = Enum.map(stream, &Jason.decode!/1) + entries = Enum.map(stream, &Jason.decode!(&1, keys: :atoms)) assert [ - %{"headers" => %{"action" => "insert"}}, - %{"headers" => %{"action" => "update"}}, - %{"headers" => %{"action" => "delete"}} + %{headers: %{action: "insert"}}, + %{headers: %{action: "update"}}, + %{headers: %{action: "delete"}} ] = entries end @@ -288,11 +288,11 @@ defmodule Electric.ShapeCache.StorageImplimentationsTest do stream = storage.get_log_stream(@shape_id, LogOffset.new(lsn1, 0), LogOffset.last(), opts) - entries = Enum.map(stream, &Jason.decode!/1) + entries = Enum.map(stream, &Jason.decode!(&1, keys: :atoms)) assert [ - %{"headers" => %{"action" => "update"}}, - %{"headers" => %{"action" => "delete"}} + %{headers: %{action: "update"}}, + %{headers: %{action: "delete"}} ] = entries end @@ -340,9 +340,9 @@ defmodule Electric.ShapeCache.StorageImplimentationsTest do opts ) - entries = Enum.map(stream, &Jason.decode!/1) + entries = Enum.map(stream, &Jason.decode!(&1, keys: :atoms)) - assert [%{"headers" => %{"action" => "update"}}] = entries + assert [%{headers: %{action: "update"}}] = entries end test "returns only logs for the requested shape_id", %{module: storage, opts: opts} do @@ -374,9 +374,9 @@ defmodule Electric.ShapeCache.StorageImplimentationsTest do :ok = storage.append_to_log!(shape_id1, log_items1, opts) :ok = storage.append_to_log!(shape_id2, log_items2, opts) - assert [%{"value" => %{"name" => "Test A"}}] = + assert [%{value: %{name: "Test A"}}] = storage.get_log_stream(shape_id1, LogOffset.first(), LogOffset.last(), opts) - |> Enum.map(&Jason.decode!/1) + |> Enum.map(&Jason.decode!(&1, keys: :atoms)) end end