Skip to content

Commit

Permalink
test(controllers/notification): add setup for notification test
Browse files Browse the repository at this point in the history
  • Loading branch information
akinsey committed Nov 3, 2023
1 parent e592c24 commit 74559b4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/epochtalk_server/models/mention.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ defmodule EpochtalkServer.Models.Mention do
def create_changeset(mention, attrs) do
now = NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)

attrs =
attrs
mention =
mention
|> Map.put(:created_at, now)

mention
Expand Down
44 changes: 44 additions & 0 deletions test/epochtalk_server_web/controllers/notification_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
defmodule Test.EpochtalkServerWeb.Controllers.Notification do
use Test.Support.ConnCase, async: true
import Test.Support.Factory
alias EpochtalkServer.Models.Mention
alias EpochtalkServer.Models.Notification

setup %{users: %{user: user, admin_user: admin_user}} do
board = insert(:board)
category = insert(:category)

build(:board_mapping,
attributes: [
[category: category, view_order: 0],
[board: board, category: category, view_order: 1]
]
)

[thread_data] = build_list(1, :thread, board: board, user: user)

post_id = thread_data.post.id
thread_id = thread_data.post.thread_id

mention = %{
"thread_id" => thread_id,
"post_id" => post_id,
"mentioner_id" => user.id,
"mentionee_id" => admin_user.id
}

# create mention
{:ok, mention} = Mention.create(mention)

notification = %{
"sender_id" => user.id,
"receiver_id" => admin_user.id,
"type" => "user",
"data" => %{
action: "refreshMentions",
mention_id: mention.id
}
}

# create notification associated with mention (for mentions dropdown)
Notification.create(notification)

:ok
end

describe "counts/2" do
test "when unauthenticated, returns Unauthorized error", %{conn: conn} do
response =
Expand Down

0 comments on commit 74559b4

Please sign in to comment.