Update the AuthorTransformer to sync all attributes and relationships.

dev
KKlochko 2 months ago
parent 3b761f9c66
commit d57fa73825

@ -13,7 +13,11 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorTransformer do
name: get_in(json_body, ["attributes", "name"]),
description: get_in(json_body, ["attributes", "description"]),
avatar_url: get_in(json_body, ["attributes", "avatar_url"]),
author_alias_registry_id: get_in(json_body, ["attributes", "author_alias_registry_id"])
inserted_at: get_in(json_body, ["attributes", "inserted_at"]),
updated_at: get_in(json_body, ["attributes", "updated_at"]),
# relationship
author_alias_registry_id: get_in(json_body, ["attributes", "author_alias_registry_id"]),
dbi_server_id: get_in(json_body, ["attributes", "dbi_server_id"])
}
{:ok, attrs}

@ -8,15 +8,21 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorTransformerTest do
json_body = %{
"data" => %{
"attributes" => %{
"author_alias_registry_id" => "1320a6fe-b311-45ac-bbaa-39cf29c44624",
"avatar_url" => "/images/avatar.png",
"dbi_server_id" => "889a323e-d104-4b5d-b276-dad5a9b1da99",
"description" => "Something",
"inserted_at" => "2025-03-25T19:19:15.187456Z",
"name" => "Author",
"avatar_url" => "/images/avatar.png",
"author_alias_registry_id" => "1320a6fe-b311-45ac-bbaa-39cf29c44624"
"updated_at" => "2025-03-26T10:16:16.124581Z"
},
"id" => "889a323e-d104-4b5d-b276-dad5a9b1da9d",
"links" => %{},
"meta" => %{},
"relationships" => %{},
"relationships" => %{
"author_alias_registry" => %{"links" => %{}, "meta" => %{}},
"dbi_server" => %{"links" => %{}, "meta" => %{}}
},
"type" => "author"
},
"jsonapi" => %{"version" => "1.0"},
@ -34,22 +40,31 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorTransformerTest do
name: "Author",
description: "Something",
avatar_url: "/images/avatar.png",
author_alias_registry_id: "1320a6fe-b311-45ac-bbaa-39cf29c44624"
author_alias_registry_id: "1320a6fe-b311-45ac-bbaa-39cf29c44624",
dbi_server_id: "889a323e-d104-4b5d-b276-dad5a9b1da99",
inserted_at: "2025-03-25T19:19:15.187456Z",
updated_at: "2025-03-26T10:16:16.124581Z"
} = author
end
test "a json doesn't contains author information \"data\" attribute" do
json_body = %{
"attributes" => %{
"author_alias_registry_id" => "1320a6fe-b311-45ac-bbaa-39cf29c44624",
"avatar_url" => "/images/avatar.png",
"dbi_server_id" => "889a323e-d104-4b5d-b276-dad5a9b1da99",
"description" => "Something",
"inserted_at" => "2025-03-25T19:19:15.187456Z",
"name" => "Author",
"avatar_url" => "/images/avatar.png",
"author_alias_registry_id" => "1320a6fe-b311-45ac-bbaa-39cf29c44624"
"updated_at" => "2025-03-26T10:16:16.124581Z"
},
"id" => "889a323e-d104-4b5d-b276-dad5a9b1da9d",
"links" => %{},
"meta" => %{},
"relationships" => %{},
"relationships" => %{
"author_alias_registry" => %{"links" => %{}, "meta" => %{}},
"dbi_server" => %{"links" => %{}, "meta" => %{}}
},
"type" => "author"
}
@ -60,7 +75,10 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorTransformerTest do
name: "Author",
description: "Something",
avatar_url: "/images/avatar.png",
author_alias_registry_id: "1320a6fe-b311-45ac-bbaa-39cf29c44624"
author_alias_registry_id: "1320a6fe-b311-45ac-bbaa-39cf29c44624",
dbi_server_id: "889a323e-d104-4b5d-b276-dad5a9b1da99",
inserted_at: "2025-03-25T19:19:15.187456Z",
updated_at: "2025-03-26T10:16:16.124581Z"
} = author
end
end

Loading…
Cancel
Save