|
13 | 13 | } |
14 | 14 | end |
15 | 15 |
|
| 16 | + let(:json_credentials) do |
| 17 | + { |
| 18 | + "type": 'service_account', |
| 19 | + "project_id": 'example', |
| 20 | + "private_key_id": 'c09c4593eee53707ca9f4208fbd6fe72b29fc7ab', |
| 21 | + "private_key": OpenSSL::PKey::RSA.new(2048), |
| 22 | + "client_email": '83315528762cf7e0-7bbcc3aad87e0083391bc7f234d487c8@developer.gserviceaccount.com', |
| 23 | + "client_id": 'acedc3c0a63b3562376386f0-f3b94aafbecd0e7d60563bf7bb8bb47f.apps.googleusercontent.com', |
| 24 | + "auth_uri": 'https://accounts.google.com/o/oauth2/auth', |
| 25 | + "token_uri": 'https://oauth2.googleapis.com/token', |
| 26 | + "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', |
| 28 | + "universe_domain": 'googleapis.com' |
| 29 | + }.to_json |
| 30 | + end |
| 31 | + |
16 | 32 | before do |
17 | 33 | allow(client).to receive(:json_key) |
18 | 34 |
|
19 | 35 | # Mock the Google::Auth::ServiceAccountCredentials |
20 | | - allow(Google::Auth::ServiceAccountCredentials).to receive(:make_creds). |
21 | | - and_return(double(fetch_access_token!: { 'access_token' => mock_token })) |
| 36 | + allow(Google::Auth::ServiceAccountCredentials).to receive(:make_creds) |
| 37 | + .and_return(double(fetch_access_token!: { 'access_token' => mock_token })) |
22 | 38 | end |
23 | 39 |
|
24 | | - it "should initialize" do |
| 40 | + it 'should initialize' do |
25 | 41 | expect { client }.not_to raise_error |
26 | 42 | end |
27 | 43 |
|
|
35 | 51 | fcm = FCM.new(StringIO.new("hey")) |
36 | 52 | expect(fcm.__send__(:json_key).class).to eq(StringIO) |
37 | 53 | end |
| 54 | + |
| 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) |
| 58 | + end |
| 59 | + |
| 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) |
| 63 | + end |
| 64 | + |
| 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 |
| 74 | + end |
38 | 75 | end |
39 | 76 |
|
40 | 77 | describe "#send_v1 or #send_notification_v1" do |
|
0 commit comments