|
1 | 1 | require File.expand_path('../../spec_helper', __dir__) |
2 | 2 |
|
3 | 3 | describe FirebaseAdmin::Client do |
4 | | - before do |
5 | | - @client = FirebaseAdmin::Client.new(project_id: 'test-project') |
6 | | - end |
| 4 | + let(:client) { FirebaseAdmin::Client.new(project_id: 'test-project') } |
7 | 5 |
|
8 | 6 | describe '.create_account' do |
9 | 7 | before do |
|
12 | 10 | end |
13 | 11 |
|
14 | 12 | it 'should get the correct resource' do |
15 | | - @client.create_account(email: 'john@smith.com', password: 'supersecret') |
| 13 | + client.create_account(email: 'john@smith.com', password: 'supersecret') |
16 | 14 | expect( |
17 | 15 | a_post('v1/projects/test-project/accounts') |
18 | 16 | .with(body: { email: 'john@smith.com', password: 'supersecret' }.to_json) |
|
28 | 26 | end |
29 | 27 |
|
30 | 28 | it 'should post to the update endpoint' do |
31 | | - @client.update_account(email: 'john@smith.com', password: 'supersecret') |
| 29 | + client.update_account(email: 'john@smith.com', password: 'supersecret') |
32 | 30 | expect( |
33 | 31 | a_post('v1/projects/test-project/accounts:update') |
34 | 32 | .with(body: { email: 'john@smith.com', password: 'supersecret' }.to_json) |
|
41 | 39 | context 'when credentials are set via GOOGLE_APPLICATION_CREDENTIALS' do |
42 | 40 | before do |
43 | 41 | ENV['GOOGLE_APPLICATION_CREDENTIALS'] = fixture('google_credentials.json').path |
| 42 | + FirebaseAdmin.reset |
44 | 43 | end |
45 | 44 |
|
46 | 45 | it 'returns a valid JWT token' do |
47 | | - token = @client.create_custom_token('user-123') |
| 46 | + token = client.create_custom_token('user-123') |
48 | 47 | token_data, _alg = JWT.decode(token, nil, false) |
49 | 48 | expect(token_data['uid']).to eq('user-123') |
50 | 49 | end |
|
53 | 52 | context 'when GOOGLE_APPLICATION_CREDENTIALS points to an invalid file' do |
54 | 53 | before do |
55 | 54 | ENV['GOOGLE_APPLICATION_CREDENTIALS'] = fixture('google_credentials_invalid.json').path |
| 55 | + FirebaseAdmin.reset |
56 | 56 | end |
57 | 57 |
|
58 | 58 | it 'raises an error' do |
59 | | - expect { @client.create_custom_token('user-123') }.to raise_error FirebaseAdmin::InvalidCredentials |
| 59 | + expect { |
| 60 | + client.create_custom_token('user-123') |
| 61 | + }.to raise_error FirebaseAdmin::InvalidCredentials |
60 | 62 | end |
61 | 63 | end |
62 | 64 |
|
|
68 | 70 | ENV['GOOGLE_APPLICATION_CREDENTIALS'] = nil |
69 | 71 | ENV['GOOGLE_CLIENT_EMAIL'] = email |
70 | 72 | ENV['GOOGLE_PRIVATE_KEY'] = private_key |
| 73 | + FirebaseAdmin.reset |
71 | 74 | end |
72 | 75 |
|
73 | 76 | it 'returns a valid JWT token' do |
74 | | - token = @client.create_custom_token('user-123') |
| 77 | + token = client.create_custom_token('user-123') |
75 | 78 | token_data, _alg = JWT.decode(token, nil, false) |
76 | 79 | expect(token_data['uid']).to eq('user-123') |
77 | 80 | end |
|
82 | 85 | ENV['GOOGLE_APPLICATION_CREDENTIALS'] = nil |
83 | 86 | ENV['GOOGLE_CLIENT_EMAIL'] = nil |
84 | 87 | ENV['GOOGLE_PRIVATE_KEY'] = nil |
| 88 | + FirebaseAdmin.reset |
85 | 89 | end |
86 | 90 |
|
87 | 91 | it 'raises an error' do |
88 | | - expect { @client.create_custom_token('user-123') }.to raise_error FirebaseAdmin::InvalidCredentials |
| 92 | + expect { |
| 93 | + client.create_custom_token('user-123') |
| 94 | + }.to raise_error FirebaseAdmin::InvalidCredentials |
89 | 95 | end |
90 | 96 | end |
91 | 97 | end |
92 | 98 |
|
93 | 99 | describe '.sign_in_for_uid' do |
94 | 100 | it 'should post to the update endpoint' do |
95 | | - expect(@client).to receive(:create_custom_token).with('user-123').and_return('token') |
96 | | - expect(@client).to receive(:sign_in_with_custom_token).with('token').and_return('result') |
97 | | - result = @client.sign_in_for_uid('user-123') |
| 101 | + expect(client).to receive(:create_custom_token).with('user-123').and_return('token') |
| 102 | + expect(client).to receive(:sign_in_with_custom_token).with('token').and_return('result') |
| 103 | + result = client.sign_in_for_uid('user-123') |
98 | 104 | expect(result).to eq('result') |
99 | 105 | end |
100 | 106 | end |
|
0 commit comments