ref: master
plugins/push_notification/test/unit/notification_settings_test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
require_relative '../../lib/push_notification_helper.rb' require 'test_helper' class NotificationSettingsTest < ActiveSupport::TestCase include PushNotificationHelper should 'list notifications options in a hash' do user = User.create!(:login => 'homer', :email => 'homer@example.com', :password => 'beer', :password_confirmation => 'beer', :environment => Environment.default) user.activate settings = PushNotificationPlugin::NotificationSettings.create!(:user => user) user.reload assert_equivalent PushNotificationPlugin::NotificationSettings::NOTIFICATIONS.keys, settings.hash_flags.keys settings.hash_flags.each_pair do |notification, status| assert !!status == status end end should 'all notifications be disabled by default for new settingss' do user = User.create!(:login => 'outro', :email => 'outro@example.com', :password => 'outro', :password_confirmation => 'outro', :environment => Environment.default) user.activate settings = PushNotificationPlugin::NotificationSettings.create!(:user => user) settings.hash_flags.each_pair do |notification, status| refute status end end should 'activate a notification for a settings' do user = User.create!(:login => 'homer', :email => 'homer@example.com', :password => 'beer', :password_confirmation => 'beer', :environment => Environment.default) user.activate settings = PushNotificationPlugin::NotificationSettings.create!(:user => user) settings.activate_notification "new_comment" settings.save! assert_equal true, settings.hash_flags["new_comment"] end should 'deactivate a notification for a settings' do user = User.create!(:login => 'homer', :email => 'homer@example.com', :password => 'beer', :password_confirmation => 'beer', :environment => Environment.default) user.activate settings = PushNotificationPlugin::NotificationSettings.create!(:user => user) settings.activate_notification "new_comment" settings.save! assert_equal true, settings.hash_flags["new_comment"] settings.deactivate_notification "new_comment" settings.save! assert_equal false, settings.hash_flags["new_comment"] end should 'set notification to specific state' do user = User.create!(:login => 'homer', :email => 'homer@example.com', :password => 'beer', :password_confirmation => 'beer', :environment => Environment.default) user.activate settings = PushNotificationPlugin::NotificationSettings.new(:user => user) settings.set_notification_state "new_comment", 1 settings.save! assert_equal true, settings.hash_flags["new_comment"] settings.set_notification_state "new_comment", 0 settings.save! assert_equal false, settings.hash_flags["new_comment"] end should 'check if notification is active' do user = User.create!(:login => 'homer', :email => 'homer@example.com', :password => 'beer', :password_confirmation => 'beer', :environment => Environment.default) user.activate settings = PushNotificationPlugin::NotificationSettings.create!(:user => user) settings.activate_notification "new_comment" settings.save! assert_equal true, settings.active?("new_comment") end should 'list active notifications' do user = User.create!(:login => 'homer', :email => 'homer@example.com', :password => 'beer', :password_confirmation => 'beer', :environment => Environment.default) user.activate settings = PushNotificationPlugin::NotificationSettings.create!(:user => user) settings.activate_notification "new_comment" settings.save! assert_equivalent ["new_comment"], settings.active_notifications settings.activate_notification "add_friend" settings.save! assert_equivalent ["new_comment","add_friend"], settings.active_notifications end should 'list inactive notifications' do user = User.create!(:login => 'homer', :email => 'homer@example.com', :password => 'beer', :password_confirmation => 'beer', :environment => Environment.default) user.activate settings = PushNotificationPlugin::NotificationSettings.create!(:user => user) assert_equivalent PushNotificationPlugin::NotificationSettings::NOTIFICATIONS.keys, settings.inactive_notifications settings.activate_notification "new_comment" settings.save! assert_equivalent (PushNotificationPlugin::NotificationSettings::NOTIFICATIONS.keys-["new_comment"]), settings.inactive_notifications end end |