Update updated_at field on notification read
This commit is contained in:
parent
0cd4b6024d
commit
dc21181f65
2 changed files with 27 additions and 1 deletions
|
@ -58,7 +58,10 @@ def set_read_up_to(%{id: user_id} = _user, id) do
|
|||
where: n.user_id == ^user_id,
|
||||
where: n.id <= ^id,
|
||||
update: [
|
||||
set: [seen: true]
|
||||
set: [
|
||||
seen: true,
|
||||
updated_at: ^NaiveDateTime.utc_now()
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -300,6 +300,29 @@ test "it sets all notifications as read up to a specified notification ID" do
|
|||
assert n2.seen == true
|
||||
assert n3.seen == false
|
||||
end
|
||||
|
||||
test "Updates `updated_at` field" do
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
Enum.each(0..10, fn i ->
|
||||
{:ok, _activity} =
|
||||
TwitterAPI.create_status(user1, %{
|
||||
"status" => "#{i} hi @#{user2.nickname}"
|
||||
})
|
||||
end)
|
||||
|
||||
Process.sleep(1000)
|
||||
|
||||
[notification | _] = Notification.for_user(user2)
|
||||
|
||||
Notification.set_read_up_to(user2, notification.id)
|
||||
|
||||
Notification.for_user(user2)
|
||||
|> Enum.each(fn notification ->
|
||||
assert notification.updated_at > notification.inserted_at
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
describe "notification target determination" do
|
||||
|
|
Loading…
Reference in a new issue