From 44112c5449a33e3a46d83b56b8901d8b72d7d79f Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Fri, 23 Dec 2022 13:03:28 +0000 Subject: [PATCH] Test for sending notifications for new questions --- spec/workers/question_worker_spec.rb | 36 +++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/spec/workers/question_worker_spec.rb b/spec/workers/question_worker_spec.rb index ab1e2914..584baac7 100644 --- a/spec/workers/question_worker_spec.rb +++ b/spec/workers/question_worker_spec.rb @@ -43,8 +43,8 @@ describe QuestionWorker do it "respects inbox locks" do user.followers.first.update(privacy_lock_inbox: true) - - + + expect { subject } .to( change { Inbox.where(user_id: user.followers.ids, question_id:, new: true).count } @@ -52,7 +52,7 @@ describe QuestionWorker do .to(4) ) end - + it "does not send questions to banned users" do user.followers.first.ban @@ -63,5 +63,35 @@ describe QuestionWorker do .to(4) ) end + + context "receiver has push notifications enabled" do + let(:receiver) { FactoryBot.create(:user) } + + before do + Rpush::Webpush::App.create( + name: "webpush", + certificate: { public_key: "AAAA", private_key: "AAAA", subject: "" }.to_json, + connections: 1, + ) + + WebPushSubscription.create!( + user: receiver, + subscription: { + endpoint: "This will not be used", + keys: {}, + }, + ) + receiver.follow(user) + end + + it "sends notifications" do + expect { subject } + .to( + change { Rpush::Webpush::Notification.count } + .from(0) + .to(1) + ) + end + end end end