mirror of
https://github.com/discourse/discourse.git
synced 2025-03-26 03:06:39 +08:00

* Feature: Push notifications for Android Notification config for desktop and mobile are merged. Desktop notifications stay as they are for desktop views. If mobile mode, push notifications are enabled. Added push notification subscriptions in their own table, rather than through custom fields. Notification banner prompts appear for both mobile and desktop when enabled.
49 lines
1.6 KiB
Ruby
49 lines
1.6 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe PushNotificationController do
|
|
|
|
context "logged out" do
|
|
it "should not allow subscribe" do
|
|
get :subscribe, params: { username: "test", subscription: { endpoint: "endpoint", keys: { p256dh: "256dh", auth: "auth" } }, send_confirmation: false, format: :json }, format: :json
|
|
expect(response).not_to be_success
|
|
json = JSON.parse(response.body)
|
|
|
|
expect(response).not_to be_success
|
|
end
|
|
end
|
|
|
|
context "logged in" do
|
|
|
|
let(:user) { log_in }
|
|
|
|
it "should subscribe" do
|
|
get :subscribe, params: { username: user.username, subscription: { endpoint: "endpoint", keys: { p256dh: "256dh", auth: "auth" } }, send_confirmation: false, format: :json }, format: :json
|
|
expect(response).to be_success
|
|
json = JSON.parse(response.body)
|
|
|
|
expect(response).to be_success
|
|
end
|
|
|
|
it "should unsubscribe with existing subscription" do
|
|
sub = { endpoint: "endpoint", keys: { p256dh: "256dh", auth: "auth" } }
|
|
PushSubscription.create(user: user, data: sub.to_json)
|
|
|
|
get :unsubscribe, params: { username: user.username, subscription: sub, format: :json }, format: :json
|
|
expect(response).to be_success
|
|
json = JSON.parse(response.body)
|
|
|
|
expect(response).to be_success
|
|
end
|
|
|
|
it "should unsubscribe without subscription" do
|
|
|
|
get :unsubscribe, params: { username: user.username, subscription: { endpoint: "endpoint", keys: { p256dh: "256dh", auth: "auth" } }, format: :json }, format: :json
|
|
expect(response).to be_success
|
|
json = JSON.parse(response.body)
|
|
|
|
expect(response).to be_success
|
|
end
|
|
end
|
|
|
|
end
|