spec/firebase-admin/client/accounts_spec.rb in firebase-admin-0.1.2 vs spec/firebase-admin/client/accounts_spec.rb in firebase-admin-0.1.3
- old
+ new
@@ -18,6 +18,61 @@
.with(body: { email: 'john@smith.com', password: 'supersecret' }.to_json)
.with(headers: { 'Authorization' => 'Bearer owner' })
).to have_been_made
end
end
+
+ describe '.update_account' do
+ before do
+ stub_post('v1/projects/test-project/accounts:update')
+ .to_return(body: fixture('update_account.json'), headers: { content_type: 'application/json; charset=utf-8' })
+ end
+
+ it 'should post to the update endpoint' do
+ @client.update_account(email: 'john@smith.com', password: 'supersecret')
+ expect(
+ a_post('v1/projects/test-project/accounts:update')
+ .with(body: { email: 'john@smith.com', password: 'supersecret' }.to_json)
+ .with(headers: { 'Authorization' => 'Bearer owner' })
+ ).to have_been_made
+ end
+ end
+
+ describe '.create_custom_token' do
+ context 'when credentials are set via GOOGLE_APPLICATION_CREDENTIALS' do
+ before do
+ ENV['GOOGLE_APPLICATION_CREDENTIALS'] = fixture('google_credentials.json').path
+ 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 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_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
+ end
+
+ describe '.sign_in_for_uid' do
+ it 'should post to the update endpoint' do
+ expect(@client).to receive(:create_custom_token).with('user-123').and_return('token')
+ expect(@client).to receive(:sign_in_with_custom_token).with('token').and_return('result')
+ result = @client.sign_in_for_uid('user-123')
+ expect(result).to eq('result')
+ end
+ end
end