Skip to content

Commit 1e842ca

Browse files
committed
test(integration): migrate app-check integration tests to modular API
1 parent db4f6ad commit 1e842ca

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

test/integration/app-check.spec.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import * as _ from 'lodash';
18-
import * as admin from '../../lib/index';
18+
import { getAppCheck, AppCheckToken } from '../../lib/app-check/index';
1919
import * as chai from 'chai';
2020
import * as chaiAsPromised from 'chai-as-promised';
2121
import fs = require('fs');
@@ -47,7 +47,7 @@ describe('admin.appCheck', () => {
4747
if (!appId) {
4848
this.skip();
4949
}
50-
return admin.appCheck().createToken(appId as string)
50+
return getAppCheck().createToken(appId as string)
5151
.then((token) => {
5252
expect(token).to.have.keys(['token', 'ttlMillis']);
5353
expect(token.token).to.be.a('string').and.to.not.be.empty;
@@ -60,7 +60,7 @@ describe('admin.appCheck', () => {
6060
if (!appId) {
6161
this.skip();
6262
}
63-
return admin.appCheck().createToken(appId as string, { limitedUse: true })
63+
return getAppCheck().createToken(appId as string, { limitedUse: true })
6464
.then((token) => {
6565
expect(token).to.have.keys(['token', 'ttlMillis']);
6666
expect(token.token).to.be.a('string').and.to.not.be.empty;
@@ -73,7 +73,7 @@ describe('admin.appCheck', () => {
7373
if (!appId) {
7474
this.skip();
7575
}
76-
return admin.appCheck().createToken(appId as string, { ttlMillis: 1800000 })
76+
return getAppCheck().createToken(appId as string, { ttlMillis: 1800000 })
7777
.then((token) => {
7878
expect(token).to.have.keys(['token', 'ttlMillis']);
7979
expect(token.token).to.be.a('string').and.to.not.be.empty;
@@ -84,35 +84,35 @@ describe('admin.appCheck', () => {
8484

8585
it('should propagate API errors', () => {
8686
// rejects with invalid-argument when appId is incorrect
87-
return admin.appCheck().createToken('incorrect-app-id')
87+
return getAppCheck().createToken('incorrect-app-id')
8888
.should.eventually.be.rejected.and.have.property('code', 'app-check/invalid-argument');
8989
});
9090

9191
const invalidAppIds = ['', null, NaN, 0, 1, true, false, [], {}, { a: 1 }, _.noop];
9292
invalidAppIds.forEach((invalidAppId) => {
9393
it(`should throw given an invalid appId: ${JSON.stringify(invalidAppId)}`, () => {
94-
expect(() => admin.appCheck().createToken(invalidAppId as any))
94+
expect(() => getAppCheck().createToken(invalidAppId as any))
9595
.to.throw('appId` must be a non-empty string.');
9696
});
9797
});
9898
});
9999

100100
describe('verifyToken', () => {
101-
let validToken: admin.appCheck.AppCheckToken;
101+
let validToken: AppCheckToken;
102102

103103
before(async () => {
104104
if (!appId) {
105105
return;
106106
}
107107
// obtain a valid app check token
108-
validToken = await admin.appCheck().createToken(appId as string);
108+
validToken = await getAppCheck().createToken(appId as string);
109109
});
110110

111111
it('should succeed with a decoded verifed token response', function() {
112112
if (!appId) {
113113
this.skip();
114114
}
115-
return admin.appCheck().verifyToken(validToken.token)
115+
return getAppCheck().verifyToken(validToken.token)
116116
.then((verifedToken) => {
117117
expect(verifedToken).to.have.keys(['token', 'appId']);
118118
expect(verifedToken.token).to.include.keys(['iss', 'sub', 'aud', 'exp', 'iat', 'app_id']);
@@ -122,8 +122,9 @@ describe('admin.appCheck', () => {
122122

123123
it('should propagate API errors', () => {
124124
// rejects with invalid-argument when the token is invalid
125-
return admin.appCheck().verifyToken('invalid-token')
125+
return getAppCheck().verifyToken('invalid-token')
126126
.should.eventually.be.rejected.and.have.property('code', 'app-check/invalid-argument');
127127
});
128128
});
129129
});
130+

0 commit comments

Comments
 (0)