Update the sync tests.
continuous-integration/drone/push Build is passing Details

dev
KKlochko 2 months ago
parent 3285d3860e
commit d2c539333c

@ -12,7 +12,7 @@ defmodule DecentralisedBookIndex.Sync.AuthorAliasRegistrySync do
alias_registry
|> Ash.Changeset.for_update(:sync, attrs)
|> Ash.update!()
|> Ash.update!(authorize?: false)
:ok
@ -23,7 +23,7 @@ defmodule DecentralisedBookIndex.Sync.AuthorAliasRegistrySync do
AuthorAliasRegistry
|> Ash.Changeset.for_create(:sync_create, attrs)
|> Ash.create!()
|> Ash.create!(authorize?: false)
:ok
end

@ -16,7 +16,7 @@ defmodule DecentralisedBookIndex.Sync.AuthorSync do
author
|> Ash.Changeset.for_update(:sync, attrs)
|> Ash.update!()
|> Ash.update!(authorize?: false)
:ok
@ -28,7 +28,7 @@ defmodule DecentralisedBookIndex.Sync.AuthorSync do
Author
|> Ash.Changeset.for_create(:sync_create, attrs)
|> Ash.create!()
|> Ash.create!(authorize?: false)
:ok
end

@ -12,7 +12,7 @@ defmodule DecentralisedBookIndex.Sync.BookEditionsRegistrySync do
editions_registry
|> Ash.Changeset.for_update(:sync, attrs)
|> Ash.update!()
|> Ash.update!(authorize?: false)
:ok
@ -23,7 +23,7 @@ defmodule DecentralisedBookIndex.Sync.BookEditionsRegistrySync do
BookEditionsRegistry
|> Ash.Changeset.for_create(:sync_create, attrs)
|> Ash.create!()
|> Ash.create!(authorize?: false)
:ok
end

@ -16,7 +16,7 @@ defmodule DecentralisedBookIndex.Sync.BookSync do
book
|> Ash.Changeset.for_update(:sync, attrs)
|> Ash.update!()
|> Ash.update!(authorize?: false)
:ok
{:error, %Ash.Error.Query.NotFound{}} ->
@ -27,7 +27,7 @@ defmodule DecentralisedBookIndex.Sync.BookSync do
Book
|> Ash.Changeset.for_create(:sync_create, attrs)
|> Ash.create!()
|> Ash.create!(authorize?: false)
:ok
end

@ -12,7 +12,7 @@ defmodule DecentralisedBookIndex.Sync.PublisherSync do
publisher
|> Ash.Changeset.for_update(:sync, attrs)
|> Ash.update!()
|> Ash.update!(authorize?: false)
:ok
{:error, %Ash.Error.Query.NotFound{}} ->
@ -22,7 +22,7 @@ defmodule DecentralisedBookIndex.Sync.PublisherSync do
Publisher
|> Ash.Changeset.for_create(:sync_create, attrs)
|> Ash.create!()
|> Ash.create!(authorize?: false)
:ok
end

@ -7,7 +7,7 @@ defmodule DecentralisedBookIndex.Sync.SyncServerTask do
alias DecentralisedBookIndex.SyncTasks.SyncBooksTask
def sync_all(last_sync_datetime \\ nil) do
{:ok, servers} = Metadata.list_dbi_server()
{:ok, servers} = Metadata.list_dbi_server(authorize?: false)
params = params(last_sync_datetime)

@ -7,9 +7,14 @@ defmodule DecentralisedBookIndex.Sync.ApiClients.FetchJsonTest do
alias DecentralisedBookIndex.TestEndpoints
@test_server_endpoint TestEndpoints.test_api_endpoint()
setup do
user = generate(user(role: :moderator))
%{user: user}
end
describe "authors api" do
test "get an author" do
{:ok, author} = Metadata.create_author("Author", "An description")
test "get an author", %{user: user} do
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
assert {:ok, data} = FetchJson.get("#{@test_server_endpoint}/api/v1/json/authors/#{author.id}")
assert data["data"]["id"] == author.id

@ -8,19 +8,24 @@ defmodule DecentralisedBookIndex.Sync.ApiClients.FetchJsonsTest do
@test_server_endpoint TestEndpoints.test_api_endpoint()
setup do
user = generate(user(role: :moderator))
%{user: user}
end
describe "authors api" do
test "get authors" do
test "get authors", %{user: user} do
for number <- 1..11 do
Metadata.create_author!("Author#{number}", "An description#{number}")
Metadata.create_author!("Author#{number}", "An description#{number}", nil, nil, actor: user)
end
assert {:ok, records} = FetchJsons.get("#{@test_server_endpoint}/api/v1/json/authors")
assert length(records) == 11
end
test "get authors names from API" do
test "get authors names from API", %{user: user} do
for number <- 1..11 do
Metadata.create_author!("Author#{number}", "An description#{number}")
Metadata.create_author!("Author#{number}", "An description#{number}", nil, nil, actor: user)
end
get_author_names = fn data ->

