Skip to content

Commit 66d7e79

Browse files
sam-gcavolkovi
authored andcommitted
Consolidate mock auth object, add user object (#2906)
* Consolidate mock auth / add user test helper * [AUTOMATED]: Prettier Code Styling * Fix tests
1 parent 65444de commit 66d7e79

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

packages-exp/auth-exp/src/api/authentication/sign_up.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import { Endpoint } from '..';
2222
import { ServerError } from '../errors';
2323
import { FirebaseError } from '@firebase/util';
2424
import * as mockFetch from '../../../test/mock_fetch';
25-
import { mockEndpoint, mockAuth } from '../../../test/api/helper';
25+
import { mockEndpoint } from '../../../test/api/helper';
26+
import { mockAuth } from '../../../test/mock_auth';
2627

2728
use(chaiAsPromised);
2829

packages-exp/auth-exp/src/core/user/user_impl.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
import { expect, use } from 'chai';
1919
import * as chaiAsPromised from 'chai-as-promised';
2020
import { UserImpl } from './user_impl';
21-
import { mockAuth } from '../../../test/mock_auth';
2221
import { StsTokenManager } from './token_manager';
2322
import { IdTokenResponse } from '../../model/id_token';
23+
import { mockAuth } from '../../../test/mock_auth';
2424

2525
use(chaiAsPromised);
2626

2727
describe('core/user/user_impl', () => {
28-
const auth = mockAuth('foo', 'i-am-the-api-key');
28+
const auth = mockAuth;
2929
let stsTokenManager: StsTokenManager;
3030

3131
beforeEach(() => {

packages-exp/auth-exp/test/api/helper.ts

+1-14
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { Auth } from '../../src/model/auth';
1918
import { Endpoint } from '../../src/api';
2019
import { mock, Route } from '../mock_fetch';
21-
22-
const TEST_HOST = 'localhost';
23-
const TEST_SCHEME = 'mock';
24-
const TEST_KEY = 'test-api-key';
25-
26-
export const mockAuth: Auth = {
27-
name: 'test-app',
28-
config: {
29-
apiKey: 'test-api-key',
30-
apiHost: TEST_HOST,
31-
apiScheme: TEST_SCHEME
32-
}
33-
};
20+
import { TEST_SCHEME, TEST_HOST, TEST_KEY } from '../mock_auth';
3421

3522
export function mockEndpoint(
3623
endpoint: Endpoint,

packages-exp/auth-exp/test/mock_auth.ts

+23-8
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,28 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { AppName, ApiKey, Auth } from '../src/model/auth';
18+
import { Auth } from '../src/model/auth';
19+
import { User } from '../src/model/user';
20+
import { UserImpl } from '../src/core/user/user_impl';
21+
import { StsTokenManager } from '../src/core/user/token_manager';
1922

20-
export function mockAuth(name: AppName, apiKey: ApiKey): Auth {
21-
return {
22-
name,
23-
config: {
24-
apiKey
25-
}
26-
};
23+
export const TEST_HOST = 'localhost';
24+
export const TEST_SCHEME = 'mock';
25+
export const TEST_KEY = 'test-api-key';
26+
27+
export const mockAuth: Auth = {
28+
name: 'test-app',
29+
config: {
30+
apiKey: TEST_KEY,
31+
apiHost: TEST_HOST,
32+
apiScheme: TEST_SCHEME
33+
}
34+
};
35+
36+
export function testUser(uid: string): User {
37+
return new UserImpl({
38+
uid,
39+
auth: mockAuth,
40+
stsTokenManager: new StsTokenManager()
41+
});
2742
}

0 commit comments

Comments
 (0)