Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add signUp API method for auth-next #2892

Merged
merged 6 commits into from
Apr 13, 2020
Prev Previous commit
Next Next commit
Update tests to test a little more
  • Loading branch information
avolkovi committed Apr 10, 2020
commit 4f95dddb4c44c1a08133329825e479dab54e20db
4 changes: 1 addition & 3 deletions packages-exp/auth-exp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@
},
"dependencies": {
"@firebase/util": "^0.2.44",
"mocha": "^7.1.1",
"tslib": "1.11.1"
},
"license": "Apache-2.0",
"devDependencies": {
"rollup": "1.32.1",
"rollup-plugin-json": "4.0.0",
"rollup-plugin-replace": "2.2.0",
"rollup-plugin-typescript2": "0.26.0",
"typescript": "3.8.3"
"rollup-plugin-typescript2": "0.26.0"
},
"repository": {
"directory": "packages-exp/auth-exp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
* limitations under the License.
*/

import * as mockFetch from '../../mock_fetch';
import { signUp, SignUpRequest } from '../../../src/api/authentication/sign_up';
import { expect } from 'chai';
import { Endpoint } from '../../../src/api';
import { ServerError } from '../../../src/api/errors';
import { mockEndpoint, mockAuth } from '../helper';
import { expect, use } from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import { signUp, SignUpRequest } from './sign_up';
import { Endpoint } from '..';
import { ServerError } from '../errors';
import { FirebaseError } from '@firebase/util';
import * as mockFetch from '../../../test/mock_fetch';
import { mockEndpoint, mockAuth } from '../../../test/api/helper';

use(chaiAsPromised);

describe('signUp', () => {
avolkovi marked this conversation as resolved.
Show resolved Hide resolved
const request: SignUpRequest = {
Expand All @@ -41,9 +45,9 @@ describe('signUp', () => {
const response = await signUp(mockAuth, request);
expect(response.displayName).to.eq('my-name');
expect(response.email).to.eq('test@foo.com');
expect(mock.calls[0]).to.eql({
request
});
expect(mock.calls[0].request).to.eql(request);
expect(mock.calls[0].method).to.eq('POST');
expect(mock.calls[0].headers).to.eql({ 'Content-Type': 'application/json' });
});

it('should handle errors', async () => {
Expand All @@ -63,16 +67,9 @@ describe('signUp', () => {
400
);

try {
await signUp(mockAuth, request);
} catch (e) {
expect(e.name).to.eq('FirebaseError');
expect(e.message).to.eq(
'Firebase: The email address is already in use by another account. (auth/email-already-in-use).'
);
expect(mock.calls[0]).to.eql({
request
});
}
await expect(signUp(mockAuth, request)).to.be.rejectedWith(FirebaseError, 'Firebase: The email address is already in use by another account. (auth/email-already-in-use).');
expect(mock.calls[0].request).to.eql(
request
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { expect } from 'chai';
import { AUTH_ERROR_FACTORY, AuthErrorCode } from '../../src/core/errors';
import { AUTH_ERROR_FACTORY, AuthErrorCode } from './errors';

describe('AUTH_ERROR_FACTORY', () => {
it('should create an Auth namespaced FirebaseError', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages-exp/auth-exp/test/mock_fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { stub, SinonStub } from 'sinon';

export interface Call {
request?: object;
method?: string;
headers?: HeadersInit;
}

export interface Route {
Expand All @@ -44,7 +46,9 @@ const fakeFetch: typeof fetch = (input: RequestInfo, request?: RequestInit) => {
const { response, status, calls } = routes.get(input)!;

calls.push({
request: request?.body ? JSON.parse(request.body as string) : undefined
request: request?.body ? JSON.parse(request.body as string) : undefined,
method: request?.method,
headers: request?.headers
});

const blob = new Blob([JSON.stringify(response)]);
Expand Down