|
13 | 13 | }
|
14 | 14 | end
|
15 | 15 |
|
| 16 | + let(:client_email) do |
| 17 | + '83315528762cf7e0-7bbcc3aad87e0083391bc7f234d487' \ |
| 18 | + 'c8@developer.gserviceaccount.com' |
| 19 | + end |
| 20 | + |
| 21 | + let(:client_x509_cert_url) do |
| 22 | + 'https://www.googleapis.com/robot/v1/metadata/x509/' \ |
| 23 | + 'fd6b61037dd2bb8585527679" + "-7bbcc3aad87e0083391b' \ |
| 24 | + 'c7f234d487c8%40developer.gserviceaccount.com' |
| 25 | + end |
| 26 | + |
| 27 | + let(:creds_error) do |
| 28 | + FCM::InvalidCredentialError |
| 29 | + end |
| 30 | + |
16 | 31 | let(:json_credentials) do
|
17 | 32 | {
|
18 | 33 | "type": 'service_account',
|
19 | 34 | "project_id": 'example',
|
20 | 35 | "private_key_id": 'c09c4593eee53707ca9f4208fbd6fe72b29fc7ab',
|
21 | 36 | "private_key": OpenSSL::PKey::RSA.new(2048),
|
22 |
| - "client_email": '83315528762cf7e0-7bbcc3aad87e0083391bc7f234d487c8@developer.gserviceaccount.com', |
23 |
| - "client_id": 'acedc3c0a63b3562376386f0-f3b94aafbecd0e7d60563bf7bb8bb47f.apps.googleusercontent.com', |
| 37 | + "client_email": client_email, |
| 38 | + "client_id": 'acedc3c0a63b3562376386f0.apps.googleusercontent.com', |
24 | 39 | "auth_uri": 'https://accounts.google.com/o/oauth2/auth',
|
25 | 40 | "token_uri": 'https://oauth2.googleapis.com/token',
|
26 | 41 | "auth_provider_x509_cert_url": 'https://www.googleapis.com/oauth2/v1/certs',
|
27 |
| - "client_x509_cert_url": 'https://www.googleapis.com/robot/v1/metadata/x509/fd6b61037dd2bb8585527679-7bbcc3aad87e0083391bc7f234d487c8%40developer.gserviceaccount.com', |
| 42 | + "client_x509_cert_url": client_x509_cert_url, |
28 | 43 | "universe_domain": 'googleapis.com'
|
29 | 44 | }.to_json
|
30 | 45 | end
|
|
42 | 57 | end
|
43 | 58 |
|
44 | 59 | describe "credentials path" do
|
45 |
| - it "can be a path to a file" do |
| 60 | + it 'can be a path to a file' do |
46 | 61 | fcm = FCM.new("README.md")
|
47 | 62 | expect(fcm.__send__(:json_key).class).to eq(File)
|
48 | 63 | end
|
49 | 64 |
|
50 |
| - it "can be an IO object" do |
51 |
| - fcm = FCM.new(StringIO.new("hey")) |
| 65 | + it 'can be an IO object' do |
| 66 | + fcm = FCM.new(StringIO.new('hey')) |
52 | 67 | expect(fcm.__send__(:json_key).class).to eq(StringIO)
|
53 | 68 | end
|
54 | 69 |
|
55 |
| - it "raises an error when passed a non-existent credentials file path" do |
56 |
| - fcm = FCM.new('spec/fake_credentials.json', '', {}) |
57 |
| - expect { fcm.__send__(:json_key).class }.to raise_error(FCM::InvalidCredentialError) |
| 70 | + it 'raises an error when passed a non IO-like object' do |
| 71 | + [ |
| 72 | + FCM.new(nil, '', {}), |
| 73 | + FCM.new({}, '', {}), |
| 74 | + FCM.new(json_credentials, '', {}) |
| 75 | + ].each do |fcm| |
| 76 | + expect { fcm.__send__(:json_key) }.to raise_error(creds_error) |
| 77 | + end |
58 | 78 | end
|
59 | 79 |
|
60 |
| - it "raises an error when passed a string of a file that does not exist" do |
61 |
| - fcm = FCM.new("fake_credentials.json", '', {}) |
62 |
| - expect { fcm.__send__(:json_key).class }.to raise_error(FCM::InvalidCredentialError) |
| 80 | + it 'raises an error when passed a non-existent credentials file path' do |
| 81 | + fcm = FCM.new('spec/fake_credentials.json', '', {}) |
| 82 | + expect { fcm.__send__(:json_key) }.to raise_error(creds_error) |
63 | 83 | end
|
64 | 84 |
|
65 |
| - it 'raises an error when passed a non IO-like object' do |
66 |
| - fcm_with_non_io_objects = [ |
67 |
| - fcm_with_nil_creds = FCM.new(nil, '', {}), |
68 |
| - fcm_with_hash_creds = FCM.new({}, '', {}), |
69 |
| - fcm_with_json = FCM.new(json_credentials, '', {}) |
70 |
| - ] |
71 |
| - fcm_with_non_io_objects.each do |fcm_with_non_io_object| |
72 |
| - expect { fcm_with_non_io_object.__send__(:json_key).class }.to raise_error(FCM::InvalidCredentialError) |
73 |
| - end |
| 85 | + it 'raises an error when passed a string of a file that does not exist' do |
| 86 | + fcm = FCM.new('fake_credentials.json', '', {}) |
| 87 | + expect { fcm.__send__(:json_key) }.to raise_error(creds_error) |
74 | 88 | end
|
75 | 89 | end
|
76 | 90 |
|
|
0 commit comments