* Remove feature flag * Remove Pusher Beams implementation * Remove Pusher Beams require from initializer * Adds consumer apps to sidebar + consider :admin_restructure * Fix routes + PN target URL * Remove old file that sneaked in * Adds docs * docs tweaks * Apply suggestions from code review Co-authored-by: rhymes <rhymes@hey.com> Co-authored-by: rhymes <rhymes@hey.com>
79 lines
2.5 KiB
Ruby
79 lines
2.5 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe PushNotifications::Send, type: :service do
|
|
let(:user) { create(:user) }
|
|
let(:user2) { create(:user) }
|
|
let(:params) do
|
|
{
|
|
user_ids: [user.id],
|
|
title: "Alert",
|
|
body: "some alert here",
|
|
payload: ""
|
|
}
|
|
end
|
|
let(:many_targets_params) do
|
|
{
|
|
user_ids: [user.id, user2.id],
|
|
title: "Alert 2",
|
|
body: "some other alert",
|
|
payload: ""
|
|
}
|
|
end
|
|
|
|
context "with no devices for user" do
|
|
before do
|
|
user.devices.delete
|
|
end
|
|
|
|
it "does nothing", :aggregate_failures do
|
|
expect(user.devices.count).to eq(0)
|
|
expect { described_class.call(**params) }
|
|
.not_to change { Rpush::Client::Redis::Notification.all.count }
|
|
end
|
|
end
|
|
|
|
context "with devices for one user" do
|
|
before do
|
|
allow(ApplicationConfig).to receive(:[]).with("RPUSH_IOS_PEM").and_return("dGVzdGluZw==")
|
|
allow(ApplicationConfig).to receive(:[]).with("COMMUNITY_NAME").and_return("Forem")
|
|
create(:device, user: user)
|
|
end
|
|
|
|
it "creates a notification and enqueues it" do
|
|
expect { described_class.call(**params) }
|
|
.to change { Rpush::Client::Redis::Notification.all.count }.by(1)
|
|
.and change(PushNotifications::DeliverWorker.jobs, :size).by(1)
|
|
end
|
|
|
|
it "creates a single notification for each of the user's devices when they have multiple" do
|
|
create(:device, user: user)
|
|
|
|
expect { described_class.call(**params) }
|
|
.to change { Rpush::Client::Redis::Notification.all.count }.by(2)
|
|
.and change(PushNotifications::DeliverWorker.jobs, :size).by(1)
|
|
end
|
|
end
|
|
|
|
context "with devices for multiple users" do
|
|
before do
|
|
allow(ApplicationConfig).to receive(:[]).with("RPUSH_IOS_PEM").and_return("dGVzdGluZw==")
|
|
allow(ApplicationConfig).to receive(:[]).with("COMMUNITY_NAME").and_return("Forem")
|
|
create(:device, user: user)
|
|
create(:device, user: user2)
|
|
end
|
|
|
|
it "creates a notification and enqueues it" do
|
|
expect { described_class.call(**many_targets_params) }
|
|
.to change { Rpush::Client::Redis::Notification.all.count }.by(2)
|
|
.and change { PushNotifications::DeliverWorker.jobs.size }.by(1)
|
|
end
|
|
|
|
it "creates a single notification for each of the user's devices when they have multiple" do
|
|
create(:device, user: user)
|
|
|
|
expect { described_class.call(**many_targets_params) }
|
|
.to change { Rpush::Client::Redis::Notification.all.count }.by(3)
|
|
.and change { PushNotifications::DeliverWorker.jobs.size }.by(1)
|
|
end
|
|
end
|
|
end
|