spec/firebase-admin/client/accounts_spec.rb in firebase-admin-0.1.6 vs spec/firebase-admin/client/accounts_spec.rb in firebase-admin-0.2.0
- old
+ new
@@ -1,20 +1,18 @@
require File.expand_path('../../spec_helper', __dir__)
describe FirebaseAdmin::Client do
- before do
- @client = FirebaseAdmin::Client.new(project_id: 'test-project')
- end
+ let(:client) { FirebaseAdmin::Client.new(project_id: 'test-project') }
describe '.create_account' do
before do
stub_post('v1/projects/test-project/accounts')
.to_return(body: fixture('create_account.json'), headers: { content_type: 'application/json; charset=utf-8' })
end
it 'should get the correct resource' do
- @client.create_account(email: 'john@smith.com', password: 'supersecret')
+ client.create_account(email: 'john@smith.com', password: 'supersecret')
expect(
a_post('v1/projects/test-project/accounts')
.with(body: { email: 'john@smith.com', password: 'supersecret' }.to_json)
.with(headers: { 'Authorization' => 'Bearer owner' })
).to have_been_made
@@ -26,11 +24,11 @@
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')
+ 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
@@ -39,26 +37,30 @@
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
+ FirebaseAdmin.reset
end
it 'returns a valid JWT token' do
- token = @client.create_custom_token('user-123')
+ 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 GOOGLE_APPLICATION_CREDENTIALS points to an invalid file' do
before do
ENV['GOOGLE_APPLICATION_CREDENTIALS'] = fixture('google_credentials_invalid.json').path
+ FirebaseAdmin.reset
end
it 'raises an error' do
- expect { @client.create_custom_token('user-123') }.to raise_error FirebaseAdmin::InvalidCredentials
+ 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' }
@@ -66,36 +68,40 @@
before do
ENV['GOOGLE_APPLICATION_CREDENTIALS'] = nil
ENV['GOOGLE_CLIENT_EMAIL'] = email
ENV['GOOGLE_PRIVATE_KEY'] = private_key
+ FirebaseAdmin.reset
end
it 'returns a valid JWT token' do
- token = @client.create_custom_token('user-123')
+ 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
+ FirebaseAdmin.reset
end
it 'raises an error' do
- expect { @client.create_custom_token('user-123') }.to raise_error FirebaseAdmin::InvalidCredentials
+ expect {
+ client.create_custom_token('user-123')
+ }.to raise_error FirebaseAdmin::InvalidCredentials
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(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