discourse/spec/controllers/push_notification_controller_spec.rb
Jeff Wong 91b31860a1
Feature: Push notifications for Android (#5792)
* 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.
2018-05-04 15:31:48 -07:00

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