Skip to content

Commit 42a0f85

Browse files
committed
Add unit tests
1 parent c30644a commit 42a0f85

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

packages/auth/src/api/authentication/token.test.ts

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import chaiAsPromised from 'chai-as-promised';
2222
import { FirebaseError, getUA, querystringDecode } from '@firebase/util';
2323

2424
import { Endpoint, HttpHeader } from '../';
25+
import { mockEndpoint } from '../../../test/helpers/api/helper';
2526
import { testAuth, TestAuth } from '../../../test/helpers/mock_auth';
2627
import * as fetch from '../../../test/helpers/mock_fetch';
2728
import { ServerError } from '../errors';
28-
import { requestStsToken } from './token';
29+
import { TokenType, requestStsToken, revokeToken } from './token';
2930
import { SDK_VERSION } from '@firebase/app';
3031
import { _getBrowserName } from '../../core/util/browser';
3132

@@ -143,3 +144,63 @@ describe('requestStsToken', () => {
143144
});
144145
});
145146
});
147+
148+
describe('api/authentication/revokeToken', () => {
149+
const request = {
150+
provider_id: 'provider-id',
151+
tokenType: TokenType.ACCESS_TOKEN,
152+
token: 'token',
153+
idToken: 'id-token'
154+
};
155+
156+
let auth: TestAuth;
157+
158+
beforeEach(async () => {
159+
auth = await testAuth();
160+
fetch.setUp();
161+
});
162+
163+
afterEach(() => {
164+
fetch.tearDown();
165+
});
166+
167+
it('should POST to the correct endpoint', async () => {
168+
const mock = mockEndpoint(Endpoint.REVOKE_TOKEN, {});
169+
170+
auth.tenantId = 'tenant-id';
171+
const response = await revokeToken(auth, request);
172+
// Currently, backend returns an empty response.
173+
expect(mock.calls[0].request).to.eql({ ...request, tenantId: 'tenant-id' });
174+
expect(mock.calls[0].method).to.eq('POST');
175+
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
176+
'application/json'
177+
);
178+
expect(mock.calls[0].headers!.get(HttpHeader.X_CLIENT_VERSION)).to.eq(
179+
'testSDK/0.0.0'
180+
);
181+
});
182+
183+
it('should handle errors', async () => {
184+
const mock = mockEndpoint(
185+
Endpoint.REVOKE_TOKEN,
186+
{
187+
error: {
188+
code: 400,
189+
message: ServerError.INVALID_IDP_RESPONSE,
190+
errors: [
191+
{
192+
message: ServerError.INVALID_IDP_RESPONSE
193+
}
194+
]
195+
}
196+
},
197+
400
198+
);
199+
200+
await expect(revokeToken(auth, request)).to.be.rejectedWith(
201+
FirebaseError,
202+
'Firebase: The supplied auth credential is malformed or has expired. (auth/invalid-credential).'
203+
);
204+
expect(mock.calls[0].request).to.eql(request);
205+
});
206+
});

0 commit comments

Comments
 (0)