Add tests for subscriptions

This commit is contained in:
Sadposter 2019-04-05 15:14:19 +01:00 committed by Hannah Ward
parent 316fe20d86
commit 75c4ceb4a2
1 changed files with 22 additions and 0 deletions

View File

@ -29,6 +29,18 @@ test "notifies someone when they are directly addressed" do
assert notification.activity_id == activity.id
assert other_notification.activity_id == activity.id
end
test "it creates a notification for subscribed users" do
user = insert(:user)
subscriber = insert(:user)
{:ok, _, _} = TwitterAPI.subscribe(subscriber, %{"user_id" => user.id})
{:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
{:ok, [notification]} = Notification.create_notifications(status)
assert notification.user_id == subscriber.id
end
end
describe "create_notification" do
@ -84,6 +96,16 @@ test "it doesn't create a notification for repeat-unrepeat-repeat chains" do
{:ok, dupe} = TwitterAPI.repeat(user, status.id)
assert nil == Notification.create_notification(dupe, retweeted_user)
end
test "it doesn't create duplicate notifications for follow+subscribed users" do
user = insert(:user)
subscriber = insert(:user)
{:ok, _, _, _} = TwitterAPI.follow(subscriber, %{"user_id" => user.id})
{:ok, _, _} = TwitterAPI.subscribe(subscriber, %{"user_id" => user.id})
{:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
{:ok, [_notif]} = Notification.create_notifications(status)
end
end
describe "get notification" do