forked from PRX/apn_on_rails
-
Notifications
You must be signed in to change notification settings - Fork 1
/
group_notification_spec.rb
73 lines (57 loc) · 2.46 KB
/
group_notification_spec.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
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper.rb')
describe APN::GroupNotification do
describe 'alert' do
it 'should trim the message to 150 characters' do
noty = APN::GroupNotification.new
noty.alert = 'a' * 200
noty.alert.should == ('a' * 147) + '...'
end
end
describe 'apple_hash' do
it 'should return a hash of the appropriate params for Apple' do
noty = APN::GroupNotification.first
noty.apple_hash.should == {"aps" => {"badge" => 5, "sound" => "my_sound.aiff", "alert" => "Hello!"},"typ" => "1"}
noty.custom_properties = nil
noty.apple_hash.should == {"aps" => {"badge" => 5, "sound" => "my_sound.aiff", "alert" => "Hello!"}}
noty.badge = nil
noty.apple_hash.should == {"aps" => {"sound" => "my_sound.aiff", "alert" => "Hello!"}}
noty.alert = nil
noty.apple_hash.should == {"aps" => {"sound" => "my_sound.aiff"}}
noty.sound = nil
noty.apple_hash.should == {"aps" => {}}
noty.sound = true
noty.apple_hash.should == {"aps" => {"sound" => "1.aiff"}}
end
end
describe 'to_apple_json' do
it 'should return the necessary JSON for Apple' do
noty = APN::GroupNotification.first
noty.to_apple_json.should be_same_meaning_as %{{"typ":"1","aps":{"badge":5,"sound":"my_sound.aiff","alert":"Hello!"}}}
end
end
describe 'message_for_sending' do
describe 'should create a binary message to be sent to Apple' do
subject {
noty = APN::GroupNotification.first
noty.custom_properties = nil
device = DeviceFactory.new(:token => token)
noty.message_for_sending(device)
}
let(:token) { '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz' }
it do
subject.should == fixture_value('message_for_sending.bin')
end
end
it 'should raise an APN::Errors::ExceededMessageSizeError if the message is too big' do
app = AppFactory.create
device = DeviceFactory.create({:app_id => app.id})
group = GroupFactory.create({:app_id => app.id})
device_grouping = DeviceGroupingFactory.create({:group_id => group.id,:device_id => device.id})
noty = GroupNotificationFactory.new(:group_id => group.id, :sound => true, :badge => nil)
noty.send(:write_attribute, 'alert', 'a' * 183)
lambda {
noty.message_for_sending(device)
}.should raise_error(APN::Errors::ExceededMessageSizeError)
end
end
end