Skip to content

Commit 23e852f

Browse files
committed
Add tests for new api method
1 parent 2238336 commit 23e852f

File tree

1 file changed

+93
-41
lines changed

1 file changed

+93
-41
lines changed

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

Lines changed: 93 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,11 @@ import { testAuth } from '../../../test/mock_auth';
2626
import * as mockFetch from '../../../test/mock_fetch';
2727
import { Auth } from '../../model/auth';
2828
import { ServerError } from '../errors';
29-
import { signInWithEmailLink } from './email_link';
29+
import { signInWithEmailLink, signInWithEmailLinkForLinking } from './email_link';
3030

3131
use(chaiAsPromised);
3232

33-
describe('api/authentication/signInWithEmailLink', () => {
34-
const request = {
35-
36-
oobCode: 'my-code'
37-
};
38-
33+
describe('api/authentication/email_link', () => {
3934
let auth: Auth;
4035

4136
beforeEach(async () => {
@@ -45,44 +40,101 @@ describe('api/authentication/signInWithEmailLink', () => {
4540

4641
afterEach(mockFetch.tearDown);
4742

48-
it('should POST to the correct endpoint', async () => {
49-
const mock = mockEndpoint(Endpoint.SIGN_IN_WITH_EMAIL_LINK, {
50-
displayName: 'my-name',
51-
43+
44+
context('signInWithEmailLink', () => {
45+
const request = {
46+
47+
oobCode: 'my-code'
48+
};
49+
50+
it('should POST to the correct endpoint', async () => {
51+
const mock = mockEndpoint(Endpoint.SIGN_IN_WITH_EMAIL_LINK, {
52+
displayName: 'my-name',
53+
54+
});
55+
56+
const response = await signInWithEmailLink(auth, request);
57+
expect(response.displayName).to.eq('my-name');
58+
expect(response.email).to.eq('[email protected]');
59+
expect(mock.calls[0].request).to.eql(request);
60+
expect(mock.calls[0].method).to.eq('POST');
61+
expect(mock.calls[0].headers).to.eql({
62+
'Content-Type': 'application/json',
63+
'X-Client-Version': 'testSDK/0.0.0'
64+
});
5265
});
5366

54-
const response = await signInWithEmailLink(auth, request);
55-
expect(response.displayName).to.eq('my-name');
56-
expect(response.email).to.eq('[email protected]');
57-
expect(mock.calls[0].request).to.eql(request);
58-
expect(mock.calls[0].method).to.eq('POST');
59-
expect(mock.calls[0].headers).to.eql({
60-
'Content-Type': 'application/json',
61-
'X-Client-Version': 'testSDK/0.0.0'
67+
it('should handle errors', async () => {
68+
const mock = mockEndpoint(
69+
Endpoint.SIGN_IN_WITH_EMAIL_LINK,
70+
{
71+
error: {
72+
code: 400,
73+
message: ServerError.INVALID_EMAIL,
74+
errors: [
75+
{
76+
message: ServerError.INVALID_EMAIL
77+
}
78+
]
79+
}
80+
},
81+
400
82+
);
83+
84+
await expect(signInWithEmailLink(auth, request)).to.be.rejectedWith(
85+
FirebaseError,
86+
'Firebase: The email address is badly formatted. (auth/invalid-email).'
87+
);
88+
expect(mock.calls[0].request).to.eql(request);
6289
});
6390
});
6491

65-
it('should handle errors', async () => {
66-
const mock = mockEndpoint(
67-
Endpoint.SIGN_IN_WITH_EMAIL_LINK,
68-
{
69-
error: {
70-
code: 400,
71-
message: ServerError.INVALID_EMAIL,
72-
errors: [
73-
{
74-
message: ServerError.INVALID_EMAIL
75-
}
76-
]
77-
}
78-
},
79-
400
80-
);
81-
82-
await expect(signInWithEmailLink(auth, request)).to.be.rejectedWith(
83-
FirebaseError,
84-
'Firebase: The email address is badly formatted. (auth/invalid-email).'
85-
);
86-
expect(mock.calls[0].request).to.eql(request);
92+
context('signInWithEmailLinkForLinking', () => {
93+
const request = {
94+
95+
oobCode: 'my-code',
96+
idToken: 'id-token-2',
97+
};
98+
99+
it('should POST to the correct endpoint', async () => {
100+
const mock = mockEndpoint(Endpoint.SIGN_IN_WITH_EMAIL_LINK, {
101+
displayName: 'my-name',
102+
103+
});
104+
105+
const response = await signInWithEmailLinkForLinking(auth, request);
106+
expect(response.displayName).to.eq('my-name');
107+
expect(response.email).to.eq('[email protected]');
108+
expect(mock.calls[0].request).to.eql(request);
109+
expect(mock.calls[0].method).to.eq('POST');
110+
expect(mock.calls[0].headers).to.eql({
111+
'Content-Type': 'application/json',
112+
'X-Client-Version': 'testSDK/0.0.0'
113+
});
114+
});
115+
116+
it('should handle errors', async () => {
117+
const mock = mockEndpoint(
118+
Endpoint.SIGN_IN_WITH_EMAIL_LINK,
119+
{
120+
error: {
121+
code: 400,
122+
message: ServerError.INVALID_EMAIL,
123+
errors: [
124+
{
125+
message: ServerError.INVALID_EMAIL
126+
}
127+
]
128+
}
129+
},
130+
400
131+
);
132+
133+
await expect(signInWithEmailLinkForLinking(auth, request)).to.be.rejectedWith(
134+
FirebaseError,
135+
'Firebase: The email address is badly formatted. (auth/invalid-email).'
136+
);
137+
expect(mock.calls[0].request).to.eql(request);
138+
});
87139
});
88140
});

0 commit comments

Comments
 (0)