@ -7,6 +7,11 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorAliasRegistrySyncTe
alias DecentralisedBookIndex.TestEndpoints
@test_server_endpoint TestEndpoints.test_api_endpoint()
setup do
user = generate(user(role: :moderator))
%{user: user}
end
describe "sync author alias registry transformations" do
test "a new registry will be created" do
server = generate(dbi_server(url: @test_server_endpoint))
@ -20,10 +25,10 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorAliasRegistrySyncTe
assert server.id == saved_alias.dbi_server_id
end
test "the same registry" do
test "the same registry", %{user: user} do
server = generate(dbi_server(url: @test_server_endpoint))
{:ok, same_alias} = Metadata.create_author_alias_registry()
{:ok, same_alias} = Metadata.create_author_alias_registry(actor: user)
attrs = %{
id: same_alias.id,

@ -7,6 +7,11 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorSyncTest do
alias DecentralisedBookIndex.TestEndpoints
@test_server_endpoint TestEndpoints.test_api_endpoint()
setup do
user = generate(user(role: :moderator))
%{user: user}
end
describe "sync author transformations" do
test "a new author will be created" do
server = generate(dbi_server(url: @test_server_endpoint))
@ -67,10 +72,10 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorSyncTest do
assert server.id == saved_author.dbi_server_id
end
test "update an existing author" do
test "update an existing author", %{user: user} do
server = generate(dbi_server(url: @test_server_endpoint))
{:ok, author} = Metadata.create_author("Author", "An description")
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
author_attrs = %{
id: author.id,

@ -7,6 +7,11 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.BookEditionsRegistrySyncT
alias DecentralisedBookIndex.TestEndpoints
@test_server_endpoint TestEndpoints.test_api_endpoint()
setup do
user = generate(user(role: :moderator))
%{user: user}
end
describe "sync book edition registry transformations" do
test "a new registry will be created" do
server = generate(dbi_server(url: @test_server_endpoint))
@ -20,10 +25,10 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.BookEditionsRegistrySyncT
assert server.id == saved_alias.dbi_server_id
end
test "the same registry" do
test "the same registry", %{user: user} do
server = generate(dbi_server(url: @test_server_endpoint))
{:ok, same_alias} = Metadata.create_book_editions_registry()
{:ok, same_alias} = Metadata.create_book_editions_registry(actor: user)
attrs = %{
id: same_alias.id,

@ -7,6 +7,11 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.PublisherSyncTest do
alias DecentralisedBookIndex.TestEndpoints
@test_server_endpoint TestEndpoints.test_api_endpoint()
setup do
user = generate(user(role: :moderator))
%{user: user}
end
describe "sync publisher transformations" do
test "a new publisher will be created" do
server = generate(dbi_server(url: @test_server_endpoint))
@ -33,10 +38,10 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.PublisherSyncTest do
assert server.id == saved_publisher.dbi_server_id
end
test "update an existing publisher" do
test "update an existing publisher", %{user: user} do
server = generate(dbi_server(url: @test_server_endpoint))
{:ok, publisher} = Metadata.create_publisher("Publisher")
{:ok, publisher} = Metadata.create_publisher("Publisher", actor: user)
publisher_attrs = %{
id: publisher.id,

@ -7,12 +7,17 @@ defmodule DecentralisedBookIndex.SyncTasks.SyncAuthorsTaskTest do
alias DecentralisedBookIndex.TestEndpoints
@test_server_endpoint TestEndpoints.test_api_endpoint()
setup do
user = generate(user(role: :moderator))
%{user: user}
end
describe "sync authors tasks" do
test "sync authors" do
test "sync authors", %{user: user} do
server = generate(dbi_server(url: @test_server_endpoint))
{:ok, author} = Metadata.create_author("Author", "An description")
{:ok, author} = Metadata.create_author("Author2", "An description")
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
{:ok, author} = Metadata.create_author("Author2", "An description", nil, nil, actor: user)
assert server = SyncAuthorsTask.sync(server)
end

@ -7,12 +7,17 @@ defmodule DecentralisedBookIndex.SyncTasks.SyncPublishersTaskTest do
alias DecentralisedBookIndex.TestEndpoints
@test_server_endpoint TestEndpoints.test_api_endpoint()
setup do
user = generate(user(role: :moderator))
%{user: user}
end
describe "sync publishers tasks" do
test "sync publisher" do
test "sync publisher", %{user: user} do
server = generate(dbi_server(url: @test_server_endpoint))
{:ok, _publisher} = Metadata.create_publisher("Publisher")
{:ok, _publisher} = Metadata.create_publisher("Publisher2")
{:ok, _publisher} = Metadata.create_publisher("Publisher", actor: user)
{:ok, _publisher} = Metadata.create_publisher("Publisher2", actor: user)
assert server = SyncPublishersTask.sync(server)
end

@ -11,19 +11,24 @@ defmodule DecentralisedBookIndex.Sync.SyncServerTaskTest do
alias DecentralisedBookIndex.TestEndpoints
@test_server_endpoint TestEndpoints.test_api_endpoint()
setup do
user = generate(user(role: :moderator))
%{user: user}
end
describe "sync all" do
test "servers" do
test "servers", %{user: user} do
server = generate(dbi_server(url: @test_server_endpoint))
{:ok, author} = Metadata.create_author("Author", "An description")
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
assert server = SyncServerTask.sync_all()
end
end
describe "sync one" do
test "server" do
test "server", %{user: user} do
server = generate(dbi_server(url: @test_server_endpoint))
{:ok, author} = Metadata.create_author("Author", "An description")
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
assert server = SyncServerTask.sync_one(server)
end

Loading…
Cancel
Save