Update Book and Publisher transformers to sync the relationship for DBIServer.

dev
KKlochko 2 months ago
parent d57fa73825
commit 5d8e70d79d

@ -21,7 +21,9 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.BookTransformer do
inserted_at: get_in(json_body, ["attributes", "inserted_at"]),
updated_at: get_in(json_body, ["attributes", "updated_at"]),
# relationship
publisher_id: get_in(json_body, ["attributes", "publisher_id"])
publisher_id: get_in(json_body, ["attributes", "publisher_id"]),
# relationship
dbi_server_id: get_in(json_body, ["attributes", "dbi_server_id"])
}
{:ok, attrs}

@ -12,7 +12,9 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.PublisherTransformer do
id: get_in(json_body, ["id"]),
name: get_in(json_body, ["attributes", "name"]),
inserted_at: get_in(json_body, ["attributes", "inserted_at"]),
updated_at: get_in(json_body, ["attributes", "updated_at"])
updated_at: get_in(json_body, ["attributes", "updated_at"]),
# relationship
dbi_server_id: get_in(json_body, ["attributes", "dbi_server_id"])
}
{:ok, attrs}

@ -8,6 +8,7 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.BookTransformerTest do
json_body = %{
"data" => %{
"attributes" => %{
"dbi_server_id" => "889a323e-d104-4b5d-b276-dad5a9b1da99",
"cover_image_url" => "/images/book_cover.png",
"description" => "A cool book.",
"format" => "Paper",
@ -37,6 +38,8 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.BookTransformerTest do
},
"meta" => %{}
},
"book_editions_registry" => %{"links" => %{}, "meta" => %{}},
"dbi_server" => %{"links" => %{}, "meta" => %{}},
"publisher" => %{
"links" => %{
"related" =>
@ -67,13 +70,15 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.BookTransformerTest do
published: "2025-03-05",
publisher_id: "11349865-1b7b-454a-b999-6c4059888a78",
title: "Book",
updated_at: "2025-04-01T18:14:25.754055Z"
updated_at: "2025-04-01T18:14:25.754055Z",
dbi_server_id: "889a323e-d104-4b5d-b276-dad5a9b1da99"
} = book
end
test "a json doesn't contains book information \"data\" attribute" do
json_body = %{
"attributes" => %{
"dbi_server_id" => "889a323e-d104-4b5d-b276-dad5a9b1da99",
"cover_image_url" => "/images/book_cover.png",
"description" => "A cool book.",
"format" => "Paper",
@ -103,6 +108,8 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.BookTransformerTest do
},
"meta" => %{}
},
"book_editions_registry" => %{"links" => %{}, "meta" => %{}},
"dbi_server" => %{"links" => %{}, "meta" => %{}},
"publisher" => %{
"links" => %{
"related" =>
@ -127,7 +134,8 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.BookTransformerTest do
published: "2025-03-05",
publisher_id: "11349865-1b7b-454a-b999-6c4059888a78",
title: "Book",
updated_at: "2025-04-01T18:14:25.754055Z"
updated_at: "2025-04-01T18:14:25.754055Z",
dbi_server_id: "889a323e-d104-4b5d-b276-dad5a9b1da99"
} = book
end
end

@ -8,6 +8,7 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.PublisherTransformerTest
json_body = %{
"data" => %{
"attributes" => %{
"dbi_server_id" => "889a323e-d104-4b5d-b276-dad5a9b1da99",
"inserted_at" => "2025-03-21T09:20:48.791539Z",
"name" => "Publisher",
"updated_at" => "2025-03-21T09:20:48.791539Z"
@ -15,7 +16,7 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.PublisherTransformerTest
"id" => "11349865-1b7b-454a-b999-6c4059888a78",
"links" => %{},
"meta" => %{},
"relationships" => %{},
"relationships" => %{"dbi_server" => %{"links" => %{}, "meta" => %{}}},
"type" => "publisher"
},
"jsonapi" => %{"version" => "1.0"},
@ -32,13 +33,15 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.PublisherTransformerTest
id: "11349865-1b7b-454a-b999-6c4059888a78",
name: "Publisher",
inserted_at: "2025-03-21T09:20:48.791539Z",
updated_at: "2025-03-21T09:20:48.791539Z"
updated_at: "2025-03-21T09:20:48.791539Z",
dbi_server_id: "889a323e-d104-4b5d-b276-dad5a9b1da99"
} = publisher
end
test "a json doesn't contains publisher information \"data\" attribute" do
json_body = %{
"attributes" => %{
"dbi_server_id" => "889a323e-d104-4b5d-b276-dad5a9b1da99",
"inserted_at" => "2025-03-21T09:20:48.791539Z",
"name" => "Publisher",
"updated_at" => "2025-03-21T09:20:48.791539Z"
@ -46,7 +49,7 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.PublisherTransformerTest
"id" => "11349865-1b7b-454a-b999-6c4059888a78",
"links" => %{},
"meta" => %{},
"relationships" => %{},
"relationships" => %{"dbi_server" => %{"links" => %{}, "meta" => %{}}},
"type" => "publisher"
}
@ -56,7 +59,8 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.PublisherTransformerTest
id: "11349865-1b7b-454a-b999-6c4059888a78",
name: "Publisher",
inserted_at: "2025-03-21T09:20:48.791539Z",
updated_at: "2025-03-21T09:20:48.791539Z"
updated_at: "2025-03-21T09:20:48.791539Z",
dbi_server_id: "889a323e-d104-4b5d-b276-dad5a9b1da99"
} = publisher
end
end

Loading…
Cancel
Save