Skip to content

Commit

Permalink
Expose id as part of an activity log entry
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonkopliku committed Jul 12, 2024
1 parent ffe1973 commit b50a668
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/trento_web/openapi/v1/schema/activity_log.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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
5 changes: 3 additions & 2 deletions lib/trento_web/views/v1/activity_log_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
67 changes: 67 additions & 0 deletions test/trento_web/views/v1/activity_log_view_test.exs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b50a668

Please sign in to comment.