spec/firebase-admin/client/accounts_spec.rb in firebase-admin-0.1.3 vs spec/firebase-admin/client/accounts_spec.rb in firebase-admin-0.1.4

- old
+ new

@@ -48,22 +48,45 @@ token_data, _alg = JWT.decode(token, nil, false) expect(token_data['uid']).to eq('user-123') end end + context 'when GOOGLE_APPLICATION_CREDENTIALS points to an invalid file' do + before do + ENV['GOOGLE_APPLICATION_CREDENTIALS'] = fixture('google_credentials_invalid.json').path + end + + it 'raises an error' do + expect { @client.create_custom_token('user-123') }.to raise_error FirebaseAdmin::InvalidCredentials + end + end + context 'when credentials are set via GOOGLE_CLIENT_EMAIL / GOOGLE_PRIVATE_KEY' do let(:email) { 'example@example.com' } let(:private_key) { fixture('example_key').read } before do + ENV['GOOGLE_APPLICATION_CREDENTIALS'] = nil ENV['GOOGLE_CLIENT_EMAIL'] = email ENV['GOOGLE_PRIVATE_KEY'] = private_key end it 'returns a valid JWT token' do token = @client.create_custom_token('user-123') token_data, _alg = JWT.decode(token, nil, false) expect(token_data['uid']).to eq('user-123') + end + end + + context 'when no credentials are provided' do + before do + ENV['GOOGLE_APPLICATION_CREDENTIALS'] = nil + ENV['GOOGLE_CLIENT_EMAIL'] = nil + ENV['GOOGLE_PRIVATE_KEY'] = nil + end + + it 'raises an error' do + expect { @client.create_custom_token('user-123') }.to raise_error FirebaseAdmin::InvalidCredentials end end end describe '.sign_in_for_uid' do