rpush 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -2
- data/lib/rpush/cli.rb +1 -1
- data/lib/rpush/client/active_model.rb +1 -1
- data/lib/rpush/client/active_model/apns/notification.rb +9 -1
- data/lib/rpush/client/active_model/apns/notification_payload_size_validator.rb +15 -0
- data/lib/rpush/client/active_model/apns2/notification.rb +14 -0
- data/lib/rpush/client/active_record.rb +1 -0
- data/lib/rpush/client/active_record/apns/active_record_serializable_notification.rb +65 -0
- data/lib/rpush/client/active_record/apns/notification.rb +1 -57
- data/lib/rpush/client/active_record/apns2/notification.rb +4 -1
- data/lib/rpush/client/redis/apns2/notification.rb +1 -0
- data/lib/rpush/client/redis/pushy/notification.rb +0 -1
- data/lib/rpush/daemon/apns2/delivery.rb +6 -1
- data/lib/rpush/daemon/apnsp8/delivery.rb +7 -2
- data/lib/rpush/daemon/store/active_record/reconnectable.rb +1 -1
- data/lib/rpush/version.rb +1 -1
- data/spec/functional/apns2_spec.rb +36 -0
- data/spec/support/simplecov_helper.rb +1 -1
- data/spec/unit/client/active_record/adm/app_spec.rb +2 -54
- data/spec/unit/client/active_record/adm/notification_spec.rb +2 -39
- data/spec/unit/client/active_record/apns/app_spec.rb +3 -26
- data/spec/unit/client/active_record/apns/feedback_spec.rb +1 -5
- data/spec/unit/client/active_record/apns/notification_spec.rb +29 -293
- data/spec/unit/client/active_record/apns2/app_spec.rb +4 -0
- data/spec/unit/client/active_record/apns2/notification_spec.rb +65 -0
- data/spec/unit/client/active_record/app_spec.rb +1 -26
- data/spec/unit/client/active_record/gcm/app_spec.rb +3 -1
- data/spec/unit/client/active_record/gcm/notification_spec.rb +6 -88
- data/spec/unit/client/active_record/notification_spec.rb +3 -11
- data/spec/unit/client/active_record/pushy/app_spec.rb +2 -13
- data/spec/unit/client/active_record/pushy/notification_spec.rb +2 -55
- data/spec/unit/client/active_record/shared/app.rb +14 -0
- data/spec/unit/{notification_shared.rb → client/active_record/shared/notification.rb} +12 -7
- data/spec/unit/client/active_record/wns/badge_notification_spec.rb +1 -11
- data/spec/unit/client/active_record/wns/raw_notification_spec.rb +3 -12
- data/spec/unit/client/active_record/wpns/app_spec.rb +3 -1
- data/spec/unit/client/active_record/wpns/notification_spec.rb +2 -17
- data/spec/unit/client/redis/adm/app_spec.rb +5 -0
- data/spec/unit/client/redis/adm/notification_spec.rb +5 -0
- data/spec/unit/client/redis/apns/app_spec.rb +5 -0
- data/spec/unit/client/redis/apns/feedback_spec.rb +5 -0
- data/spec/unit/client/redis/apns/notification_spec.rb +50 -0
- data/spec/unit/client/redis/apns2/app_spec.rb +4 -0
- data/spec/unit/client/redis/apns2/notification_spec.rb +50 -0
- data/spec/unit/client/redis/app_spec.rb +5 -0
- data/spec/unit/client/redis/gcm/app_spec.rb +5 -0
- data/spec/unit/client/redis/gcm/notification_spec.rb +5 -0
- data/spec/unit/client/redis/notification_spec.rb +5 -0
- data/spec/unit/client/redis/pushy/app_spec.rb +5 -0
- data/spec/unit/client/redis/pushy/notification_spec.rb +5 -0
- data/spec/unit/client/redis/wns/badge_notification_spec.rb +5 -0
- data/spec/unit/client/redis/wns/raw_notification_spec.rb +22 -0
- data/spec/unit/client/redis/wpns/app_spec.rb +5 -0
- data/spec/unit/client/redis/wpns/notification_spec.rb +5 -0
- data/spec/unit/client/shared/adm/app.rb +51 -0
- data/spec/unit/client/shared/adm/notification.rb +39 -0
- data/spec/unit/client/shared/apns/app.rb +29 -0
- data/spec/unit/client/shared/apns/feedback.rb +9 -0
- data/spec/unit/client/shared/apns/notification.rb +262 -0
- data/spec/unit/client/shared/app.rb +17 -0
- data/spec/unit/client/shared/gcm/app.rb +4 -0
- data/spec/unit/client/shared/gcm/notification.rb +77 -0
- data/spec/unit/client/shared/notification.rb +10 -0
- data/spec/unit/client/shared/pushy/app.rb +17 -0
- data/spec/unit/client/shared/pushy/notification.rb +55 -0
- data/spec/unit/client/shared/wns/badge_notification.rb +15 -0
- data/spec/unit/client/shared/wns/raw_notification.rb +21 -0
- data/spec/unit/client/shared/wpns/app.rb +4 -0
- data/spec/unit/client/shared/wpns/notification.rb +18 -0
- data/spec/unit/daemon/shared/store.rb +312 -0
- data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +7 -7
- data/spec/unit/daemon/store/active_record_spec.rb +2 -290
- data/spec/unit/daemon/store/redis_spec.rb +2 -291
- data/spec/unit_spec_helper.rb +3 -0
- metadata +89 -10
- data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +0 -16
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Rpush::Client::App' do
|
4
|
+
context 'validating certificates' do
|
5
|
+
it 'rescues from certificate error' do
|
6
|
+
app = Rpush::Apns::App.new(name: 'test', environment: 'development', certificate: 'bad')
|
7
|
+
expect { app.valid? }.not_to raise_error
|
8
|
+
expect(app.valid?).to eq(false)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'raises other errors' do
|
12
|
+
app = Rpush::Apns::App.new(name: 'test', environment: 'development', certificate: 'bad')
|
13
|
+
allow(OpenSSL::X509::Certificate).to receive(:new).and_raise(NameError, 'simulating no openssl')
|
14
|
+
expect { app.valid? }.to raise_error(NameError)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Rpush::Client::Gcm::Notification' do
|
4
|
+
let(:app) { Rpush::Gcm::App.create!(name: 'test', auth_key: 'abc') }
|
5
|
+
let(:notification) { described_class.new }
|
6
|
+
|
7
|
+
it "has a 'data' payload limit of 4096 bytes" do
|
8
|
+
notification.data = { key: "a" * 4096 }
|
9
|
+
expect(notification.valid?).to be_falsey
|
10
|
+
expect(notification.errors[:base]).to eq ["Notification payload data cannot be larger than 4096 bytes."]
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'limits the number of registration ids to 1000' do
|
14
|
+
notification.registration_ids = ['a'] * (1000 + 1)
|
15
|
+
expect(notification.valid?).to be_falsey
|
16
|
+
expect(notification.errors[:base]).to eq ["Number of registration_ids cannot be larger than 1000."]
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'validates expiry is present if collapse_key is set' do
|
20
|
+
notification.collapse_key = 'test'
|
21
|
+
notification.expiry = nil
|
22
|
+
expect(notification.valid?).to be_falsey
|
23
|
+
expect(notification.errors[:expiry]).to eq ['must be set when using a collapse_key']
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'includes time_to_live in the payload' do
|
27
|
+
notification.expiry = 100
|
28
|
+
expect(notification.as_json['time_to_live']).to eq 100
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'includes content_available in the payload' do
|
32
|
+
notification.content_available = true
|
33
|
+
expect(notification.as_json['content_available']).to eq true
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'includes mutable_content in the payload' do
|
37
|
+
notification.mutable_content = true
|
38
|
+
expect(notification.as_json['mutable_content']).to eq true
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'sets the priority to high when set to high' do
|
42
|
+
notification.priority = 'high'
|
43
|
+
expect(notification.as_json['priority']).to eq 'high'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'sets the priority to normal when set to normal' do
|
47
|
+
notification.priority = 'normal'
|
48
|
+
expect(notification.as_json['priority']).to eq 'normal'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'validates the priority is either "normal" or "high"' do
|
52
|
+
notification.priority = 'invalid'
|
53
|
+
expect(notification.errors[:priority]).to eq ['must be one of either "normal" or "high"']
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'excludes the priority if it is not defined' do
|
57
|
+
expect(notification.as_json).not_to have_key 'priority'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'includes the notification payload if defined' do
|
61
|
+
notification.notification = { key: 'any key is allowed' }
|
62
|
+
expect(notification.as_json).to have_key 'notification'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'excludes the notification payload if undefined' do
|
66
|
+
expect(notification.as_json).not_to have_key 'notification'
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'includes the dry_run payload if defined' do
|
70
|
+
notification.dry_run = true
|
71
|
+
expect(notification.as_json['dry_run']).to eq true
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'excludes the dry_run payload if undefined' do
|
75
|
+
expect(notification.as_json).not_to have_key 'dry_run'
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Rpush::Client::Notification' do
|
4
|
+
let(:notification) { described_class.new }
|
5
|
+
|
6
|
+
it 'allows assignment of many registration IDs' do
|
7
|
+
notification.registration_ids = %w[a b]
|
8
|
+
expect(notification.registration_ids).to eq %w[a b]
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Rpush::Client::Pushy::App' do
|
4
|
+
describe 'validates' do
|
5
|
+
subject { described_class.new }
|
6
|
+
|
7
|
+
it 'validates presence of name' do
|
8
|
+
is_expected.not_to be_valid
|
9
|
+
expect(subject.errors[:name]).to eq ["can't be blank"]
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'validates presence of api_key' do
|
13
|
+
is_expected.not_to be_valid
|
14
|
+
expect(subject.errors[:api_key]).to eq ["can't be blank"]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Rpush::Client::Pushy::Notification' do
|
4
|
+
subject(:notification) { described_class.new }
|
5
|
+
|
6
|
+
describe 'validates' do
|
7
|
+
let(:app) { Rpush::Pushy::App.create!(name: 'MyApp', api_key: 'my_api_key') }
|
8
|
+
|
9
|
+
describe 'data' do
|
10
|
+
subject { described_class.new(app: app, registration_ids: ['id']) }
|
11
|
+
it 'validates presence' do
|
12
|
+
is_expected.not_to be_valid
|
13
|
+
expect(subject.errors[:data]).to eq ["can't be blank"]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has a 'data' payload limit of 4096 bytes" do
|
17
|
+
subject.data = { message: 'a' * 4096 }
|
18
|
+
is_expected.not_to be_valid
|
19
|
+
expected_errors = ["Notification payload data cannot be larger than 4096 bytes."]
|
20
|
+
expect(subject.errors[:base]).to eq expected_errors
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'registration_ids' do
|
25
|
+
subject { described_class.new(app: app, data: { message: 'test' }) }
|
26
|
+
it 'validates presence' do
|
27
|
+
is_expected.not_to be_valid
|
28
|
+
expect(subject.errors[:registration_ids]).to eq ["can't be blank"]
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'limits the number of registration ids to 1000' do
|
32
|
+
subject.registration_ids = ['a'] * (1000 + 1)
|
33
|
+
is_expected.not_to be_valid
|
34
|
+
expected_errors = ["Number of registration_ids cannot be larger than 1000."]
|
35
|
+
expect(subject.errors[:base]).to eq expected_errors
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'time_to_live' do
|
40
|
+
subject { described_class.new(app: app, data: { message: 'test' }, registration_ids: ['id']) }
|
41
|
+
|
42
|
+
it 'should be > 0' do
|
43
|
+
subject.time_to_live = -1
|
44
|
+
is_expected.not_to be_valid
|
45
|
+
expect(subject.errors[:time_to_live]).to eq ['must be greater than 0']
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should be <= 1.year.seconds' do
|
49
|
+
subject.time_to_live = 2.years.seconds.to_i
|
50
|
+
is_expected.not_to be_valid
|
51
|
+
expect(subject.errors[:time_to_live]).to eq ['The maximum value is 1 year']
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Rpush::Client::Wns::BadgeNotification' do
|
4
|
+
let(:notification) do
|
5
|
+
notif = described_class.new
|
6
|
+
notif.app = Rpush::Wns::App.create!(name: "MyApp", client_id: "someclient", client_secret: "somesecret")
|
7
|
+
notif.uri = 'https://db5.notify.windows.com/?token=TOKEN'
|
8
|
+
notif.badge = 42
|
9
|
+
notif
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should allow a notification without data' do
|
13
|
+
expect(notification.valid?).to be(true)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Rpush::Client::Wns::RawNotification' do
|
4
|
+
let(:notification) do
|
5
|
+
notif = described_class.new
|
6
|
+
notif.app = Rpush::Wns::App.create!(name: "MyApp", client_id: "someclient", client_secret: "somesecret")
|
7
|
+
notif.uri = 'https://db5.notify.windows.com/?token=TOKEN'
|
8
|
+
notif.data = { foo: 'foo', bar: 'bar' }
|
9
|
+
notif
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'allows exact payload of 5 KB' do
|
13
|
+
allow(notification).to receive(:payload_data_size) { 5120 }
|
14
|
+
expect(notification.valid?).to be(true)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'allows the size of payload under 5 KB' do
|
18
|
+
allow(notification).to receive(:payload_data_size) { 5119 }
|
19
|
+
expect(notification.valid?).to be(true)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Rpush::Client::Wpns::Notification' do
|
4
|
+
let(:app) { Rpush::Wpns::App.create!(name: 'test', auth_key: 'abc') }
|
5
|
+
let(:notification) { described_class.new }
|
6
|
+
|
7
|
+
it "should have an url in the uri parameter" do
|
8
|
+
notification = described_class.new(uri: "somthing")
|
9
|
+
notification.valid?
|
10
|
+
expect(notification.errors[:uri]).to include('is invalid')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be invalid if there's no data" do
|
14
|
+
notification = described_class.new(data: {})
|
15
|
+
notification.valid?
|
16
|
+
expect(notification.errors[:data]).to include("can't be blank")
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,312 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Rpush::Daemon::Store' do
|
4
|
+
subject(:store) { described_class.new }
|
5
|
+
|
6
|
+
let(:app) { Rpush::Apns::App.create!(name: 'my_app', environment: 'development', certificate: TEST_CERT) }
|
7
|
+
let(:notification) { Rpush::Apns::Notification.create!(device_token: "a" * 64, app: app) }
|
8
|
+
let(:time) { Time.parse('2019/06/06 02:45').utc }
|
9
|
+
let(:logger) { double(Rpush::Logger, error: nil, internal_logger: nil) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(Rpush).to receive_messages(logger: logger)
|
13
|
+
end
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
Timecop.freeze(time)
|
17
|
+
end
|
18
|
+
|
19
|
+
after do
|
20
|
+
Timecop.return
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'updates an notification' do
|
24
|
+
expect(notification).to receive(:save!)
|
25
|
+
store.update_notification(notification)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'updates an app' do
|
29
|
+
expect(app).to receive(:save!)
|
30
|
+
store.update_app(app)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'finds an app by ID' do
|
34
|
+
expect(store.app(app.id)).to eq(app)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'finds all apps' do
|
38
|
+
app
|
39
|
+
expect(store.all_apps).to eq([app])
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'translates an Integer notification ID' do
|
43
|
+
expect(store.translate_integer_notification_id(notification.id)).to eq(notification.id)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns the pending notification count' do
|
47
|
+
notification
|
48
|
+
expect(store.pending_delivery_count).to eq(1)
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'mark_retryable' do
|
52
|
+
it 'increments the retry count' do
|
53
|
+
expect do
|
54
|
+
store.mark_retryable(notification, time)
|
55
|
+
end.to change(notification, :retries).by(1)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'sets the deliver after timestamp' do
|
59
|
+
deliver_after = (time + 10.seconds)
|
60
|
+
expect do
|
61
|
+
store.mark_retryable(notification, deliver_after)
|
62
|
+
end.to change(notification, :deliver_after).to(deliver_after)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'saves the notification without validation' do
|
66
|
+
expect(notification).to receive(:save!).with(validate: false)
|
67
|
+
store.mark_retryable(notification, time)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'does not save the notification if persist: false' do
|
71
|
+
expect(notification).not_to receive(:save!)
|
72
|
+
store.mark_retryable(notification, time, persist: false)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'mark_batch_retryable' do
|
77
|
+
let(:deliver_after) { time + 10.seconds }
|
78
|
+
|
79
|
+
it 'sets the attributes on the object for use in reflections' do
|
80
|
+
store.mark_batch_retryable([notification], deliver_after)
|
81
|
+
expect(notification.deliver_after.to_s).to eq deliver_after.to_s
|
82
|
+
expect(notification.retries).to eq 1
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'increments the retired count' do
|
86
|
+
expect do
|
87
|
+
store.mark_batch_retryable([notification], deliver_after)
|
88
|
+
notification.reload
|
89
|
+
end.to change(notification, :retries).by(1)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'sets the deliver after timestamp' do
|
93
|
+
expect do
|
94
|
+
store.mark_batch_retryable([notification], deliver_after)
|
95
|
+
notification.reload
|
96
|
+
end.to change { notification.deliver_after.try(:utc).to_s }.to(deliver_after.utc.to_s)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe 'mark_delivered' do
|
101
|
+
it 'marks the notification as delivered' do
|
102
|
+
expect do
|
103
|
+
store.mark_delivered(notification, time)
|
104
|
+
end.to change(notification, :delivered).to(true)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'sets the time the notification was delivered' do
|
108
|
+
expect do
|
109
|
+
store.mark_delivered(notification, time)
|
110
|
+
notification.reload
|
111
|
+
end.to change { notification.delivered_at.try(:utc).to_s }.to(time.to_s)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'saves the notification without validation' do
|
115
|
+
expect(notification).to receive(:save!).with(validate: false)
|
116
|
+
store.mark_delivered(notification, time)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'does not save the notification if persist: false' do
|
120
|
+
expect(notification).not_to receive(:save!)
|
121
|
+
store.mark_delivered(notification, time, persist: false)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe 'mark_batch_delivered' do
|
126
|
+
it 'sets the attributes on the object for use in reflections' do
|
127
|
+
store.mark_batch_delivered([notification])
|
128
|
+
expect(notification.delivered_at.to_s).to eq time.to_s
|
129
|
+
expect(notification.delivered).to be_truthy
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'marks the notifications as delivered' do
|
133
|
+
expect do
|
134
|
+
store.mark_batch_delivered([notification])
|
135
|
+
notification.reload
|
136
|
+
end.to change(notification, :delivered).to(true)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'sets the time the notifications were delivered' do
|
140
|
+
expect do
|
141
|
+
store.mark_batch_delivered([notification])
|
142
|
+
notification.reload
|
143
|
+
end.to change { notification.delivered_at.try(:utc)&.to_s }.to(time.to_s)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe 'mark_failed' do
|
148
|
+
it 'marks the notification as not delivered' do
|
149
|
+
store.mark_failed(notification, nil, '', time)
|
150
|
+
expect(notification.delivered).to eq(false)
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'marks the notification as failed' do
|
154
|
+
expect do
|
155
|
+
store.mark_failed(notification, nil, '', time)
|
156
|
+
notification.reload
|
157
|
+
end.to change(notification, :failed).to(true)
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'sets the time the notification delivery failed' do
|
161
|
+
expect do
|
162
|
+
store.mark_failed(notification, nil, '', time)
|
163
|
+
notification.reload
|
164
|
+
end.to change { notification.failed_at.try(:utc).to_s }.to(time.to_s)
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'sets the error code' do
|
168
|
+
expect do
|
169
|
+
store.mark_failed(notification, 42, '', time)
|
170
|
+
end.to change(notification, :error_code).to(42)
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'sets the error description' do
|
174
|
+
expect do
|
175
|
+
store.mark_failed(notification, 42, 'Weeee', time)
|
176
|
+
end.to change(notification, :error_description).to('Weeee')
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'saves the notification without validation' do
|
180
|
+
expect(notification).to receive(:save!).with(validate: false)
|
181
|
+
store.mark_failed(notification, nil, '', time)
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'does not save the notification if persist: false' do
|
185
|
+
expect(notification).not_to receive(:save!)
|
186
|
+
store.mark_failed(notification, nil, '', time, persist: false)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe 'mark_batch_failed' do
|
191
|
+
it 'sets the attributes on the object for use in reflections' do
|
192
|
+
store.mark_batch_failed([notification], 123, 'an error')
|
193
|
+
expect(notification.failed_at.to_s).to eq time.to_s
|
194
|
+
expect(notification.delivered_at).to be_nil
|
195
|
+
expect(notification.delivered).to eq(false)
|
196
|
+
expect(notification.failed).to be_truthy
|
197
|
+
expect(notification.error_code).to eq 123
|
198
|
+
expect(notification.error_description).to eq 'an error'
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'marks the notification as not delivered' do
|
202
|
+
store.mark_batch_failed([notification], nil, '')
|
203
|
+
notification.reload
|
204
|
+
expect(notification.delivered).to be_falsey
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'marks the notification as failed' do
|
208
|
+
expect do
|
209
|
+
store.mark_batch_failed([notification], nil, '')
|
210
|
+
notification.reload
|
211
|
+
end.to change(notification, :failed).to(true)
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'sets the time the notification delivery failed' do
|
215
|
+
expect do
|
216
|
+
store.mark_batch_failed([notification], nil, '')
|
217
|
+
notification.reload
|
218
|
+
end.to change { notification.failed_at.try(:utc) }.to(time)
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'sets the error code' do
|
222
|
+
expect do
|
223
|
+
store.mark_batch_failed([notification], 42, '')
|
224
|
+
notification.reload
|
225
|
+
end.to change(notification, :error_code).to(42)
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'sets the error description' do
|
229
|
+
expect do
|
230
|
+
store.mark_batch_failed([notification], 42, 'Weeee')
|
231
|
+
notification.reload
|
232
|
+
end.to change(notification, :error_description).to('Weeee')
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe 'create_apns_feedback' do
|
237
|
+
it 'creates the Feedback record' do
|
238
|
+
expect(Rpush::Apns::Feedback).to receive(:create!).with(
|
239
|
+
failed_at: time, device_token: 'ab' * 32, app_id: app.id
|
240
|
+
)
|
241
|
+
store.create_apns_feedback(time, 'ab' * 32, app)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe 'create_gcm_notification' do
|
246
|
+
let(:data) { { 'data' => true } }
|
247
|
+
let(:attributes) { { device_token: 'ab' * 32 } }
|
248
|
+
let(:registration_ids) { %w[123 456] }
|
249
|
+
let(:deliver_after) { time + 10.seconds }
|
250
|
+
let(:args) { [attributes, data, registration_ids, deliver_after, app] }
|
251
|
+
|
252
|
+
it 'sets the given attributes' do
|
253
|
+
new_notification = store.create_gcm_notification(*args)
|
254
|
+
expect(new_notification.device_token).to eq 'ab' * 32
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'sets the given data' do
|
258
|
+
new_notification = store.create_gcm_notification(*args)
|
259
|
+
expect(new_notification.data['data']).to be_truthy
|
260
|
+
end
|
261
|
+
|
262
|
+
it 'sets the given registration IDs' do
|
263
|
+
new_notification = store.create_gcm_notification(*args)
|
264
|
+
expect(new_notification.registration_ids).to eq registration_ids
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'sets the deliver_after timestamp' do
|
268
|
+
new_notification = store.create_gcm_notification(*args)
|
269
|
+
expect(new_notification.deliver_after).to eq deliver_after
|
270
|
+
end
|
271
|
+
|
272
|
+
it 'saves the new notification' do
|
273
|
+
new_notification = store.create_gcm_notification(*args)
|
274
|
+
expect(new_notification.new_record?).to be_falsey
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
describe 'create_adm_notification' do
|
279
|
+
let(:data) { { 'data' => true } }
|
280
|
+
let(:attributes) { { app_id: app.id, collapse_key: 'ckey', delay_while_idle: true } }
|
281
|
+
let(:registration_ids) { %w[123 456] }
|
282
|
+
let(:deliver_after) { time + 10.seconds }
|
283
|
+
let(:args) { [attributes, data, registration_ids, deliver_after, app] }
|
284
|
+
|
285
|
+
it 'sets the given attributes' do
|
286
|
+
new_notification = store.create_adm_notification(*args)
|
287
|
+
expect(new_notification.app_id).to eq app.id
|
288
|
+
expect(new_notification.collapse_key).to eq 'ckey'
|
289
|
+
expect(new_notification.delay_while_idle).to be_truthy
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'sets the given data' do
|
293
|
+
new_notification = store.create_adm_notification(*args)
|
294
|
+
expect(new_notification.data['data']).to be_truthy
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'sets the given registration IDs' do
|
298
|
+
new_notification = store.create_adm_notification(*args)
|
299
|
+
expect(new_notification.registration_ids).to eq registration_ids
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'sets the deliver_after timestamp' do
|
303
|
+
new_notification = store.create_adm_notification(*args)
|
304
|
+
expect(new_notification.deliver_after.to_s).to eq deliver_after.to_s
|
305
|
+
end
|
306
|
+
|
307
|
+
it 'saves the new notification' do
|
308
|
+
new_notification = store.create_adm_notification(*args)
|
309
|
+
expect(new_notification.new_record?).to be_falsey
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|