This commit is contained in:
@@ -7,7 +7,12 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorTransformerTest do
|
|||||||
test "a json contains correct author information" do
|
test "a json contains correct author information" do
|
||||||
json_body = %{
|
json_body = %{
|
||||||
"data" => %{
|
"data" => %{
|
||||||
"attributes" => %{"description" => "Something", "name" => "Author", "avatar_url" => "/images/avatar.png"},
|
"attributes" => %{
|
||||||
|
"description" => "Something",
|
||||||
|
"name" => "Author",
|
||||||
|
"avatar_url" => "/images/avatar.png",
|
||||||
|
"author_alias_registry_id" => "1320a6fe-b311-45ac-bbaa-39cf29c44624"
|
||||||
|
},
|
||||||
"id" => "889a323e-d104-4b5d-b276-dad5a9b1da9d",
|
"id" => "889a323e-d104-4b5d-b276-dad5a9b1da9d",
|
||||||
"links" => %{},
|
"links" => %{},
|
||||||
"meta" => %{},
|
"meta" => %{},
|
||||||
@@ -26,13 +31,19 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorTransformerTest do
|
|||||||
id: "889a323e-d104-4b5d-b276-dad5a9b1da9d",
|
id: "889a323e-d104-4b5d-b276-dad5a9b1da9d",
|
||||||
name: "Author",
|
name: "Author",
|
||||||
description: "Something",
|
description: "Something",
|
||||||
avatar_url: "/images/avatar.png"
|
avatar_url: "/images/avatar.png",
|
||||||
|
author_alias_registry_id: "1320a6fe-b311-45ac-bbaa-39cf29c44624"
|
||||||
} = author
|
} = author
|
||||||
end
|
end
|
||||||
|
|
||||||
test "a json doesn't contains author information \"data\" attribute" do
|
test "a json doesn't contains author information \"data\" attribute" do
|
||||||
json_body = %{
|
json_body = %{
|
||||||
"attributes" => %{"description" => "Something", "name" => "Author", "avatar_url" => "/images/avatar.png"},
|
"attributes" => %{
|
||||||
|
"description" => "Something",
|
||||||
|
"name" => "Author",
|
||||||
|
"avatar_url" => "/images/avatar.png",
|
||||||
|
"author_alias_registry_id" => "1320a6fe-b311-45ac-bbaa-39cf29c44624"
|
||||||
|
},
|
||||||
"id" => "889a323e-d104-4b5d-b276-dad5a9b1da9d",
|
"id" => "889a323e-d104-4b5d-b276-dad5a9b1da9d",
|
||||||
"links" => %{},
|
"links" => %{},
|
||||||
"meta" => %{},
|
"meta" => %{},
|
||||||
@@ -45,7 +56,8 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorTransformerTest do
|
|||||||
id: "889a323e-d104-4b5d-b276-dad5a9b1da9d",
|
id: "889a323e-d104-4b5d-b276-dad5a9b1da9d",
|
||||||
name: "Author",
|
name: "Author",
|
||||||
description: "Something",
|
description: "Something",
|
||||||
avatar_url: "/images/avatar.png"
|
avatar_url: "/images/avatar.png",
|
||||||
|
author_alias_registry_id: "1320a6fe-b311-45ac-bbaa-39cf29c44624"
|
||||||
} = author
|
} = author
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorAliasRegistrySyncTest do
|
||||||
|
use DecentralisedBookIndex.DataCase, async: true
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.Sync.AuthorAliasRegistrySync
|
||||||
|
alias DecentralisedBookIndex.Metadata
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.TestEndpoints
|
||||||
|
@test_server_endpoint TestEndpoints.test_api_endpoint()
|
||||||
|
|
||||||
|
describe "sync author alias registry transformations" do
|
||||||
|
test "a new registry will be created" do
|
||||||
|
server = generate(dbi_server(url: @test_server_endpoint))
|
||||||
|
|
||||||
|
attrs = %{
|
||||||
|
id: "889a323e-d104-4b5d-b276-dad5a9b1da9d",
|
||||||
|
}
|
||||||
|
|
||||||
|
assert :ok = AuthorAliasRegistrySync.create_update(attrs, server.id)
|
||||||
|
assert {:ok, saved_alias} = Metadata.get_author_by_id(attrs.id)
|
||||||
|
assert server.id == saved_alias.dbi_server_id
|
||||||
|
end
|
||||||
|
|
||||||
|
test "the same registry" do
|
||||||
|
server = generate(dbi_server(url: @test_server_endpoint))
|
||||||
|
|
||||||
|
{:ok, same_alias} = Metadata.create_author_alias_registry()
|
||||||
|
|
||||||
|
attrs = %{
|
||||||
|
id: same_alias.id,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert :ok = AuthorAliasRegistrySync.create_update(attrs, server.id)
|
||||||
|
assert {:ok, saved_alias} = Metadata.get_author_by_id(attrs.id)
|
||||||
|
assert server.id == saved_alias.dbi_server_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -31,8 +31,38 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorSyncTest do
|
|||||||
author
|
author
|
||||||
|> Map.replace(:inserted_at, inserted_at)
|
|> Map.replace(:inserted_at, inserted_at)
|
||||||
|> Map.replace(:updated_at, updated_at)
|
|> Map.replace(:updated_at, updated_at)
|
||||||
|
|> Map.delete(:author_alias_registry_id)
|
||||||
|
|
||||||
assert author = saved_author
|
assert get_submap(saved_author, author) == author
|
||||||
|
assert nil != saved_author.author_alias_registry_id
|
||||||
|
assert server.id == saved_author.dbi_server_id
|
||||||
|
end
|
||||||
|
|
||||||
|
test "a new author has the same alias registry" do
|
||||||
|
server = generate(dbi_server(url: @test_server_endpoint))
|
||||||
|
|
||||||
|
author = %{
|
||||||
|
id: "889a323e-d104-4b5d-b276-dad5a9b1da9d",
|
||||||
|
name: "Author",
|
||||||
|
description: "Something",
|
||||||
|
avatar_url: "/images/avatar.png",
|
||||||
|
author_alias_registry_id: "1320a6fe-b311-45ac-bbaa-39cf29c44624",
|
||||||
|
inserted_at: "2025-03-21T09:20:48.791539Z",
|
||||||
|
updated_at: "2025-03-21T09:20:48.791539Z"
|
||||||
|
}
|
||||||
|
|
||||||
|
{:ok, inserted_at, 0} = DateTime.from_iso8601(author[:inserted_at])
|
||||||
|
{:ok, updated_at, 0} = DateTime.from_iso8601(author[:updated_at])
|
||||||
|
|
||||||
|
assert :ok = AuthorSync.create_update(author, server.id)
|
||||||
|
assert {:ok, saved_author} = Metadata.get_author_by_id(author.id)
|
||||||
|
|
||||||
|
author =
|
||||||
|
author
|
||||||
|
|> Map.replace(:inserted_at, inserted_at)
|
||||||
|
|> Map.replace(:updated_at, updated_at)
|
||||||
|
|
||||||
|
assert get_submap(saved_author, author) == author
|
||||||
assert nil != saved_author.author_alias_registry_id
|
assert nil != saved_author.author_alias_registry_id
|
||||||
assert server.id == saved_author.dbi_server_id
|
assert server.id == saved_author.dbi_server_id
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user