diff --git a/lib/decentralised_book_index/sync/sync/author_alias_registry_sync.ex b/lib/decentralised_book_index/sync/sync/author_alias_registry_sync.ex index 9db52e5..a509f20 100644 --- a/lib/decentralised_book_index/sync/sync/author_alias_registry_sync.ex +++ b/lib/decentralised_book_index/sync/sync/author_alias_registry_sync.ex @@ -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 diff --git a/lib/decentralised_book_index/sync/sync/author_sync.ex b/lib/decentralised_book_index/sync/sync/author_sync.ex index 4671572..867fbae 100644 --- a/lib/decentralised_book_index/sync/sync/author_sync.ex +++ b/lib/decentralised_book_index/sync/sync/author_sync.ex @@ -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 diff --git a/lib/decentralised_book_index/sync/sync/book_editions_registry_sync.ex b/lib/decentralised_book_index/sync/sync/book_editions_registry_sync.ex index 633ac10..ab54a89 100644 --- a/lib/decentralised_book_index/sync/sync/book_editions_registry_sync.ex +++ b/lib/decentralised_book_index/sync/sync/book_editions_registry_sync.ex @@ -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 diff --git a/lib/decentralised_book_index/sync/sync/book_sync.ex b/lib/decentralised_book_index/sync/sync/book_sync.ex index d7afd61..d840b3e 100644 --- a/lib/decentralised_book_index/sync/sync/book_sync.ex +++ b/lib/decentralised_book_index/sync/sync/book_sync.ex @@ -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 diff --git a/lib/decentralised_book_index/sync/sync/publisher_sync.ex b/lib/decentralised_book_index/sync/sync/publisher_sync.ex index f06bf9e..f7979f5 100644 --- a/lib/decentralised_book_index/sync/sync/publisher_sync.ex +++ b/lib/decentralised_book_index/sync/sync/publisher_sync.ex @@ -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 diff --git a/lib/decentralised_book_index/sync/sync_tasks/sync_server_task.ex b/lib/decentralised_book_index/sync/sync_tasks/sync_server_task.ex index 167ed11..cb7cef2 100644 --- a/lib/decentralised_book_index/sync/sync_tasks/sync_server_task.ex +++ b/lib/decentralised_book_index/sync/sync_tasks/sync_server_task.ex @@ -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) diff --git a/test/decentralised_book_index/sync/api_clients/fetch_json_test.exs b/test/decentralised_book_index/sync/api_clients/fetch_json_test.exs index 31abde4..7d9174c 100644 --- a/test/decentralised_book_index/sync/api_clients/fetch_json_test.exs +++ b/test/decentralised_book_index/sync/api_clients/fetch_json_test.exs @@ -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 diff --git a/test/decentralised_book_index/sync/api_clients/fetch_jsons_test.exs b/test/decentralised_book_index/sync/api_clients/fetch_jsons_test.exs index 038af9d..e3601c3 100644 --- a/test/decentralised_book_index/sync/api_clients/fetch_jsons_test.exs +++ b/test/decentralised_book_index/sync/api_clients/fetch_jsons_test.exs @@ -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 -> diff --git a/test/decentralised_book_index/sync/sync/author_alias_registry_sync_test.exs b/test/decentralised_book_index/sync/sync/author_alias_registry_sync_test.exs index a479cb8..6c9dec0 100644 --- a/test/decentralised_book_index/sync/sync/author_alias_registry_sync_test.exs +++ b/test/decentralised_book_index/sync/sync/author_alias_registry_sync_test.exs @@ -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, diff --git a/test/decentralised_book_index/sync/sync/author_sync_test.exs b/test/decentralised_book_index/sync/sync/author_sync_test.exs index 9cd2984..9cd19b0 100644 --- a/test/decentralised_book_index/sync/sync/author_sync_test.exs +++ b/test/decentralised_book_index/sync/sync/author_sync_test.exs @@ -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, diff --git a/test/decentralised_book_index/sync/sync/book_editions_registry_sync_test.exs b/test/decentralised_book_index/sync/sync/book_editions_registry_sync_test.exs index d9899db..545c652 100644 --- a/test/decentralised_book_index/sync/sync/book_editions_registry_sync_test.exs +++ b/test/decentralised_book_index/sync/sync/book_editions_registry_sync_test.exs @@ -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, diff --git a/test/decentralised_book_index/sync/sync/publisher_sync_test.exs b/test/decentralised_book_index/sync/sync/publisher_sync_test.exs index 29c82c0..6f70ce2 100644 --- a/test/decentralised_book_index/sync/sync/publisher_sync_test.exs +++ b/test/decentralised_book_index/sync/sync/publisher_sync_test.exs @@ -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, diff --git a/test/decentralised_book_index/sync/sync_tasks/sync_authors_task_test.exs b/test/decentralised_book_index/sync/sync_tasks/sync_authors_task_test.exs index 20413a1..f5c9d7e 100644 --- a/test/decentralised_book_index/sync/sync_tasks/sync_authors_task_test.exs +++ b/test/decentralised_book_index/sync/sync_tasks/sync_authors_task_test.exs @@ -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 diff --git a/test/decentralised_book_index/sync/sync_tasks/sync_publishers_task_test.exs b/test/decentralised_book_index/sync/sync_tasks/sync_publishers_task_test.exs index 89f12a7..8f91916 100644 --- a/test/decentralised_book_index/sync/sync_tasks/sync_publishers_task_test.exs +++ b/test/decentralised_book_index/sync/sync_tasks/sync_publishers_task_test.exs @@ -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 diff --git a/test/decentralised_book_index/sync/sync_tasks/sync_server_task_test.exs b/test/decentralised_book_index/sync/sync_tasks/sync_server_task_test.exs index 9fcaf45..8d84025 100644 --- a/test/decentralised_book_index/sync/sync_tasks/sync_server_task_test.exs +++ b/test/decentralised_book_index/sync/sync_tasks/sync_server_task_test.exs @@ -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