Skip to content

Commit 73da5d2

Browse files
committed
chore: add unit test
1 parent fda717e commit 73da5d2

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*!
2+
* @license
3+
* Copyright 2025 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+
'use strict';
19+
20+
import { expect } from 'chai';
21+
import {
22+
FirebaseFpnvError,
23+
CLIENT_CERT_URL,
24+
PN_TOKEN_INFO,
25+
FPNV_ERROR_CODE_MAPPING
26+
} from '../../../src/fpnv/fpnv-api-client-internal';
27+
import { PrefixedFirebaseError, FirebaseError } from '../../../src/utils/error';
28+
29+
const FPNV_PREFIX = 'fpnv';
30+
31+
describe('FPNV Constants and Error Class', () => {
32+
33+
describe('Constants Integrity', () => {
34+
it('should have the correct CLIENT_CERT_URL', () => {
35+
expect(CLIENT_CERT_URL).to.equal('https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com');
36+
});
37+
38+
it('should have the correct structure and values for PN_TOKEN_INFO', () => {
39+
expect(PN_TOKEN_INFO).to.be.an('object');
40+
expect(PN_TOKEN_INFO).to.have.all.keys('url', 'verifyApiName', 'jwtName', 'shortName', 'typ');
41+
expect(PN_TOKEN_INFO.shortName).to.equal('FPNV token');
42+
expect(PN_TOKEN_INFO.typ).to.equal('JWT');
43+
});
44+
45+
it('should have the correct structure and values for FPNV_ERROR_CODE_MAPPING', () => {
46+
expect(FPNV_ERROR_CODE_MAPPING).to.be.an('object');
47+
expect(FPNV_ERROR_CODE_MAPPING).to.deep.equal({
48+
INVALID_ARGUMENT: 'invalid-argument',
49+
INVALID_TOKEN: 'invalid-token',
50+
EXPIRED_TOKEN: 'expired-token',
51+
});
52+
});
53+
});
54+
55+
describe('FirebaseFpnvError', () => {
56+
const testCode = FPNV_ERROR_CODE_MAPPING.INVALID_TOKEN;
57+
const testMessage = 'The provided token is malformed or invalid.';
58+
59+
it('should correctly extend PrefixedFirebaseError', () => {
60+
const error = new FirebaseFpnvError(testCode, testMessage);
61+
62+
expect(error).to.be.an.instanceOf(FirebaseFpnvError);
63+
expect(error).to.be.an.instanceOf(PrefixedFirebaseError);
64+
expect(error).to.be.an.instanceOf(FirebaseError);
65+
expect(error).to.be.an.instanceOf(Error);
66+
});
67+
68+
69+
it('should have the correct error properties on the instance', () => {
70+
const error = new FirebaseFpnvError(testCode, testMessage);
71+
72+
expect(error.code).to.equal(`${FPNV_PREFIX}/${testCode}`);
73+
expect(error.message).to.equal(testMessage);
74+
});
75+
76+
it('should handle all defined error codes', () => {
77+
const codes = Object.values(FPNV_ERROR_CODE_MAPPING);
78+
79+
codes.forEach(code => {
80+
const error = new FirebaseFpnvError(code, `Test message for ${code}`);
81+
expect(error.code).to.equal(`${FPNV_PREFIX}/${code}`);
82+
});
83+
});
84+
});
85+
});

test/unit/index.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,4 @@ import './data-connect/validate-admin-args.spec';
126126

127127
// Fpnv
128128
import './fpnv/index.spec';
129+
import './fpnv/fpnv-api-client-internal.spec';

0 commit comments

Comments
 (0)