Skip to content

Commit 68c21c7

Browse files
committed
Add API call to signUp
1 parent a334c04 commit 68c21c7

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

packages-exp/auth-exp/src/core/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2019 Google LLC
3+
* Copyright 2020 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

packages-exp/auth-exp/src/model/auth.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2019 Google LLC
3+
* Copyright 2020 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import * as mockFetch from '../../mock_fetch';
19+
import { signUp, SignUpRequest } from '../../../src/api/authentication/sign_up';
20+
import { expect } from 'chai';
21+
import { Endpoint } from '../../../src/api';
22+
import { ServerError } from '../../../src/api/errors';
23+
import { mockEndpoint, mockAuth } from '../helper';
24+
25+
describe('signUp', () => {
26+
const request: SignUpRequest = {
27+
returnSecureToken: true,
28+
29+
password: 'my-password'
30+
};
31+
32+
beforeEach(mockFetch.setUp);
33+
afterEach(mockFetch.tearDown);
34+
35+
it('should POST to the correct endpoint', async () => {
36+
const mock = mockEndpoint(Endpoint.SIGN_UP, { displayName: 'my-name', email: '[email protected]' });
37+
38+
const response = await signUp(mockAuth, request);
39+
expect(response.displayName).to.eq('my-name');
40+
expect(response.email).to.eq('[email protected]');
41+
expect(mock.calls[0]).to.eql({
42+
request
43+
});
44+
});
45+
46+
it('should handle errors', async () => {
47+
const mock = mockEndpoint(Endpoint.SIGN_UP, {
48+
error: {
49+
code: 400,
50+
message: ServerError.EMAIL_EXISTS,
51+
errors: [
52+
{
53+
message: ServerError.EMAIL_EXISTS,
54+
}
55+
]
56+
}
57+
}, 400);
58+
59+
try {
60+
await signUp(mockAuth, request);
61+
} catch (e) {
62+
expect(e.name).to.eq('FirebaseError');
63+
expect(e.message).to.eq('Firebase: The email address is already in use by another account. (auth/email-already-in-use).');
64+
expect(mock.calls[0]).to.eql({
65+
request
66+
});
67+
}
68+
});
69+
});

0 commit comments

Comments
 (0)