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

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

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

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

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

@ -7,7 +7,7 @@ defmodule DecentralisedBookIndex.Sync.SyncServerTask do
alias DecentralisedBookIndex.SyncTasks.SyncBooksTask alias DecentralisedBookIndex.SyncTasks.SyncBooksTask
def sync_all(last_sync_datetime \\ nil) do 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) params = params(last_sync_datetime)

@ -7,9 +7,14 @@ defmodule DecentralisedBookIndex.Sync.ApiClients.FetchJsonTest do
alias DecentralisedBookIndex.TestEndpoints alias DecentralisedBookIndex.TestEndpoints
@test_server_endpoint TestEndpoints.test_api_endpoint() @test_server_endpoint TestEndpoints.test_api_endpoint()
setup do
user = generate(user(role: :moderator))
%{user: user}
end
describe "authors api" do describe "authors api" do
test "get an author" do test "get an author", %{user: user} do
{:ok, author} = Metadata.create_author("Author", "An description") {: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 {:ok, data} = FetchJson.get("#{@test_server_endpoint}/api/v1/json/authors/#{author.id}")
assert data["data"]["id"] == 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() @test_server_endpoint TestEndpoints.test_api_endpoint()
setup do
user = generate(user(role: :moderator))
%{user: user}
end
describe "authors api" do describe "authors api" do
test "get authors" do test "get authors", %{user: user} do
for number <- 1..11 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 end
assert {:ok, records} = FetchJsons.get("#{@test_server_endpoint}/api/v1/json/authors") assert {:ok, records} = FetchJsons.get("#{@test_server_endpoint}/api/v1/json/authors")
assert length(records) == 11 assert length(records) == 11
end end
test "get authors names from API" do test "get authors names from API", %{user: user} do
for number <- 1..11 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 end
get_author_names = fn data -> get_author_names = fn data ->

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

@ -7,6 +7,11 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorSyncTest do
alias DecentralisedBookIndex.TestEndpoints alias DecentralisedBookIndex.TestEndpoints
@test_server_endpoint TestEndpoints.test_api_endpoint() @test_server_endpoint TestEndpoints.test_api_endpoint()
setup do
user = generate(user(role: :moderator))
%{user: user}
end
describe "sync author transformations" do describe "sync author transformations" do
test "a new author will be created" do test "a new author will be created" do
server = generate(dbi_server(url: @test_server_endpoint)) 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 assert server.id == saved_author.dbi_server_id
end end
test "update an existing author" do test "update an existing author", %{user: user} do
server = generate(dbi_server(url: @test_server_endpoint)) 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 = %{ author_attrs = %{
id: author.id, id: author.id,

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

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

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

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

@ -11,19 +11,24 @@ defmodule DecentralisedBookIndex.Sync.SyncServerTaskTest do
alias DecentralisedBookIndex.TestEndpoints alias DecentralisedBookIndex.TestEndpoints
@test_server_endpoint TestEndpoints.test_api_endpoint() @test_server_endpoint TestEndpoints.test_api_endpoint()
setup do
user = generate(user(role: :moderator))
%{user: user}
end
describe "sync all" do describe "sync all" do
test "servers" do test "servers", %{user: user} do
server = generate(dbi_server(url: @test_server_endpoint)) 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() assert server = SyncServerTask.sync_all()
end end
end end
describe "sync one" do describe "sync one" do
test "server" do test "server", %{user: user} do
server = generate(dbi_server(url: @test_server_endpoint)) 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) assert server = SyncServerTask.sync_one(server)
end end

Loading…
Cancel
Save