|
17 | 17 |
|
18 | 18 | import { expect, use } from 'chai';
|
19 | 19 | import * as chaiAsPromised from 'chai-as-promised';
|
| 20 | +import * as sinon from 'sinon'; |
| 21 | +import * as sinonChai from 'sinon-chai'; |
20 | 22 |
|
21 | 23 | import { FirebaseError } from '@firebase/util';
|
22 | 24 |
|
| 25 | +import { mockEndpoint } from '../../../test/api/helper'; |
23 | 26 | import { makeJWT } from '../../../test/jwt';
|
24 | 27 | import { mockAuth } from '../../../test/mock_auth';
|
| 28 | +import * as fetch from '../../../test/mock_fetch'; |
| 29 | +import { Endpoint } from '../../api'; |
25 | 30 | import { IdTokenResponse } from '../../model/id_token';
|
26 | 31 | import { StsTokenManager } from './token_manager';
|
27 | 32 | import { UserImpl } from './user_impl';
|
28 | 33 |
|
| 34 | +use(sinonChai); |
29 | 35 | use(chaiAsPromised);
|
30 | 36 |
|
31 | 37 | describe('core/user/user_impl', () => {
|
32 | 38 | const auth = mockAuth;
|
33 | 39 | let stsTokenManager: StsTokenManager;
|
34 | 40 |
|
35 | 41 | beforeEach(() => {
|
| 42 | + fetch.setUp(); |
36 | 43 | stsTokenManager = new StsTokenManager();
|
37 | 44 | });
|
38 | 45 |
|
| 46 | + afterEach(() => { |
| 47 | + sinon.restore(); |
| 48 | + fetch.tearDown(); |
| 49 | + }); |
| 50 | + |
39 | 51 | describe('.constructor', () => {
|
40 | 52 | it('attaches required fields', () => {
|
41 | 53 | const user = new UserImpl({ uid: 'uid', auth, stsTokenManager });
|
@@ -116,9 +128,22 @@ describe('core/user/user_impl', () => {
|
116 | 128 | });
|
117 | 129 |
|
118 | 130 | describe('#delete', () => {
|
119 |
| - it('throws', () => { |
| 131 | + it('calls delete endpoint', async () => { |
| 132 | + stsTokenManager.updateFromServerResponse({ |
| 133 | + idToken: 'id-token', |
| 134 | + refreshToken: 'refresh-token-string', |
| 135 | + expiresIn: '100000' |
| 136 | + } as IdTokenResponse); |
120 | 137 | const user = new UserImpl({ uid: 'uid', auth, stsTokenManager });
|
121 |
| - expect(() => user.delete()).to.throw(); |
| 138 | + const endpoint = mockEndpoint(Endpoint.DELETE_ACCOUNT, {}); |
| 139 | + const signOut = sinon.stub(auth, 'signOut'); |
| 140 | + |
| 141 | + await user.delete(); |
| 142 | + expect(endpoint.calls[0].request).to.eql({ |
| 143 | + idToken: 'id-token', |
| 144 | + }); |
| 145 | + |
| 146 | + expect(signOut).to.have.been.called; |
122 | 147 | });
|
123 | 148 | });
|
124 | 149 |
|
|
0 commit comments