mercurius 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mercurius/testing/gcm/successful_connection.rb +1 -1
- data/lib/mercurius/testing/gcm/token_serializer.rb +4 -8
- data/lib/mercurius/testing/gcm/unregistered_device_token_connection.rb +27 -6
- data/lib/mercurius/version.rb +1 -1
- data/spec/lib/testing_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c407384556945caff8534e28bb17bc33eeb1e804
|
4
|
+
data.tar.gz: fb500925edc12008a2cf11653699083f37995d18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 060ef7919702f1ca15acbb7f501fcaee491da68f5d5a416ecc49e57c84eef62c07abeff7afebacd9d1479ed56e74d270261789622b7cc30ec9f6d36c4c045153
|
7
|
+
data.tar.gz: dd66a90ef1b5a22689bebf352700b4303bbe24993c24119df9b3782af55f3a0acfba3d23e3d5832054237159fd854f2928a9e6b636b019c2e32df4d9d4b7c91b
|
@@ -1,15 +1,11 @@
|
|
1
1
|
module GCM
|
2
2
|
module TokenSerializer
|
3
|
-
def valid_token_json(
|
4
|
-
|
5
|
-
{ 'message_id' => SecureRandom.hex }
|
6
|
-
end
|
3
|
+
def valid_token_json(token)
|
4
|
+
{ 'message_id' => SecureRandom.hex }
|
7
5
|
end
|
8
6
|
|
9
|
-
def invalid_token_json(
|
10
|
-
|
11
|
-
{ 'error' => error }
|
12
|
-
end
|
7
|
+
def invalid_token_json(token, error)
|
8
|
+
{ 'error' => error }
|
13
9
|
end
|
14
10
|
|
15
11
|
def canonical_token_json(tokens, canonical_ids_map)
|
@@ -7,19 +7,40 @@ module GCM
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def write(json)
|
10
|
-
|
11
|
-
@invalid_tokens.include? token
|
12
|
-
end
|
10
|
+
tokens = json[:registration_ids]
|
13
11
|
|
14
12
|
json = {
|
15
13
|
'multicast_id' => '123',
|
16
|
-
'success' =>
|
17
|
-
'failure' =>
|
14
|
+
'success' => valid_tokens_count(tokens),
|
15
|
+
'failure' => invalid_tokens_count(tokens),
|
18
16
|
'canonical_ids' => 0,
|
19
|
-
'results' =>
|
17
|
+
'results' => tokens.map do |token|
|
18
|
+
if valid? token
|
19
|
+
valid_token_json token
|
20
|
+
else
|
21
|
+
invalid_token_json token, 'NotRegistered'
|
22
|
+
end
|
23
|
+
end
|
20
24
|
}.to_json
|
21
25
|
|
22
26
|
Mercurius::FakeResponse.new body: json, status: 200
|
23
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def valid?(token)
|
31
|
+
!invalid? token
|
32
|
+
end
|
33
|
+
|
34
|
+
def invalid?(token)
|
35
|
+
@invalid_tokens.include?(token)
|
36
|
+
end
|
37
|
+
|
38
|
+
def valid_tokens_count(tokens)
|
39
|
+
tokens.count { |token| valid? token }
|
40
|
+
end
|
41
|
+
|
42
|
+
def invalid_tokens_count(tokens)
|
43
|
+
tokens.count { |token| invalid? token }
|
44
|
+
end
|
24
45
|
end
|
25
46
|
end
|
data/lib/mercurius/version.rb
CHANGED
data/spec/lib/testing_spec.rb
CHANGED
@@ -20,7 +20,7 @@ describe 'Test mode' do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'Returns invalid device errors for the tokens provided' do
|
23
|
-
responses = service.deliver message, '
|
23
|
+
responses = service.deliver message, 'token456', 'token123'
|
24
24
|
expect(responses.results.failed.size).to eq 1
|
25
25
|
expect(responses.results.failed[0].token).to eq 'token456'
|
26
26
|
expect(responses.results.failed[0].error).to eq 'NotRegistered'
|