Update Author to sync only a new non-local data.
This commit is contained in:
@@ -90,5 +90,51 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorSyncTest do
|
||||
|
||||
assert author = saved_author
|
||||
end
|
||||
|
||||
test "the local existing author wouldn't updated", %{user: user} do
|
||||
server = generate(dbi_server(url: @test_server_endpoint))
|
||||
|
||||
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
||||
|
||||
author_attrs = %{
|
||||
id: author.id,
|
||||
name: "Author",
|
||||
description: "Something2",
|
||||
avatar_url: "/images/avatar.png",
|
||||
author_alias_registry_id: nil,
|
||||
inserted_at: "2025-03-21T09:20:48.791539Z",
|
||||
updated_at: "2025-03-21T09:20:48.791539Z"
|
||||
}
|
||||
|
||||
assert :ok = AuthorSync.create_update(author_attrs, server.id)
|
||||
assert {:ok, saved_author} = Metadata.get_author_by_id(author.id)
|
||||
|
||||
assert get_submap(saved_author, author_attrs) != author_attrs
|
||||
assert saved_author.name == "Author"
|
||||
assert saved_author.dbi_server_id == nil
|
||||
end
|
||||
|
||||
test "old author wouldn't be sync", %{user: user} do
|
||||
server = generate(dbi_server(url: @test_server_endpoint))
|
||||
|
||||
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
||||
{:ok, author} = Metadata.assign_author_dbi_server(author, server.id, actor: user)
|
||||
|
||||
author_attrs = %{
|
||||
id: author.id,
|
||||
name: "Author",
|
||||
description: "Something2",
|
||||
avatar_url: "/images/avatar.png",
|
||||
author_alias_registry_id: nil,
|
||||
inserted_at: "2025-03-21T09:20:48.791539Z",
|
||||
updated_at: "2025-03-21T09:20:48.791539Z"
|
||||
}
|
||||
|
||||
assert :ok = AuthorSync.create_update(author_attrs, server.id)
|
||||
assert {:ok, saved_author} = Metadata.get_author_by_id(author.id)
|
||||
|
||||
assert get_submap(saved_author, author_attrs) != author_attrs
|
||||
assert saved_author.name == "Author"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user