diff --git a/lib/trento_web/openapi/v1/schema/activity_log.ex b/lib/trento_web/openapi/v1/schema/activity_log.ex index 5e44160a31..69357033ac 100644 --- a/lib/trento_web/openapi/v1/schema/activity_log.ex +++ b/lib/trento_web/openapi/v1/schema/activity_log.ex @@ -13,6 +13,11 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ActivityLog do type: :object, additionalProperties: false, properties: %{ + id: %Schema{ + type: :string, + description: "Identifier of Activity Log entry.", + format: :uuid + }, type: %Schema{ type: :string, description: "Type of Activity Log entry." @@ -29,7 +34,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ActivityLog do description: "Timestamp upon Activity Log entry insertion." } }, - required: [:type, :actor, :metadata, :occurred_on] + required: [:id, :type, :actor, :metadata, :occurred_on] } }) end diff --git a/lib/trento_web/views/v1/activity_log_view.ex b/lib/trento_web/views/v1/activity_log_view.ex index 63aff847c3..75622be091 100644 --- a/lib/trento_web/views/v1/activity_log_view.ex +++ b/lib/trento_web/views/v1/activity_log_view.ex @@ -2,11 +2,12 @@ defmodule TrentoWeb.V1.ActivityLogView do use TrentoWeb, :view def render("activity_log.json", %{activity_log: entries}) do - render_many(entries, __MODULE__, "activity_log_entry.json", as: :entries) + render_many(entries, __MODULE__, "activity_log_entry.json", as: :activity_log_entry) end - def render("activity_log_entry.json", %{entries: entry}) do + def render("activity_log_entry.json", %{activity_log_entry: entry}) do %{ + id: entry.id, type: entry.type, actor: entry.actor, metadata: entry.metadata, diff --git a/test/trento_web/views/v1/activity_log_view_test.exs b/test/trento_web/views/v1/activity_log_view_test.exs new file mode 100644 index 0000000000..ee2ddab0a6 --- /dev/null +++ b/test/trento_web/views/v1/activity_log_view_test.exs @@ -0,0 +1,67 @@ +defmodule TrentoWeb.V1.ActivityLogViewTest do + use ExUnit.Case + + import Phoenix.View + + import Trento.Factory + + alias Trento.ActivityLog.ActivityLog + alias TrentoWeb.V1.ActivityLogView + + test "should render activity_log.json" do + [ + %ActivityLog{ + id: id1, + type: type1, + actor: actor1, + metadata: metadata1, + inserted_at: inserted_at1 + }, + %ActivityLog{ + id: id2, + type: type2, + actor: actor2, + metadata: metadata2, + inserted_at: inserted_at2 + } + ] = activity_log = build_list(2, :activity_log_entry) + + assert [ + %{ + id: ^id1, + type: ^type1, + actor: ^actor1, + metadata: ^metadata1, + occurred_on: ^inserted_at1 + }, + %{ + id: ^id2, + type: ^type2, + actor: ^actor2, + metadata: ^metadata2, + occurred_on: ^inserted_at2 + } + ] = render(ActivityLogView, "activity_log.json", %{activity_log: activity_log}) + end + + test "should render activity_log_entry.json" do + %ActivityLog{ + id: id, + type: type, + actor: actor, + metadata: metadata, + inserted_at: inserted_at + } = activity_log_entry = build(:activity_log_entry) + + assert %{ + id: ^id, + type: ^type, + actor: ^actor, + metadata: ^metadata, + occurred_on: ^inserted_at + } = + render(ActivityLogView, "activity_log_entry.json", %{ + activity_log_entry: activity_log_entry + }) + end +end