@@ -19,15 +19,16 @@ import * as chai from 'chai';
19
19
import * as chaiAsPromised from 'chai-as-promised' ;
20
20
import * as firebase from '../src/api' ;
21
21
import { base64 } from '@firebase/util' ;
22
+ import { _FirebaseApp } from '@firebase/app-types/private' ;
22
23
23
24
const expect = chai . expect ;
24
25
25
26
before ( ( ) => {
26
27
chai . use ( chaiAsPromised ) ;
27
28
} ) ;
28
29
29
- describe ( 'Testing Module Tests' , function ( ) {
30
- it ( 'assertSucceeds() iff success' , async function ( ) {
30
+ describe ( 'Testing Module Tests' , function ( ) {
31
+ it ( 'assertSucceeds() iff success' , async function ( ) {
31
32
const success = Promise . resolve ( 'success' ) ;
32
33
const failure = Promise . reject ( 'failure' ) ;
33
34
await firebase . assertSucceeds ( success ) . catch ( ( ) => {
@@ -38,55 +39,64 @@ describe('Testing Module Tests', function() {
38
39
. then ( ( ) => {
39
40
throw new Error ( 'Expected failure to fail.' ) ;
40
41
} )
41
- . catch ( ( ) => { } ) ;
42
+ . catch ( ( ) => { } ) ;
42
43
} ) ;
43
44
44
- it ( 'assertFails() iff failure' , async function ( ) {
45
+ it ( 'assertFails() iff failure' , async function ( ) {
45
46
const success = Promise . resolve ( 'success' ) ;
46
47
const failure = Promise . reject ( 'failure' ) ;
47
48
await firebase
48
49
. assertFails ( success )
49
50
. then ( ( ) => {
50
51
throw new Error ( 'Expected success to fail.' ) ;
51
52
} )
52
- . catch ( ( ) => { } ) ;
53
+ . catch ( ( ) => { } ) ;
53
54
await firebase . assertFails ( failure ) . catch ( ( ) => {
54
55
throw new Error ( 'Expected failure to succeed.' ) ;
55
56
} ) ;
56
57
} ) ;
57
58
58
- it ( 'initializeTestApp() with auth=null does not set access token' , async function ( ) {
59
+ it ( 'initializeTestApp() with auth=null does not set access token' , async function ( ) {
59
60
const app = firebase . initializeTestApp ( {
60
61
projectId : 'foo' ,
61
62
auth : undefined
62
63
} ) ;
63
- const token = await ( app as any ) . INTERNAL . getToken ( ) ;
64
- expect ( token ) . to . be . null ;
64
+
65
+ const authInternal = ( app as unknown as _FirebaseApp )
66
+ . container . getProvider ( 'auth-internal' ) . getImmediate ( { optional : true } ) ;
67
+ // Auth instance will not be available because no API Key is provided
68
+ expect ( authInternal ) . to . be . null ;
65
69
} ) ;
66
70
67
- it ( 'initializeTestApp() with auth sets the correct access token' , async function ( ) {
71
+ it ( 'initializeTestApp() with auth sets the correct access token' , async function ( ) {
68
72
const auth = { uid : 'alice' } ;
69
73
const app = firebase . initializeTestApp ( {
70
74
projectId : 'foo' ,
71
75
auth : auth
72
76
} ) ;
73
- const token = await ( app as any ) . INTERNAL . getToken ( ) ;
77
+ const authInternal = ( app as unknown as _FirebaseApp )
78
+ . container . getProvider ( 'auth-internal' ) . getImmediate ( ) ;
79
+
80
+ const token = await authInternal . getToken ( ) ;
74
81
expect ( token ) . to . have . keys ( 'accessToken' ) ;
75
82
const claims = JSON . parse (
76
- base64 . decodeString ( token . accessToken . split ( '.' ) [ 1 ] , /*webSafe=*/ false )
83
+ base64 . decodeString ( token ! . accessToken . split ( '.' ) [ 1 ] , /*webSafe=*/ false )
77
84
) ;
78
85
// We add an 'iat' field.
79
86
expect ( claims ) . to . deep . equal ( { uid : auth . uid , iat : 0 , sub : auth . uid } ) ;
80
87
} ) ;
81
88
82
- it ( 'initializeAdminApp() sets the access token to "owner"' , async function ( ) {
89
+ it ( 'initializeAdminApp() sets the access token to "owner"' , async function ( ) {
83
90
const app = firebase . initializeAdminApp ( { projectId : 'foo' } ) ;
84
- const token = await ( app as any ) . INTERNAL . getToken ( ) ;
91
+ const authInternal = ( app as unknown as _FirebaseApp )
92
+ . container . getProvider ( 'auth-internal' ) . getImmediate ( ) ;
93
+
94
+ const token = await authInternal . getToken ( ) ;
85
95
expect ( token ) . to . have . keys ( 'accessToken' ) ;
86
- expect ( token . accessToken ) . to . be . string ( 'owner' ) ;
96
+ expect ( token ! . accessToken ) . to . be . string ( 'owner' ) ;
87
97
} ) ;
88
98
89
- it ( 'loadDatabaseRules() throws if no databaseName or rules' , async function ( ) {
99
+ it ( 'loadDatabaseRules() throws if no databaseName or rules' , async function ( ) {
90
100
// eslint-disable-next-line @typescript-eslint/no-explicit-any
91
101
await expect ( ( firebase as any ) . loadDatabaseRules . bind ( null , { } ) ) . to . throw (
92
102
/ d a t a b a s e N a m e n o t s p e c i f i e d /
@@ -101,13 +111,13 @@ describe('Testing Module Tests', function() {
101
111
) . to . throw ( / d a t a b a s e N a m e n o t s p e c i f i e d / ) ;
102
112
} ) ;
103
113
104
- it ( 'loadDatabaseRules() tries to make a network request' , async function ( ) {
114
+ it ( 'loadDatabaseRules() tries to make a network request' , async function ( ) {
105
115
await expect (
106
116
firebase . loadDatabaseRules ( { databaseName : 'foo' , rules : '{}' } )
107
117
) . to . be . rejectedWith ( / E C O N N R E F U S E D / ) ;
108
118
} ) ;
109
119
110
- it ( 'loadFirestoreRules() succeeds on valid input' , async function ( ) {
120
+ it ( 'loadFirestoreRules() succeeds on valid input' , async function ( ) {
111
121
let promise = firebase . loadFirestoreRules ( {
112
122
projectId : 'foo' ,
113
123
rules : `service cloud.firestore {
@@ -119,28 +129,28 @@ describe('Testing Module Tests', function() {
119
129
await expect ( promise ) . to . be . rejectedWith ( / U N A V A I L A B L E / ) ;
120
130
} ) ;
121
131
122
- it ( 'clearFirestoreData() succeeds on valid input' , async function ( ) {
132
+ it ( 'clearFirestoreData() succeeds on valid input' , async function ( ) {
123
133
let promise = firebase . clearFirestoreData ( {
124
134
projectId : 'foo'
125
135
} ) ;
126
136
await expect ( promise ) . to . be . rejectedWith ( / U N A V A I L A B L E / ) ;
127
137
} ) ;
128
138
129
- it ( 'apps() returns apps created with initializeTestApp' , async function ( ) {
139
+ it ( 'apps() returns apps created with initializeTestApp' , async function ( ) {
130
140
const numApps = firebase . apps ( ) . length ;
131
141
await firebase . initializeTestApp ( { databaseName : 'foo' , auth : undefined } ) ;
132
142
expect ( firebase . apps ( ) . length ) . to . equal ( numApps + 1 ) ;
133
143
await firebase . initializeTestApp ( { databaseName : 'bar' , auth : undefined } ) ;
134
144
expect ( firebase . apps ( ) . length ) . to . equal ( numApps + 2 ) ;
135
145
} ) ;
136
146
137
- it ( 'there is a way to get database timestamps' , function ( ) {
147
+ it ( 'there is a way to get database timestamps' , function ( ) {
138
148
expect ( firebase . database . ServerValue . TIMESTAMP ) . to . deep . equal ( {
139
149
'.sv' : 'timestamp'
140
150
} ) ;
141
151
} ) ;
142
152
143
- it ( 'there is a way to get firestore timestamps' , function ( ) {
153
+ it ( 'there is a way to get firestore timestamps' , function ( ) {
144
154
expect ( firebase . firestore . FieldValue . serverTimestamp ( ) ) . not . to . be . null ;
145
155
} ) ;
146
156
} ) ;
0 commit comments