discourse/spec/services/push_notification_pusher_spec.rb
Vinoth Kannan 0e65c2b3c8
FIX: send notification in user's locale if available. (#12215)
Previously, it was sending notifications in site's default locale.
2021-02-25 23:40:37 +05:30

46 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe PushNotificationPusher do
it "returns badges url by default" do
expect(PushNotificationPusher.get_badge).to eq("/assets/push-notifications/discourse.png")
end
it "returns custom badges url" do
upload = Fabricate(:upload)
SiteSetting.push_notifications_icon = upload
expect(PushNotificationPusher.get_badge)
.to eq(UrlHelper.absolute(upload.url))
end
it "sends notification in user's locale" do
SiteSetting.allow_user_locale = true
user = Fabricate(:user, locale: 'pt_BR')
PushSubscription.create!(user_id: user.id, data: "{\"endpoint\": \"endpoint\"}")
PushNotificationPusher.expects(:send_notification).with(user, { "endpoint" => "endpoint" }, {
title: "system mencionou você em \"Topic\" - Discourse",
body: "description",
badge: "/assets/push-notifications/discourse.png",
icon: "/assets/push-notifications/mentioned.png",
tag: "test.localhost-1",
base_url: "http://test.localhost",
url: "https://example.com/t/1/2",
hide_when_active: true
}).once
PushNotificationPusher.push(user, {
topic_title: 'Topic',
username: 'system',
excerpt: 'description',
topic_id: 1,
post_url: "https://example.com/t/1/2",
notification_type: 1
})
end
end