Compare commits
13
Commits
64028d09f5
...
1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
045faf59a4 | ||
|
|
152bee732f | ||
|
|
99188454e9 | ||
|
|
80e99b7de8 | ||
|
|
51c584056b | ||
|
|
b70b99ba51 | ||
|
|
9c7a555dae | ||
|
|
ab3d65a899 | ||
|
|
44841a53e8 | ||
|
|
a25a4e24da | ||
|
|
493aca0e5b | ||
|
|
8a3b522049 | ||
|
|
89c871110c |
+15
-1
@@ -24,6 +24,20 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- mix test
|
- mix test
|
||||||
|
|
||||||
|
- name: build the image
|
||||||
|
image: plugins/kaniko
|
||||||
|
settings:
|
||||||
|
username: kklochko
|
||||||
|
password:
|
||||||
|
from_secret: REGISTRY_PASSWORD
|
||||||
|
repo: git.kklochko.space/kklochko/decentralised_book_index
|
||||||
|
registry: git.kklochko.space
|
||||||
|
tags:
|
||||||
|
- latest
|
||||||
|
- ${DRONE_TAG}
|
||||||
|
when:
|
||||||
|
event: tag
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: mix
|
- name: mix
|
||||||
temp: {}
|
temp: {}
|
||||||
@@ -34,4 +48,4 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
POSTGRES_DB: decentralised_book_index_dev
|
POSTGRES_DB: decentralised_book_index_dev
|
||||||
POSTGRES_USER: postgres
|
POSTGRES_USER: postgres
|
||||||
POSTGRES_PASSWORD: postgres
|
POSTGRES_PASSWORD: postgres
|
||||||
|
|||||||
+2
-1
@@ -12,7 +12,8 @@ config :decentralised_book_index, Oban,
|
|||||||
repo: DecentralisedBookIndex.Repo,
|
repo: DecentralisedBookIndex.Repo,
|
||||||
queues: [default: 14],
|
queues: [default: 14],
|
||||||
plugins: [
|
plugins: [
|
||||||
Oban.Plugins.Pruner,
|
# A job will be pruned after 7 days.
|
||||||
|
{Oban.Plugins.Pruner, max_age: 7*24*60*60},
|
||||||
{Oban.Plugins.Cron,
|
{Oban.Plugins.Cron,
|
||||||
crontab: [
|
crontab: [
|
||||||
{"@daily", DecentralisedBookIndex.SyncWorker},
|
{"@daily", DecentralisedBookIndex.SyncWorker},
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.SearchResources do
|
|||||||
|
|
||||||
defp can_add?(current_user, role) do
|
defp can_add?(current_user, role) do
|
||||||
case role do
|
case role do
|
||||||
:admin -> current_user != nil and Role.can_moderate?(current_user.role)
|
:admin -> current_user != nil and Role.can_administrate?(current_user.role)
|
||||||
:moderator -> current_user != nil and Role.can_moderate?(current_user.role)
|
:moderator -> current_user != nil and Role.can_moderate?(current_user.role)
|
||||||
_ -> false
|
_ -> false
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.SelectedAuthor do
|
|||||||
|
|
||||||
errors =
|
errors =
|
||||||
if Phoenix.Component.used_input?(assigns.author_form), do: assigns.author_form.errors, else: []
|
if Phoenix.Component.used_input?(assigns.author_form), do: assigns.author_form.errors, else: []
|
||||||
IO.inspect("errors")
|
|
||||||
IO.inspect(errors)
|
|
||||||
|
|
||||||
assigns =
|
assigns =
|
||||||
assigns
|
assigns
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyPartials.Navbar do
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= if @current_user != nil and Role.can_administrate?(@current_user.role) do %>
|
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a
|
||||||
href={~p"/servers/"}
|
href={~p"/servers/"}
|
||||||
|
|||||||
@@ -158,9 +158,6 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def handle_event("select-author-alias", %{"author-alias" => author_alias_id}, socket) do
|
def handle_event("select-author-alias", %{"author-alias" => author_alias_id}, socket) do
|
||||||
IO.inspect("book_editions_registry_id")
|
|
||||||
IO.inspect(author_alias_id)
|
|
||||||
|
|
||||||
socket =
|
socket =
|
||||||
socket
|
socket
|
||||||
|> update(:form, fn form ->
|
|> update(:form, fn form ->
|
||||||
|
|||||||
@@ -57,6 +57,25 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Show do
|
|||||||
<p class="text-gray-300 leading-relaxed">
|
<p class="text-gray-300 leading-relaxed">
|
||||||
{@author.description}
|
{@author.description}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<%= if not is_nil(@author.dbi_server) do %>
|
||||||
|
<dl>
|
||||||
|
<dt class="mt-4 mb-2 font-semibold leading-none text-gray-900 dark:text-white">
|
||||||
|
From Server
|
||||||
|
</dt>
|
||||||
|
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">
|
||||||
|
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
|
||||||
|
<.link navigate={~p"/servers/#{@author.dbi_server.id}/"} class="hover:underline">
|
||||||
|
{@author.dbi_server.name}
|
||||||
|
</.link>
|
||||||
|
<% else %>
|
||||||
|
<.link navigate={@author.dbi_server.url} class="hover:underline">
|
||||||
|
{@author.dbi_server.name}
|
||||||
|
</.link>
|
||||||
|
<% end %>
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,22 @@ defmodule DecentralisedBookIndexWeb.BookLive.Show do
|
|||||||
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{bid.type}: {bid.bid}</dd>
|
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{bid.type}: {bid.bid}</dd>
|
||||||
<% end %>
|
<% end %>
|
||||||
</dl>
|
</dl>
|
||||||
|
<%= if not is_nil(@book.dbi_server) do %>
|
||||||
|
<dl>
|
||||||
|
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">From Server</dt>
|
||||||
|
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">
|
||||||
|
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
|
||||||
|
<.link navigate={~p"/servers/#{@book.dbi_server.id}/"} class="hover:underline">
|
||||||
|
{@book.dbi_server.name}
|
||||||
|
</.link>
|
||||||
|
<% else %>
|
||||||
|
<.link navigate={@book.dbi_server.url} class="hover:underline">
|
||||||
|
{@book.dbi_server.name}
|
||||||
|
</.link>
|
||||||
|
<% end %>
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= if not Enum.empty?(@alternative_editions) do %>
|
<%= if not Enum.empty?(@alternative_editions) do %>
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.FormComponent do
|
|||||||
socket =
|
socket =
|
||||||
socket
|
socket
|
||||||
|> put_flash(:info, "Server #{socket.assigns.form.source.type}d successfully")
|
|> put_flash(:info, "Server #{socket.assigns.form.source.type}d successfully")
|
||||||
|> push_navigate(to: patch_url(socket.assigns.action, dbi_server.id))
|
|> redirect(to: patch_url(socket.assigns.action, dbi_server.id))
|
||||||
|
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
|
|
||||||
|
|||||||
@@ -4,26 +4,30 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Index do
|
|||||||
alias DecentralisedBookIndex.Metadata
|
alias DecentralisedBookIndex.Metadata
|
||||||
alias DecentralisedBookIndex.SyncTasks.SyncServerTask
|
alias DecentralisedBookIndex.SyncTasks.SyncServerTask
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.Accounts.Role
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<.header>
|
<.header>
|
||||||
Listing Servers
|
Listing Servers
|
||||||
<:actions>
|
<:actions>
|
||||||
<div class="flex flex-row gap-2">
|
<%= if @current_user != nil and Role.can_administrate?(@current_user.role) do %>
|
||||||
<div class="flex flex-row gap-2">
|
<div class="flex flex-row gap-2">
|
||||||
<.primary_button phx-click="sync">
|
<div class="flex flex-row gap-2">
|
||||||
Sync now
|
<.primary_button phx-click="sync">
|
||||||
</.primary_button>
|
Sync now
|
||||||
</div>
|
|
||||||
<div class="flex flex-row gap-2">
|
|
||||||
<.link patch={~p"/oban"}>
|
|
||||||
<.primary_button>
|
|
||||||
Task dashboard
|
|
||||||
</.primary_button>
|
</.primary_button>
|
||||||
</.link>
|
</div>
|
||||||
|
<div class="flex flex-row gap-2">
|
||||||
|
<.link patch={~p"/oban"}>
|
||||||
|
<.primary_button>
|
||||||
|
Task dashboard
|
||||||
|
</.primary_button>
|
||||||
|
</.link>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<% end %>
|
||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
@@ -63,7 +67,9 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Index do
|
|||||||
<.link navigate={~p"/servers/#{dbi_server}"}>Show</.link>
|
<.link navigate={~p"/servers/#{dbi_server}"}>Show</.link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<.link patch={~p"/servers/#{dbi_server}/edit"}>Edit</.link>
|
<%= if @current_user != nil and Role.can_administrate?(@current_user.role) do %>
|
||||||
|
<.link patch={~p"/servers/#{dbi_server}/edit"}>Edit</.link>
|
||||||
|
<% end %>
|
||||||
</:action>
|
</:action>
|
||||||
</.table>
|
</.table>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
defmodule DecentralisedBookIndexWeb.DbiServerLive.Show do
|
defmodule DecentralisedBookIndexWeb.DbiServerLive.Show do
|
||||||
use DecentralisedBookIndexWeb, :live_view
|
use DecentralisedBookIndexWeb, :live_view
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.Accounts.Role
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
@@ -8,7 +10,7 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Show do
|
|||||||
{@dbi_server.name}
|
{@dbi_server.name}
|
||||||
|
|
||||||
<:actions>
|
<:actions>
|
||||||
<%= if is_nil(@dbi_server.dbi_server) do %>
|
<%= if is_nil(@dbi_server.dbi_server) and @current_user != nil and Role.can_administrate?(@current_user.role) do %>
|
||||||
<.link patch={~p"/servers/#{@dbi_server}/edit"} phx-click={JS.push_focus()}>
|
<.link patch={~p"/servers/#{@dbi_server}/edit"} phx-click={JS.push_focus()}>
|
||||||
<.edit_button>
|
<.edit_button>
|
||||||
Edit
|
Edit
|
||||||
@@ -18,7 +20,6 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Show do
|
|||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<dl>
|
<dl>
|
||||||
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">Url</dt>
|
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">Url</dt>
|
||||||
@@ -28,6 +29,16 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Show do
|
|||||||
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">Sync on?</dt>
|
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">Sync on?</dt>
|
||||||
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{@dbi_server.sync_on?}</dd>
|
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{@dbi_server.sync_on?}</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
<%= if not is_nil(@dbi_server.dbi_server) do %>
|
||||||
|
<dl>
|
||||||
|
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">From Server</dt>
|
||||||
|
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">
|
||||||
|
<.link navigate={~p"/servers/#{@dbi_server.dbi_server.id}/"} class="hover:underline">
|
||||||
|
{@dbi_server.dbi_server.name}
|
||||||
|
</.link>
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<.back navigate={~p"/servers"}>Back to servers</.back>
|
<.back navigate={~p"/servers"}>Back to servers</.back>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
defmodule DecentralisedBookIndexWeb.PublisherLive.Show do
|
defmodule DecentralisedBookIndexWeb.PublisherLive.Show do
|
||||||
use DecentralisedBookIndexWeb, :live_view
|
use DecentralisedBookIndexWeb, :live_view
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.Accounts.Role
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
@@ -18,6 +20,27 @@ defmodule DecentralisedBookIndexWeb.PublisherLive.Show do
|
|||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
|
<%= if not is_nil(@publisher.dbi_server) do %>
|
||||||
|
<div>
|
||||||
|
<dl>
|
||||||
|
<dt class="mt-4 mb-2 font-semibold leading-none text-gray-900 dark:text-white">
|
||||||
|
From Server
|
||||||
|
</dt>
|
||||||
|
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">
|
||||||
|
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
|
||||||
|
<.link navigate={~p"/servers/#{@publisher.dbi_server.id}/"} class="hover:underline">
|
||||||
|
{@publisher.dbi_server.name}
|
||||||
|
</.link>
|
||||||
|
<% else %>
|
||||||
|
<.link navigate={@publisher.dbi_server.url} class="hover:underline">
|
||||||
|
{@publisher.dbi_server.name}
|
||||||
|
</.link>
|
||||||
|
<% end %>
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<.back navigate={~p"/publishers"}>Back to publishers</.back>
|
<.back navigate={~p"/publishers"}>Back to publishers</.back>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -41,6 +41,18 @@ defmodule DecentralisedBookIndexWeb.Router do
|
|||||||
scope "/", DecentralisedBookIndexWeb do
|
scope "/", DecentralisedBookIndexWeb do
|
||||||
pipe_through :browser
|
pipe_through :browser
|
||||||
|
|
||||||
|
ash_authentication_live_session :admin_authenticated_routes,
|
||||||
|
on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :admin_required} do
|
||||||
|
live "/servers/new", DbiServerLive.Edit, :new
|
||||||
|
live "/servers/:id/edit", DbiServerLive.Edit, :edit
|
||||||
|
#live "/servers", DbiServerLive.Index, :index
|
||||||
|
#live "/servers/:id", DbiServerLive.Show, :show
|
||||||
|
|
||||||
|
live "/users", UserLive.Index, :index
|
||||||
|
live "/users/:id", UserLive.Show, :show
|
||||||
|
live "/users/:id/edit", UserLive.Edit, :edit
|
||||||
|
end
|
||||||
|
|
||||||
ash_authentication_live_session :moderator_authenticated_routes,
|
ash_authentication_live_session :moderator_authenticated_routes,
|
||||||
on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :moderator_required} do
|
on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :moderator_required} do
|
||||||
live "/books/new", BookLive.Edit, :new
|
live "/books/new", BookLive.Edit, :new
|
||||||
@@ -56,19 +68,9 @@ defmodule DecentralisedBookIndexWeb.Router do
|
|||||||
live "/publishers/:id/edit", PublisherLive.Edit, :edit
|
live "/publishers/:id/edit", PublisherLive.Edit, :edit
|
||||||
|
|
||||||
live "/publishers/:id", PublisherLive.Show, :show
|
live "/publishers/:id", PublisherLive.Show, :show
|
||||||
end
|
|
||||||
|
|
||||||
ash_authentication_live_session :admin_authenticated_routes,
|
|
||||||
on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :admin_required} do
|
|
||||||
live "/servers", DbiServerLive.Index, :index
|
live "/servers", DbiServerLive.Index, :index
|
||||||
live "/servers/new", DbiServerLive.Edit, :new
|
|
||||||
live "/servers/:id/edit", DbiServerLive.Edit, :edit
|
|
||||||
|
|
||||||
live "/servers/:id", DbiServerLive.Show, :show
|
live "/servers/:id", DbiServerLive.Show, :show
|
||||||
|
|
||||||
live "/users", UserLive.Index, :index
|
|
||||||
live "/users/:id", UserLive.Show, :show
|
|
||||||
live "/users/:id/edit", UserLive.Edit, :edit
|
|
||||||
end
|
end
|
||||||
|
|
||||||
ash_authentication_live_session :maybe_authenticated_routes,
|
ash_authentication_live_session :maybe_authenticated_routes,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ defmodule DecentralisedBookIndex.MixProject do
|
|||||||
def project do
|
def project do
|
||||||
[
|
[
|
||||||
app: :decentralised_book_index,
|
app: :decentralised_book_index,
|
||||||
version: "0.1.0",
|
version: "1.0.0",
|
||||||
elixir: "~> 1.14",
|
elixir: "~> 1.14",
|
||||||
elixirc_paths: elixirc_paths(Mix.env()),
|
elixirc_paths: elixirc_paths(Mix.env()),
|
||||||
start_permanent: Mix.env() == :prod,
|
start_permanent: Mix.env() == :prod,
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ defmodule DecentralisedBookIndex.Metadata.AuthorTest do
|
|||||||
test "new author has no alternatives names", %{user: user} do
|
test "new author has no alternatives names", %{user: user} do
|
||||||
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
||||||
assert {:ok, alternatives_names} = Metadata.get_author_alternative_names(author)
|
assert {:ok, alternatives_names} = Metadata.get_author_alternative_names(author)
|
||||||
assert alternatives_names = []
|
assert ^alternatives_names = []
|
||||||
end
|
end
|
||||||
|
|
||||||
test "author has related author so they has one alternative name", %{user: user} do
|
test "author has related author so they has one alternative name", %{user: user} do
|
||||||
@@ -73,7 +73,7 @@ defmodule DecentralisedBookIndex.Metadata.AuthorTest do
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert {:ok, alternatives_names} = Metadata.get_author_alternative_names(author)
|
assert {:ok, alternatives_names} = Metadata.get_author_alternative_names(author)
|
||||||
assert alternatives_names = [related_author]
|
assert get_ids(alternatives_names) == [related_author.id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,8 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|||||||
bids,
|
bids,
|
||||||
author_roles,
|
author_roles,
|
||||||
publisher.id,
|
publisher.id,
|
||||||
nil
|
nil,
|
||||||
|
actor: user
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -146,7 +147,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert {:ok, alternatives_names} = Metadata.get_book_alternative_editions(book)
|
assert {:ok, alternatives_names} = Metadata.get_book_alternative_editions(book)
|
||||||
assert alternatives_names = []
|
assert ^alternatives_names = []
|
||||||
end
|
end
|
||||||
|
|
||||||
test "book has related book so they has one alternative name", %{user: user} do
|
test "book has related book so they has one alternative name", %{user: user} do
|
||||||
@@ -187,7 +188,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert {:ok, alternatives_names} = Metadata.get_book_alternative_editions(book)
|
assert {:ok, alternatives_names} = Metadata.get_book_alternative_editions(book)
|
||||||
assert alternatives_names = [related_book]
|
assert get_ids(alternatives_names) == [related_book.id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -201,7 +202,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|||||||
%{order: 1, author_id: author.id, role: ""}
|
%{order: 1, author_id: author.id, role: ""}
|
||||||
]
|
]
|
||||||
|
|
||||||
{:ok, book} =
|
{:ok, _book} =
|
||||||
Metadata.create_book(
|
Metadata.create_book(
|
||||||
"Book",
|
"Book",
|
||||||
"An description",
|
"An description",
|
||||||
@@ -217,7 +218,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|||||||
actor: user
|
actor: user
|
||||||
)
|
)
|
||||||
|
|
||||||
assert {:ok, books} = Metadata.get_author_books(author)
|
assert {:ok, _books} = Metadata.get_author_books(author)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "get the list contains aliases' books", %{user: user} do
|
test "get the list contains aliases' books", %{user: user} do
|
||||||
@@ -256,7 +257,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "get a book by book id" do
|
describe "get a book by book id" do
|
||||||
test "get by bid", %{user: user} do
|
test "get by bid" do
|
||||||
expected_book = generate(book())
|
expected_book = generate(book())
|
||||||
|
|
||||||
[%Metadata.BookId{type: type, bid: bid} | _] = expected_book.bids
|
[%Metadata.BookId{type: type, bid: bid} | _] = expected_book.bids
|
||||||
|
|||||||
@@ -12,13 +12,8 @@ defmodule DecentralisedBookIndex.Metadata.Forms.AuthorFormTest do
|
|||||||
test "user can't submit" do
|
test "user can't submit" do
|
||||||
user = generate(user())
|
user = generate(user())
|
||||||
|
|
||||||
valid_params = %{
|
|
||||||
"name" => "Oleh",
|
|
||||||
"description" => "A cool author"
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_raise Ash.Error.Forbidden, fn ->
|
assert_raise Ash.Error.Forbidden, fn ->
|
||||||
form =
|
_form =
|
||||||
AshPhoenix.Form.for_create(Metadata.Author, :create,
|
AshPhoenix.Form.for_create(Metadata.Author, :create,
|
||||||
as: "author",
|
as: "author",
|
||||||
actor: user
|
actor: user
|
||||||
@@ -28,12 +23,7 @@ defmodule DecentralisedBookIndex.Metadata.Forms.AuthorFormTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "moderator can submit", %{user: user} do
|
test "moderator can submit", %{user: user} do
|
||||||
valid_params = %{
|
assert _form =
|
||||||
"name" => "Oleh",
|
|
||||||
"description" => "A cool author"
|
|
||||||
}
|
|
||||||
|
|
||||||
assert form =
|
|
||||||
AshPhoenix.Form.for_create(Metadata.Author, :create,
|
AshPhoenix.Form.for_create(Metadata.Author, :create,
|
||||||
as: "author",
|
as: "author",
|
||||||
actor: user
|
actor: user
|
||||||
@@ -55,7 +45,7 @@ defmodule DecentralisedBookIndex.Metadata.Forms.AuthorFormTest do
|
|||||||
actor: user
|
actor: user
|
||||||
)
|
)
|
||||||
|
|
||||||
assert {:ok, author} = AshPhoenix.Form.submit(form, params: valid_params)
|
assert {:ok, _author} = AshPhoenix.Form.submit(form, params: valid_params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -74,7 +64,7 @@ defmodule DecentralisedBookIndex.Metadata.Forms.AuthorFormTest do
|
|||||||
actor: user
|
actor: user
|
||||||
)
|
)
|
||||||
|
|
||||||
assert {:ok, author} = AshPhoenix.Form.submit(form, params: valid_params)
|
assert {:ok, _author} = AshPhoenix.Form.submit(form, params: valid_params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ defmodule DecentralisedBookIndex.Metadata.Forms.BookFormTest do
|
|||||||
import ExUnitProperties
|
import ExUnitProperties
|
||||||
|
|
||||||
alias DecentralisedBookIndex.Metadata
|
alias DecentralisedBookIndex.Metadata
|
||||||
alias DecentralisedBookIndex.Metadata.Book
|
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
user = generate(user(role: :moderator))
|
user = generate(user(role: :moderator))
|
||||||
@@ -14,22 +13,9 @@ defmodule DecentralisedBookIndex.Metadata.Forms.BookFormTest do
|
|||||||
describe "form submiting" do
|
describe "form submiting" do
|
||||||
test "user can't submit" do
|
test "user can't submit" do
|
||||||
user = generate(user())
|
user = generate(user())
|
||||||
bids = bids()
|
|
||||||
author_roles = author_roles()
|
|
||||||
|
|
||||||
valid_params = %{
|
|
||||||
"title" => "Book",
|
|
||||||
"description" => "A cool author",
|
|
||||||
"format" => "Paper",
|
|
||||||
"language" => "English",
|
|
||||||
"page_count" => 600,
|
|
||||||
"published" => ~D[2025-03-06],
|
|
||||||
"author_roles" => author_roles,
|
|
||||||
"bids" => bids
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_raise Ash.Error.Forbidden, fn ->
|
assert_raise Ash.Error.Forbidden, fn ->
|
||||||
form =
|
_form =
|
||||||
AshPhoenix.Form.for_create(Metadata.Book, :create,
|
AshPhoenix.Form.for_create(Metadata.Book, :create,
|
||||||
as: "book",
|
as: "book",
|
||||||
actor: user
|
actor: user
|
||||||
@@ -39,21 +25,7 @@ defmodule DecentralisedBookIndex.Metadata.Forms.BookFormTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "moderator can submit", %{user: user} do
|
test "moderator can submit", %{user: user} do
|
||||||
bids = bids(actor: user)
|
assert _form =
|
||||||
author_roles = author_roles(actor: user)
|
|
||||||
|
|
||||||
valid_params = %{
|
|
||||||
"title" => "Book",
|
|
||||||
"description" => "A cool author",
|
|
||||||
"format" => "Paper",
|
|
||||||
"language" => "English",
|
|
||||||
"page_count" => 600,
|
|
||||||
"published" => ~D[2025-03-06],
|
|
||||||
"author_roles" => author_roles,
|
|
||||||
"bids" => bids
|
|
||||||
}
|
|
||||||
|
|
||||||
assert form =
|
|
||||||
AshPhoenix.Form.for_create(Metadata.Book, :create,
|
AshPhoenix.Form.for_create(Metadata.Book, :create,
|
||||||
as: "book",
|
as: "book",
|
||||||
actor: user
|
actor: user
|
||||||
@@ -86,7 +58,7 @@ defmodule DecentralisedBookIndex.Metadata.Forms.BookFormTest do
|
|||||||
actor: user
|
actor: user
|
||||||
)
|
)
|
||||||
|
|
||||||
assert {:ok, user} = AshPhoenix.Form.submit(form, params: valid_params)
|
assert {:ok, _book} = AshPhoenix.Form.submit(form, params: valid_params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -106,7 +78,7 @@ defmodule DecentralisedBookIndex.Metadata.Forms.BookFormTest do
|
|||||||
actor: user
|
actor: user
|
||||||
)
|
)
|
||||||
|
|
||||||
assert {:ok, user} = AshPhoenix.Form.submit(form, params: valid_params)
|
assert {:ok, _book} = AshPhoenix.Form.submit(form, params: valid_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "update bids and authors", %{user: user} do
|
test "update bids and authors", %{user: user} do
|
||||||
@@ -125,7 +97,7 @@ defmodule DecentralisedBookIndex.Metadata.Forms.BookFormTest do
|
|||||||
actor: user
|
actor: user
|
||||||
)
|
)
|
||||||
|
|
||||||
assert {:ok, user} = AshPhoenix.Form.submit(form, params: valid_params)
|
assert {:ok, _book} = AshPhoenix.Form.submit(form, params: valid_params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -12,12 +12,8 @@ defmodule DecentralisedBookIndex.Metadata.Forms.PublisherFormTest do
|
|||||||
test "user can't submit" do
|
test "user can't submit" do
|
||||||
user = generate(user())
|
user = generate(user())
|
||||||
|
|
||||||
valid_params = %{
|
|
||||||
"name" => "Publisher"
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_raise Ash.Error.Forbidden, fn ->
|
assert_raise Ash.Error.Forbidden, fn ->
|
||||||
form =
|
_form =
|
||||||
AshPhoenix.Form.for_create(Metadata.Publisher, :create,
|
AshPhoenix.Form.for_create(Metadata.Publisher, :create,
|
||||||
as: "publisher",
|
as: "publisher",
|
||||||
actor: user
|
actor: user
|
||||||
@@ -27,11 +23,7 @@ defmodule DecentralisedBookIndex.Metadata.Forms.PublisherFormTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "moderator can submit", %{user: user} do
|
test "moderator can submit", %{user: user} do
|
||||||
valid_params = %{
|
assert _form =
|
||||||
"name" => "Publisher"
|
|
||||||
}
|
|
||||||
|
|
||||||
assert form =
|
|
||||||
AshPhoenix.Form.for_create(Metadata.Publisher, :create,
|
AshPhoenix.Form.for_create(Metadata.Publisher, :create,
|
||||||
as: "publisher",
|
as: "publisher",
|
||||||
actor: user
|
actor: user
|
||||||
|
|||||||
@@ -26,17 +26,13 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorSyncTest do
|
|||||||
updated_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 = AuthorSync.create_update(author, server.id)
|
||||||
assert {:ok, saved_author} = Metadata.get_author_by_id(author.id)
|
assert {:ok, saved_author} = Metadata.get_author_by_id(author.id)
|
||||||
|
|
||||||
author =
|
author =
|
||||||
author
|
author
|
||||||
|> Map.replace(:inserted_at, inserted_at)
|
|
||||||
|> Map.replace(:updated_at, updated_at)
|
|
||||||
|> Map.delete(:author_alias_registry_id)
|
|> Map.delete(:author_alias_registry_id)
|
||||||
|
|> datetime_from_iso8601_for_map()
|
||||||
|
|
||||||
assert get_submap(saved_author, author) == author
|
assert get_submap(saved_author, author) == author
|
||||||
assert nil != saved_author.author_alias_registry_id
|
assert nil != saved_author.author_alias_registry_id
|
||||||
@@ -56,16 +52,12 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorSyncTest do
|
|||||||
updated_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 = AuthorSync.create_update(author, server.id)
|
||||||
assert {:ok, saved_author} = Metadata.get_author_by_id(author.id)
|
assert {:ok, saved_author} = Metadata.get_author_by_id(author.id)
|
||||||
|
|
||||||
author =
|
author =
|
||||||
author
|
author
|
||||||
|> Map.replace(:inserted_at, inserted_at)
|
|> datetime_from_iso8601_for_map()
|
||||||
|> Map.replace(:updated_at, updated_at)
|
|
||||||
|
|
||||||
assert get_submap(saved_author, author) == author
|
assert get_submap(saved_author, author) == author
|
||||||
assert nil != saved_author.author_alias_registry_id
|
assert nil != saved_author.author_alias_registry_id
|
||||||
@@ -88,7 +80,7 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorSyncTest do
|
|||||||
assert :ok = AuthorSync.create_update(author_attrs, server.id)
|
assert :ok = AuthorSync.create_update(author_attrs, server.id)
|
||||||
assert {:ok, saved_author} = Metadata.get_author_by_id(author.id)
|
assert {:ok, saved_author} = Metadata.get_author_by_id(author.id)
|
||||||
|
|
||||||
assert author = saved_author
|
assert get_submap(author, author_attrs) == get_submap(saved_author, author_attrs)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "the local existing author wouldn't updated", %{user: user} do
|
test "the local existing author wouldn't updated", %{user: user} do
|
||||||
|
|||||||
@@ -32,20 +32,17 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.BookSyncTest do
|
|||||||
updated_at: "2025-04-01T18:14:25.754055Z"
|
updated_at: "2025-04-01T18:14:25.754055Z"
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, inserted_at, 0} = DateTime.from_iso8601(book[:inserted_at])
|
|
||||||
{:ok, updated_at, 0} = DateTime.from_iso8601(book[:updated_at])
|
|
||||||
|
|
||||||
assert :ok = BookSync.create_update(book, server.id)
|
assert :ok = BookSync.create_update(book, server.id)
|
||||||
assert {:ok, saved_book} = Metadata.get_book_by_id(book.id)
|
assert {:ok, saved_book} = Metadata.get_book_by_id(book.id)
|
||||||
|
|
||||||
book =
|
book =
|
||||||
book
|
book
|
||||||
|> Map.replace(:inserted_at, inserted_at)
|
|> datetime_from_iso8601_for_map()
|
||||||
|> Map.replace(:updated_at, updated_at)
|
|
||||||
|> Map.replace(:published, Date.from_iso8601!(book[:published]))
|
|> Map.replace(:published, Date.from_iso8601!(book[:published]))
|
||||||
|
|
||||||
assert nil != saved_book.book_editions_registry_id
|
assert nil != saved_book.book_editions_registry_id
|
||||||
assert server.id == saved_book.dbi_server_id
|
assert server.id == saved_book.dbi_server_id
|
||||||
|
assert get_submap(saved_book, book) == book
|
||||||
end
|
end
|
||||||
|
|
||||||
test "a new book has the same editions registry" do
|
test "a new book has the same editions registry" do
|
||||||
@@ -68,20 +65,17 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.BookSyncTest do
|
|||||||
book_editions_registry_id: "1ed81d9e-3757-472a-aa3b-44fcdfbe770a"
|
book_editions_registry_id: "1ed81d9e-3757-472a-aa3b-44fcdfbe770a"
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, inserted_at, 0} = DateTime.from_iso8601(book[:inserted_at])
|
|
||||||
{:ok, updated_at, 0} = DateTime.from_iso8601(book[:updated_at])
|
|
||||||
|
|
||||||
assert :ok = BookSync.create_update(book, server.id)
|
assert :ok = BookSync.create_update(book, server.id)
|
||||||
assert {:ok, saved_book} = Metadata.get_book_by_id(book.id)
|
assert {:ok, saved_book} = Metadata.get_book_by_id(book.id)
|
||||||
|
|
||||||
book =
|
book =
|
||||||
book
|
book
|
||||||
|> Map.replace(:inserted_at, inserted_at)
|
|> datetime_from_iso8601_for_map()
|
||||||
|> Map.replace(:updated_at, updated_at)
|
|
||||||
|> Map.replace(:published, Date.from_iso8601!(book[:published]))
|
|> Map.replace(:published, Date.from_iso8601!(book[:published]))
|
||||||
|
|
||||||
assert nil != saved_book.book_editions_registry_id
|
assert nil != saved_book.book_editions_registry_id
|
||||||
assert server.id == saved_book.dbi_server_id
|
assert server.id == saved_book.dbi_server_id
|
||||||
|
assert get_submap(saved_book, book) == book
|
||||||
end
|
end
|
||||||
|
|
||||||
test "a new book with relationships will be created" do
|
test "a new book with relationships will be created" do
|
||||||
@@ -166,10 +160,10 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.BookSyncTest do
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert :ok = BookSync.create_update(book_attrs, server.id)
|
assert :ok = BookSync.create_update(book_attrs, server.id)
|
||||||
assert {:ok, saved_book} = Metadata.get_book_by_id(book.id)
|
assert {:ok, _saved_book} = Metadata.get_book_by_id(book.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "the local existing book wouldn't updated", %{user: user} do
|
test "the local existing book wouldn't updated" do
|
||||||
server = generate(dbi_server(url: @test_server_endpoint))
|
server = generate(dbi_server(url: @test_server_endpoint))
|
||||||
|
|
||||||
book = generate(book())
|
book = generate(book())
|
||||||
@@ -195,7 +189,7 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.BookSyncTest do
|
|||||||
assert saved_book.dbi_server_id == nil
|
assert saved_book.dbi_server_id == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
test "old book wouldn't be sync", %{user: user} do
|
test "old book wouldn't be sync" do
|
||||||
server = generate(dbi_server(url: @test_server_endpoint))
|
server = generate(dbi_server(url: @test_server_endpoint))
|
||||||
|
|
||||||
book = generate(book())
|
book = generate(book())
|
||||||
@@ -347,11 +341,4 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.BookSyncTest do
|
|||||||
assert Enum.all?(old_roles, fn id -> id not in new_roles end)
|
assert Enum.all?(old_roles, fn id -> id not in new_roles end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_ids(records) do
|
|
||||||
Enum.map(records, fn record -> get_id(record) end)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp get_id(record) when is_struct(record), do: record.id
|
|
||||||
defp get_id(record) when is_map(record), do: record[:id]
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.DBIServerSyncTest do
|
|||||||
server = generate(dbi_server(url: @test_server_endpoint))
|
server = generate(dbi_server(url: @test_server_endpoint))
|
||||||
|
|
||||||
dbi_server = %{
|
dbi_server = %{
|
||||||
id: "0c0647ec-07ef-4caa-b683-5847dbfbe5cc",
|
id: "0c0647ec-07ef-4caa-b683-5847dbfbe5cc",
|
||||||
name: "Test",
|
name: "Test",
|
||||||
url: "http://localhost:4001",
|
url: "http://localhost:4001",
|
||||||
inserted_at: "2025-03-22T20:07:30.766249Z",
|
inserted_at: "2025-03-22T20:07:30.766249Z",
|
||||||
updated_at: "2025-05-04T18:48:44.213309Z"
|
updated_at: "2025-05-04T18:48:44.213309Z"
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, inserted_at, 0} = DateTime.from_iso8601(dbi_server[:inserted_at])
|
{:ok, inserted_at, 0} = DateTime.from_iso8601(dbi_server[:inserted_at])
|
||||||
@@ -35,27 +35,30 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.DBIServerSyncTest do
|
|||||||
|> Map.replace(:inserted_at, inserted_at)
|
|> Map.replace(:inserted_at, inserted_at)
|
||||||
|> Map.replace(:updated_at, updated_at)
|
|> Map.replace(:updated_at, updated_at)
|
||||||
|
|
||||||
assert dbi_server = saved_dbi_server
|
assert dbi_server == get_submap(saved_dbi_server, dbi_server)
|
||||||
assert server.id == saved_dbi_server.dbi_server_id
|
assert server.id == saved_dbi_server.dbi_server_id
|
||||||
end
|
end
|
||||||
|
|
||||||
test "update an existing dbi_server", %{user: user} do
|
test "update an existing dbi_server", %{user: user} do
|
||||||
server = generate(dbi_server(url: @test_server_endpoint))
|
server = generate(dbi_server(url: @test_server_endpoint))
|
||||||
|
|
||||||
{:ok, dbi_server} = Metadata.create_dbi_server("Test", "http://localhost:4001", false, actor: user)
|
{:ok, dbi_server} =
|
||||||
|
Metadata.create_dbi_server("Test", "http://localhost:4001", false, actor: user)
|
||||||
|
|
||||||
dbi_server_attrs = %{
|
dbi_server_attrs = %{
|
||||||
id: dbi_server.id,
|
id: dbi_server.id,
|
||||||
name: "Test",
|
name: "Test",
|
||||||
url: "http://localhost:4001",
|
url: "http://localhost:4001",
|
||||||
inserted_at: "2025-03-22T20:07:30.766249Z",
|
inserted_at: "2025-03-22T20:07:30.766249Z",
|
||||||
updated_at: "2025-05-04T18:48:44.213309Z"
|
updated_at: "2025-05-04T18:48:44.213309Z"
|
||||||
}
|
}
|
||||||
|
|
||||||
assert :ok = DBIServerSync.create_update(dbi_server_attrs, server.id)
|
assert :ok = DBIServerSync.create_update(dbi_server_attrs, server.id)
|
||||||
assert {:ok, saved_dbi_server} = Metadata.get_dbi_server_by_id(dbi_server.id)
|
assert {:ok, saved_dbi_server} = Metadata.get_dbi_server_by_id(dbi_server.id)
|
||||||
|
|
||||||
assert dbi_server_attrs = saved_dbi_server
|
assert datetime_from_iso8601_for_map(dbi_server_attrs) ==
|
||||||
|
get_submap(saved_dbi_server, dbi_server_attrs)
|
||||||
|
|
||||||
assert server.id == saved_dbi_server.dbi_server_id
|
assert server.id == saved_dbi_server.dbi_server_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,9 +23,6 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.PublisherSyncTest do
|
|||||||
updated_at: "2025-03-21T09:20:48.791539Z"
|
updated_at: "2025-03-21T09:20:48.791539Z"
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, inserted_at, 0} = DateTime.from_iso8601(publisher[:inserted_at])
|
|
||||||
{:ok, updated_at, 0} = DateTime.from_iso8601(publisher[:updated_at])
|
|
||||||
|
|
||||||
assert :ok = PublisherSync.create_update(publisher, server.id)
|
assert :ok = PublisherSync.create_update(publisher, server.id)
|
||||||
assert {:ok, saved_publisher} = Metadata.get_publisher_by_id(publisher.id)
|
assert {:ok, saved_publisher} = Metadata.get_publisher_by_id(publisher.id)
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ defmodule DecentralisedBookIndex.SyncTasks.SyncAuthorsTaskTest do
|
|||||||
test "sync authors", %{user: user} 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", nil, nil, actor: user)
|
{:ok, _author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
||||||
{:ok, author} = Metadata.create_author("Author2", "An description", nil, nil, actor: user)
|
{:ok, _author} = Metadata.create_author("Author2", "An description", nil, nil, actor: user)
|
||||||
|
|
||||||
assert server = SyncAuthorsTask.sync(server)
|
assert ^server = SyncAuthorsTask.sync(server)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ defmodule DecentralisedBookIndex.SyncTasks.SyncBookTaskTest do
|
|||||||
use DecentralisedBookIndex.DataCase
|
use DecentralisedBookIndex.DataCase
|
||||||
|
|
||||||
alias DecentralisedBookIndex.SyncTasks.SyncBooksTask
|
alias DecentralisedBookIndex.SyncTasks.SyncBooksTask
|
||||||
alias DecentralisedBookIndex.Metadata
|
|
||||||
|
|
||||||
alias DecentralisedBookIndex.TestEndpoints
|
alias DecentralisedBookIndex.TestEndpoints
|
||||||
@test_server_endpoint TestEndpoints.test_api_endpoint()
|
@test_server_endpoint TestEndpoints.test_api_endpoint()
|
||||||
@@ -14,7 +13,7 @@ defmodule DecentralisedBookIndex.SyncTasks.SyncBookTaskTest do
|
|||||||
_book = generate(book())
|
_book = generate(book())
|
||||||
_book = generate(book())
|
_book = generate(book())
|
||||||
|
|
||||||
assert server = SyncBooksTask.sync(server)
|
assert ^server = SyncBooksTask.sync(server)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ defmodule DecentralisedBookIndex.SyncTasks.SyncDBIServerTaskTest do
|
|||||||
{:ok, _dbi_server} = Metadata.create_dbi_server("Test", "http://localhost:4001", false, actor: user)
|
{:ok, _dbi_server} = Metadata.create_dbi_server("Test", "http://localhost:4001", false, actor: user)
|
||||||
{:ok, _dbi_server} = Metadata.create_dbi_server("Test2", "http://localhost:4001", false, actor: user)
|
{:ok, _dbi_server} = Metadata.create_dbi_server("Test2", "http://localhost:4001", false, actor: user)
|
||||||
|
|
||||||
assert server = SyncDBIServerTask.sync(server)
|
assert ^server = SyncDBIServerTask.sync(server)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ defmodule DecentralisedBookIndex.SyncTasks.SyncPublishersTaskTest do
|
|||||||
{:ok, _publisher} = Metadata.create_publisher("Publisher", actor: user)
|
{:ok, _publisher} = Metadata.create_publisher("Publisher", actor: user)
|
||||||
{:ok, _publisher} = Metadata.create_publisher("Publisher2", actor: user)
|
{:ok, _publisher} = Metadata.create_publisher("Publisher2", actor: user)
|
||||||
|
|
||||||
assert server = SyncPublishersTask.sync(server)
|
assert ^server = SyncPublishersTask.sync(server)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ defmodule DecentralisedBookIndex.SyncTasks.SyncServerTaskTest do
|
|||||||
|
|
||||||
alias DecentralisedBookIndex.SyncTasks.SyncServerTask
|
alias DecentralisedBookIndex.SyncTasks.SyncServerTask
|
||||||
|
|
||||||
alias DecentralisedBookIndex.Sync.ApiClients.FetchJson
|
|
||||||
alias DecentralisedBookIndex.Sync.AuthorSync
|
|
||||||
|
|
||||||
alias DecentralisedBookIndex.Metadata
|
alias DecentralisedBookIndex.Metadata
|
||||||
|
|
||||||
alias DecentralisedBookIndex.TestEndpoints
|
alias DecentralisedBookIndex.TestEndpoints
|
||||||
@@ -18,19 +15,19 @@ defmodule DecentralisedBookIndex.SyncTasks.SyncServerTaskTest do
|
|||||||
|
|
||||||
describe "sync all" do
|
describe "sync all" do
|
||||||
test "servers", %{user: user} 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", nil, nil, actor: user)
|
{:ok, _author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
||||||
|
|
||||||
assert server = SyncServerTask.sync_all()
|
assert :ok = SyncServerTask.sync_all()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "sync one" do
|
describe "sync one" do
|
||||||
test "server", %{user: user} 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", nil, nil, actor: user)
|
{:ok, _author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
||||||
|
|
||||||
assert server = SyncServerTask.sync_one(server)
|
assert :ok = SyncServerTask.sync_one(server)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ defmodule DecentralisedBookIndexWeb.LiveViewsPermissionsTest do
|
|||||||
for user <- [moderator, admin] do
|
for user <- [moderator, admin] do
|
||||||
assert {:ok, _view, html} =
|
assert {:ok, _view, html} =
|
||||||
conn
|
conn
|
||||||
|> log_in_user(moderator)
|
|> log_in_user(user)
|
||||||
|> live("/publishers")
|
|> live("/publishers")
|
||||||
|
|
||||||
assert html =~ "Listing Publishers"
|
assert html =~ "Listing Publishers"
|
||||||
@@ -303,12 +303,11 @@ defmodule DecentralisedBookIndexWeb.LiveViewsPermissionsTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "Server Index /servers" do
|
describe "Server Index /servers" do
|
||||||
test "can't be accessed by regular user and moderator", %{
|
test "can't be accessed by regular user", %{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
user: user,
|
user: user
|
||||||
moderator: moderator
|
|
||||||
} do
|
} do
|
||||||
for user <- [nil, user, moderator] do
|
for user <- [nil, user] do
|
||||||
assert {:error, {:redirect, %{flash: %{"error" => "Unauthorized!"}, to: "/"}}} =
|
assert {:error, {:redirect, %{flash: %{"error" => "Unauthorized!"}, to: "/"}}} =
|
||||||
conn
|
conn
|
||||||
|> log_in_user(user)
|
|> log_in_user(user)
|
||||||
@@ -316,11 +315,15 @@ defmodule DecentralisedBookIndexWeb.LiveViewsPermissionsTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "can be accessed by admin", %{conn: conn, admin: admin} do
|
test "can be accessed by moderator and admin", %{
|
||||||
for user <- [admin] do
|
conn: conn,
|
||||||
|
moderator: moderator,
|
||||||
|
admin: admin
|
||||||
|
} do
|
||||||
|
for user <- [moderator, admin] do
|
||||||
assert {:ok, _view, html} =
|
assert {:ok, _view, html} =
|
||||||
conn
|
conn
|
||||||
|> log_in_user(admin)
|
|> log_in_user(user)
|
||||||
|> live("/servers")
|
|> live("/servers")
|
||||||
|
|
||||||
assert html =~ "Listing Servers"
|
assert html =~ "Listing Servers"
|
||||||
@@ -333,13 +336,12 @@ defmodule DecentralisedBookIndexWeb.LiveViewsPermissionsTest do
|
|||||||
%{server: generate(dbi_server())}
|
%{server: generate(dbi_server())}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "can't be accessed by non-admin user", %{
|
test "can't be accessed by non-moderator user", %{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
user: user,
|
user: user,
|
||||||
moderator: moderator,
|
|
||||||
server: server
|
server: server
|
||||||
} do
|
} do
|
||||||
for user <- [nil, user, moderator] do
|
for user <- [nil, user] do
|
||||||
assert {:error, {:redirect, %{flash: %{"error" => "Unauthorized!"}, to: "/"}}} =
|
assert {:error, {:redirect, %{flash: %{"error" => "Unauthorized!"}, to: "/"}}} =
|
||||||
conn
|
conn
|
||||||
|> log_in_user(user)
|
|> log_in_user(user)
|
||||||
@@ -347,8 +349,13 @@ defmodule DecentralisedBookIndexWeb.LiveViewsPermissionsTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "can be accessed by admin", %{conn: conn, admin: admin, server: server} do
|
test "can be accessed by admin", %{
|
||||||
for user <- [admin] do
|
conn: conn,
|
||||||
|
moderator: moderator,
|
||||||
|
admin: admin,
|
||||||
|
server: server
|
||||||
|
} do
|
||||||
|
for user <- [moderator, admin] do
|
||||||
{:ok, _view, html} =
|
{:ok, _view, html} =
|
||||||
conn
|
conn
|
||||||
|> log_in_user(user)
|
|> log_in_user(user)
|
||||||
@@ -445,7 +452,7 @@ defmodule DecentralisedBookIndexWeb.LiveViewsPermissionsTest do
|
|||||||
for user <- [admin] do
|
for user <- [admin] do
|
||||||
assert {:ok, _view, html} =
|
assert {:ok, _view, html} =
|
||||||
conn
|
conn
|
||||||
|> log_in_user(admin)
|
|> log_in_user(user)
|
||||||
|> live("/users")
|
|> live("/users")
|
||||||
|
|
||||||
assert html =~ "Listing Users"
|
assert html =~ "Listing Users"
|
||||||
|
|||||||
@@ -41,6 +41,13 @@ defmodule DecentralisedBookIndex.Helpers do
|
|||||||
|> DateTime.to_iso8601()
|
|> DateTime.to_iso8601()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_ids(records) do
|
||||||
|
Enum.map(records, fn record -> get_id(record) end)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_id(record) when is_struct(record), do: record.id
|
||||||
|
def get_id(record) when is_map(record), do: record[:id]
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Logs the given `user` into the `conn`.
|
Logs the given `user` into the `conn`.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user