@firebase/rules-unit-testing 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,228 +1,228 @@
1
- /**
2
- * @license
3
- * Copyright 2021 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
- import { FirebaseSignInProvider } from '@firebase/util';
18
- import firebase from 'firebase/compat/app';
19
- import 'firebase/compat/database';
20
- import 'firebase/compat/firestore';
21
- import 'firebase/compat/storage';
22
- /**
23
- * More options for the mock user token to be used for testing, including developer-specified custom
24
- * claims or optional overrides for Firebase Auth token payloads.
25
- * @public
26
- */
27
- export declare type TokenOptions = {
28
- /** The token issue time, in seconds since epoch */
29
- iat?: number;
30
- /** The token expiry time, normally 'iat' + 3600 */
31
- exp?: number;
32
- /** The time the user authenticated, normally 'iat' */
33
- auth_time?: number;
34
- /** The sign in provider, only set when the provider is 'anonymous' */
35
- provider_id?: 'anonymous';
36
- /** The user's primary email */
37
- email?: string;
38
- /** The user's email verification status */
39
- email_verified?: boolean;
40
- /** The user's primary phone number */
41
- phone_number?: string;
42
- /** The user's display name */
43
- name?: string;
44
- /** The user's profile photo URL */
45
- picture?: string;
46
- /** Information on all identities linked to this user */
47
- firebase?: {
48
- /** The primary sign-in provider */
49
- sign_in_provider: FirebaseSignInProvider;
50
- /** A map of providers to the user's list of unique identifiers from each provider */
51
- identities?: {
52
- [provider in FirebaseSignInProvider]?: string[];
53
- };
54
- };
55
- /** Set to PROJECT_ID by default. In rare cases, you may want to specify an override. */
56
- aud?: string;
57
- /** Set to https://securetoken.google.com/PROJECT_ID by default. In rare cases, you may want to specify an override. */
58
- iss?: string;
59
- /** Custom claims set by the developer */
60
- [claim: string]: unknown;
61
- /** DO NOT USE. The user ID MUST be specified as the first param in authenticatedContext(uid, options) instead. */
62
- uid?: never;
63
- /** DO NOT USE. The user ID MUST be specified as the first param in authenticatedContext(uid, options) instead. */
64
- sub?: never;
65
- /** DO NOT USE. The user ID MUST be specified as the first param in authenticatedContext(uid, options) instead. */
66
- user_id?: never;
67
- };
68
- /**
69
- * Configuration of the unit testing environment, including emulators.
70
- * @public
71
- */
72
- export interface TestEnvironmentConfig {
73
- /**
74
- * The project ID of the test environment. Can also be specified via the environment variable GCLOUD_PROJECT.
75
- *
76
- * A "demo-*" project ID is strongly recommended, especially for unit testing.
77
- * See: https://firebase.google.com/docs/emulator-suite/connect_firestore#choose_a_firebase_project
78
- */
79
- projectId?: string;
80
- /**
81
- * The Firebase Emulator hub. Can also be specified via the environment variable FIREBASE_EMULATOR_HUB.
82
- * If specified either way, other running emulators can be automatically discovered, and thus do
83
- * not to be explicity specified.
84
- */
85
- hub?: HostAndPort;
86
- /**
87
- * The Database emulator. Its host and port can also be discovered automatically through the hub
88
- * (see field "hub") or specified via the environment variable FIREBASE_DATABASE_EMULATOR_HOST.
89
- */
90
- database?: EmulatorConfig;
91
- /**
92
- * The Firestore emulator. Its host and port can also be discovered automatically through the hub
93
- * (see field "hub") or specified via the environment variable FIRESTORE_EMULATOR_HOST.
94
- */
95
- firestore?: EmulatorConfig;
96
- /**
97
- * The Storage emulator. Its host and port can also be discovered automatically through the hub
98
- * (see field "hub") or specified via the environment variable FIREBASE_STORAGE_EMULATOR_HOST.
99
- */
100
- storage?: EmulatorConfig;
101
- }
102
- /**
103
- * An object containing the hostname and port number of an emulator.
104
- * @public
105
- */
106
- export interface HostAndPort {
107
- /**
108
- * The host of the emulator. Can be omitted if discovered automatically through the hub or
109
- * specified via environment variables. See `TestEnvironmentConfig` for details.
110
- */
111
- host: string;
112
- /**
113
- * The port of the emulator. Can be omitted if discovered automatically through the hub or
114
- * specified via environment variables. See `TestEnvironmentConfig` for details.
115
- */
116
- port: number;
117
- }
118
- /**
119
- * Configuration for a given emulator.
120
- * @public
121
- */
122
- export declare type EmulatorConfig = {
123
- /** The security rules source code under test for this emulator. Strongly recommended. */
124
- rules?: string;
125
- } & (HostAndPort | {});
126
- /**
127
- * An object used to control the rules unit test environment. Can be used to create RulesTestContext
128
- * for different authentication situations.
129
- * @public
130
- */
131
- export interface RulesTestEnvironment {
132
- /** The project ID specified or discovered at test environment creation. */
133
- readonly projectId: string;
134
- /**
135
- * A readonly copy of the emulator config specified or discovered at test environment creation.
136
- */
137
- readonly emulators: {
138
- database?: HostAndPort;
139
- firestore?: HostAndPort;
140
- storage?: HostAndPort;
141
- };
142
- /**
143
- * Create a `RulesTestContext` which behaves like an authenticated Firebase Auth user.
144
- *
145
- * Requests created via the returned context will have a mock Firebase Auth token attached.
146
- *
147
- * @param user_id - the User ID of the user. Specifies the value of "user_id" and "sub" on the token
148
- * @param tokenOptions - custom claims or overrides for Firebase Auth token payloads
149
- *
150
- * @example
151
- * ```javascript
152
- * const alice = testEnv.authenticatedContext('alice');
153
- * await assertSucceeds(get(doc(alice.firestore(), '/doc/readable/by/alice'), { ... });
154
- * ```
155
- */
156
- authenticatedContext(user_id: string, tokenOptions?: TokenOptions): RulesTestContext;
157
- /**
158
- * Create a `RulesTestContext` which behaves like client that is NOT logged in via Firebase
159
- * Auth.
160
- *
161
- * Requests created via the returned context will not have Firebase Auth tokens attached.
162
- *
163
- * @example
164
- * ```javascript
165
- * const unauthed = testEnv.unauthenticatedContext();
166
- * await assertFails(get(doc(unauthed.firestore(), '/private/doc'), { ... });
167
- * ```
168
- */
169
- unauthenticatedContext(): RulesTestContext;
170
- withSecurityRulesDisabled(callback: (context: RulesTestContext) => Promise<void>): Promise<void>;
171
- /**
172
- * Clear all data in the Realtime Database emulator namespace.
173
- */
174
- clearDatabase(): Promise<void>;
175
- /**
176
- * Clear data in the Firestore that belongs to the `projectId` in the Firestore emulator.
177
- */
178
- clearFirestore(): Promise<void>;
179
- /**
180
- * Clear Storage files and metadata in all buckets in the Storage emulator.
181
- */
182
- clearStorage(): Promise<void>;
183
- /**
184
- * At the very end of your test code, call the cleanup function. Destroy all RulesTestContexts
185
- * created in test environment and clean up the underlying resources, allowing a clean exit.
186
- *
187
- * This method does not change the state in emulators in any way. To reset data between tests,
188
- * see `clearDatabase()`, `clearFirestore()` and `clearStorage()`.
189
- */
190
- cleanup(): Promise<void>;
191
- }
192
- /**
193
- * A test context that represents a client. Can be used to access emulators for rules unit testing.
194
- * @public
195
- */
196
- export interface RulesTestContext {
197
- /**
198
- * Get a {@link @firebase/firestore#Firestore} instance for this test context. The returned Firebase JS Client SDK instance
199
- * can be used with the client SDK APIs (v9 modular or v9 compat).
200
- *
201
- * See: {@link @firebase/firestore#Firestore}
202
- * @param settings - a settings object to configure the {@link @firebase/firestore#Firestore} instance
203
- * @returns a `Firestore` instance configured to connect to the emulator
204
- * @public
205
- */
206
- firestore(settings?: firebase.firestore.Settings): firebase.firestore.Firestore;
207
- /**
208
- * Get a {@link @firebase/database#Database} instance for this test context. The returned Firebase JS Client SDK instance
209
- * can be used with the client SDK APIs (v9 modular or v9 compat).
210
- *
211
- * See: {@link @firebase/database#Database}
212
- * @param databaseURL - the URL of the Realtime Database instance. If specified, returns an instance
213
- * for an emulated version of the namespace with parameters extracted from URL
214
- * @returns a `Database` instance configured to connect to the emulator. It never connects to
215
- * production even if a production `databaseURL` is specified
216
- */
217
- database(databaseURL?: string): firebase.database.Database;
218
- /**
219
- * Get a {@link @firebase/storage#FirebaseStorage} instance for this test context. The returned Firebase JS Client SDK instance
220
- * can be used with the client SDK APIs (v9 modular or v9 compat).
221
- *
222
- * See: {@link @firebase/storage#FirebaseStorage}
223
- * @param settings - the gs:// url to the Firebase Storage Bucket for testing. If specified,
224
- * returns a `Storage` instance for an emulated version of the bucket name
225
- * @returns a `Storage` instance configured to connect to the emulator
226
- */
227
- storage(bucketUrl?: string): firebase.storage.Storage;
228
- }
1
+ /**
2
+ * @license
3
+ * Copyright 2021 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
+ import { FirebaseSignInProvider } from '@firebase/util';
18
+ import firebase from 'firebase/compat/app';
19
+ import 'firebase/compat/database';
20
+ import 'firebase/compat/firestore';
21
+ import 'firebase/compat/storage';
22
+ /**
23
+ * More options for the mock user token to be used for testing, including developer-specified custom
24
+ * claims or optional overrides for Firebase Auth token payloads.
25
+ * @public
26
+ */
27
+ export type TokenOptions = {
28
+ /** The token issue time, in seconds since epoch */
29
+ iat?: number;
30
+ /** The token expiry time, normally 'iat' + 3600 */
31
+ exp?: number;
32
+ /** The time the user authenticated, normally 'iat' */
33
+ auth_time?: number;
34
+ /** The sign in provider, only set when the provider is 'anonymous' */
35
+ provider_id?: 'anonymous';
36
+ /** The user's primary email */
37
+ email?: string;
38
+ /** The user's email verification status */
39
+ email_verified?: boolean;
40
+ /** The user's primary phone number */
41
+ phone_number?: string;
42
+ /** The user's display name */
43
+ name?: string;
44
+ /** The user's profile photo URL */
45
+ picture?: string;
46
+ /** Information on all identities linked to this user */
47
+ firebase?: {
48
+ /** The primary sign-in provider */
49
+ sign_in_provider: FirebaseSignInProvider;
50
+ /** A map of providers to the user's list of unique identifiers from each provider */
51
+ identities?: {
52
+ [provider in FirebaseSignInProvider]?: string[];
53
+ };
54
+ };
55
+ /** Set to PROJECT_ID by default. In rare cases, you may want to specify an override. */
56
+ aud?: string;
57
+ /** Set to https://securetoken.google.com/PROJECT_ID by default. In rare cases, you may want to specify an override. */
58
+ iss?: string;
59
+ /** Custom claims set by the developer */
60
+ [claim: string]: unknown;
61
+ /** DO NOT USE. The user ID MUST be specified as the first param in authenticatedContext(uid, options) instead. */
62
+ uid?: never;
63
+ /** DO NOT USE. The user ID MUST be specified as the first param in authenticatedContext(uid, options) instead. */
64
+ sub?: never;
65
+ /** DO NOT USE. The user ID MUST be specified as the first param in authenticatedContext(uid, options) instead. */
66
+ user_id?: never;
67
+ };
68
+ /**
69
+ * Configuration of the unit testing environment, including emulators.
70
+ * @public
71
+ */
72
+ export interface TestEnvironmentConfig {
73
+ /**
74
+ * The project ID of the test environment. Can also be specified via the environment variable GCLOUD_PROJECT.
75
+ *
76
+ * A "demo-*" project ID is strongly recommended, especially for unit testing.
77
+ * See: https://firebase.google.com/docs/emulator-suite/connect_firestore#choose_a_firebase_project
78
+ */
79
+ projectId?: string;
80
+ /**
81
+ * The Firebase Emulator hub. Can also be specified via the environment variable FIREBASE_EMULATOR_HUB.
82
+ * If specified either way, other running emulators can be automatically discovered, and thus do
83
+ * not to be explicity specified.
84
+ */
85
+ hub?: HostAndPort;
86
+ /**
87
+ * The Database emulator. Its host and port can also be discovered automatically through the hub
88
+ * (see field "hub") or specified via the environment variable FIREBASE_DATABASE_EMULATOR_HOST.
89
+ */
90
+ database?: EmulatorConfig;
91
+ /**
92
+ * The Firestore emulator. Its host and port can also be discovered automatically through the hub
93
+ * (see field "hub") or specified via the environment variable FIRESTORE_EMULATOR_HOST.
94
+ */
95
+ firestore?: EmulatorConfig;
96
+ /**
97
+ * The Storage emulator. Its host and port can also be discovered automatically through the hub
98
+ * (see field "hub") or specified via the environment variable FIREBASE_STORAGE_EMULATOR_HOST.
99
+ */
100
+ storage?: EmulatorConfig;
101
+ }
102
+ /**
103
+ * An object containing the hostname and port number of an emulator.
104
+ * @public
105
+ */
106
+ export interface HostAndPort {
107
+ /**
108
+ * The host of the emulator. Can be omitted if discovered automatically through the hub or
109
+ * specified via environment variables. See `TestEnvironmentConfig` for details.
110
+ */
111
+ host: string;
112
+ /**
113
+ * The port of the emulator. Can be omitted if discovered automatically through the hub or
114
+ * specified via environment variables. See `TestEnvironmentConfig` for details.
115
+ */
116
+ port: number;
117
+ }
118
+ /**
119
+ * Configuration for a given emulator.
120
+ * @public
121
+ */
122
+ export type EmulatorConfig = {
123
+ /** The security rules source code under test for this emulator. Strongly recommended. */
124
+ rules?: string;
125
+ } & (HostAndPort | {});
126
+ /**
127
+ * An object used to control the rules unit test environment. Can be used to create RulesTestContext
128
+ * for different authentication situations.
129
+ * @public
130
+ */
131
+ export interface RulesTestEnvironment {
132
+ /** The project ID specified or discovered at test environment creation. */
133
+ readonly projectId: string;
134
+ /**
135
+ * A readonly copy of the emulator config specified or discovered at test environment creation.
136
+ */
137
+ readonly emulators: {
138
+ database?: HostAndPort;
139
+ firestore?: HostAndPort;
140
+ storage?: HostAndPort;
141
+ };
142
+ /**
143
+ * Create a `RulesTestContext` which behaves like an authenticated Firebase Auth user.
144
+ *
145
+ * Requests created via the returned context will have a mock Firebase Auth token attached.
146
+ *
147
+ * @param user_id - the User ID of the user. Specifies the value of "user_id" and "sub" on the token
148
+ * @param tokenOptions - custom claims or overrides for Firebase Auth token payloads
149
+ *
150
+ * @example
151
+ * ```javascript
152
+ * const alice = testEnv.authenticatedContext('alice');
153
+ * await assertSucceeds(get(doc(alice.firestore(), '/doc/readable/by/alice'), { ... });
154
+ * ```
155
+ */
156
+ authenticatedContext(user_id: string, tokenOptions?: TokenOptions): RulesTestContext;
157
+ /**
158
+ * Create a `RulesTestContext` which behaves like client that is NOT logged in via Firebase
159
+ * Auth.
160
+ *
161
+ * Requests created via the returned context will not have Firebase Auth tokens attached.
162
+ *
163
+ * @example
164
+ * ```javascript
165
+ * const unauthed = testEnv.unauthenticatedContext();
166
+ * await assertFails(get(doc(unauthed.firestore(), '/private/doc'), { ... });
167
+ * ```
168
+ */
169
+ unauthenticatedContext(): RulesTestContext;
170
+ withSecurityRulesDisabled(callback: (context: RulesTestContext) => Promise<void>): Promise<void>;
171
+ /**
172
+ * Clear all data in the Realtime Database emulator namespace.
173
+ */
174
+ clearDatabase(): Promise<void>;
175
+ /**
176
+ * Clear data in the Firestore that belongs to the `projectId` in the Firestore emulator.
177
+ */
178
+ clearFirestore(): Promise<void>;
179
+ /**
180
+ * Clear Storage files and metadata in all buckets in the Storage emulator.
181
+ */
182
+ clearStorage(): Promise<void>;
183
+ /**
184
+ * At the very end of your test code, call the cleanup function. Destroy all RulesTestContexts
185
+ * created in test environment and clean up the underlying resources, allowing a clean exit.
186
+ *
187
+ * This method does not change the state in emulators in any way. To reset data between tests,
188
+ * see `clearDatabase()`, `clearFirestore()` and `clearStorage()`.
189
+ */
190
+ cleanup(): Promise<void>;
191
+ }
192
+ /**
193
+ * A test context that represents a client. Can be used to access emulators for rules unit testing.
194
+ * @public
195
+ */
196
+ export interface RulesTestContext {
197
+ /**
198
+ * Get a {@link @firebase/firestore#Firestore} instance for this test context. The returned Firebase JS Client SDK instance
199
+ * can be used with the client SDK APIs (v9 modular or v9 compat).
200
+ *
201
+ * See: {@link @firebase/firestore#Firestore}
202
+ * @param settings - a settings object to configure the {@link @firebase/firestore#Firestore} instance
203
+ * @returns a `Firestore` instance configured to connect to the emulator
204
+ * @public
205
+ */
206
+ firestore(settings?: firebase.firestore.Settings): firebase.firestore.Firestore;
207
+ /**
208
+ * Get a {@link @firebase/database#Database} instance for this test context. The returned Firebase JS Client SDK instance
209
+ * can be used with the client SDK APIs (v9 modular or v9 compat).
210
+ *
211
+ * See: {@link @firebase/database#Database}
212
+ * @param databaseURL - the URL of the Realtime Database instance. If specified, returns an instance
213
+ * for an emulated version of the namespace with parameters extracted from URL
214
+ * @returns a `Database` instance configured to connect to the emulator. It never connects to
215
+ * production even if a production `databaseURL` is specified
216
+ */
217
+ database(databaseURL?: string): firebase.database.Database;
218
+ /**
219
+ * Get a {@link @firebase/storage#FirebaseStorage} instance for this test context. The returned Firebase JS Client SDK instance
220
+ * can be used with the client SDK APIs (v9 modular or v9 compat).
221
+ *
222
+ * See: {@link @firebase/storage#FirebaseStorage}
223
+ * @param settings - the gs:// url to the Firebase Storage Bucket for testing. If specified,
224
+ * returns a `Storage` instance for an emulated version of the bucket name
225
+ * @returns a `Storage` instance configured to connect to the emulator
226
+ */
227
+ storage(bucketUrl?: string): firebase.storage.Storage;
228
+ }
@@ -1,75 +1,75 @@
1
- /**
2
- * @license
3
- * Copyright 2021 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
- * Run a setup function with background Cloud Functions triggers disabled. This can be used to
19
- * import data into the Realtime Database or Cloud Firestore emulator without triggering locally
20
- * emulated Cloud Functions.
21
- *
22
- * This method only works with Firebase CLI version 8.13.0 or higher. This overload works only if
23
- * the Emulator hub host:port is specified by the environment variable FIREBASE_EMULATOR_HUB.
24
- *
25
- * @param fn - a function which may be sync or async (returns a promise)
26
- * @public
27
- */
28
- export declare function withFunctionTriggersDisabled<TResult>(fn: () => TResult | Promise<TResult>): Promise<TResult>;
29
- /**
30
- * Run a setup function with background Cloud Functions triggers disabled. This can be used to
31
- * import data into the Realtime Database or Cloud Firestore emulator without triggering locally
32
- * emulated Cloud Functions.
33
- *
34
- * This method only works with Firebase CLI version 8.13.0 or higher. The Emulator hub must be
35
- * running, which host and port are specified in this overload.
36
- *
37
- * @param fn - a function which may be sync or async (returns a promise)
38
- * @param hub - the host and port of the Emulator Hub (ex: `{host: 'localhost', port: 4400}`)
39
- * @public
40
- */
41
- export declare function withFunctionTriggersDisabled<TResult>(hub: {
42
- host: string;
43
- port: number;
44
- }, fn: () => TResult | Promise<TResult>): Promise<TResult>;
45
- /**
46
- * Assert the promise to be rejected with a "permission denied" error.
47
- *
48
- * Useful to assert a certain request to be denied by Security Rules. See example below.
49
- * This function recognizes permission-denied errors from Database, Firestore, and Storage JS SDKs.
50
- *
51
- * @param pr - the promise to be asserted
52
- * @returns a Promise that is fulfilled if pr is rejected with "permission denied". If pr is
53
- * rejected with any other error or resolved, the returned promise rejects.
54
- * @public
55
- * @example
56
- * ```javascript
57
- * const unauthed = testEnv.unauthenticatedContext();
58
- * await assertFails(get(doc(unauthed.firestore(), '/private/doc'), { ... });
59
- * ```
60
- */
61
- export declare function assertFails(pr: Promise<any>): Promise<any>;
62
- /**
63
- * Assert the promise to be successful.
64
- *
65
- * This is a no-op function returning the passed promise as-is, but can be used for documentational
66
- * purposes in test code to emphasize that a certain request should succeed (e.g. allowed by rules).
67
- *
68
- * @public
69
- * @example
70
- * ```javascript
71
- * const alice = testEnv.authenticatedContext('alice');
72
- * await assertSucceeds(get(doc(alice.firestore(), '/doc/readable/by/alice'), { ... });
73
- * ```
74
- */
75
- export declare function assertSucceeds<T>(pr: Promise<T>): Promise<T>;
1
+ /**
2
+ * @license
3
+ * Copyright 2021 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
+ * Run a setup function with background Cloud Functions triggers disabled. This can be used to
19
+ * import data into the Realtime Database or Cloud Firestore emulator without triggering locally
20
+ * emulated Cloud Functions.
21
+ *
22
+ * This method only works with Firebase CLI version 8.13.0 or higher. This overload works only if
23
+ * the Emulator hub host:port is specified by the environment variable FIREBASE_EMULATOR_HUB.
24
+ *
25
+ * @param fn - a function which may be sync or async (returns a promise)
26
+ * @public
27
+ */
28
+ export declare function withFunctionTriggersDisabled<TResult>(fn: () => TResult | Promise<TResult>): Promise<TResult>;
29
+ /**
30
+ * Run a setup function with background Cloud Functions triggers disabled. This can be used to
31
+ * import data into the Realtime Database or Cloud Firestore emulator without triggering locally
32
+ * emulated Cloud Functions.
33
+ *
34
+ * This method only works with Firebase CLI version 8.13.0 or higher. The Emulator hub must be
35
+ * running, which host and port are specified in this overload.
36
+ *
37
+ * @param fn - a function which may be sync or async (returns a promise)
38
+ * @param hub - the host and port of the Emulator Hub (ex: `{host: 'localhost', port: 4400}`)
39
+ * @public
40
+ */
41
+ export declare function withFunctionTriggersDisabled<TResult>(hub: {
42
+ host: string;
43
+ port: number;
44
+ }, fn: () => TResult | Promise<TResult>): Promise<TResult>;
45
+ /**
46
+ * Assert the promise to be rejected with a "permission denied" error.
47
+ *
48
+ * Useful to assert a certain request to be denied by Security Rules. See example below.
49
+ * This function recognizes permission-denied errors from Database, Firestore, and Storage JS SDKs.
50
+ *
51
+ * @param pr - the promise to be asserted
52
+ * @returns a Promise that is fulfilled if pr is rejected with "permission denied". If pr is
53
+ * rejected with any other error or resolved, the returned promise rejects.
54
+ * @public
55
+ * @example
56
+ * ```javascript
57
+ * const unauthed = testEnv.unauthenticatedContext();
58
+ * await assertFails(get(doc(unauthed.firestore(), '/private/doc'), { ... });
59
+ * ```
60
+ */
61
+ export declare function assertFails(pr: Promise<any>): Promise<any>;
62
+ /**
63
+ * Assert the promise to be successful.
64
+ *
65
+ * This is a no-op function returning the passed promise as-is, but can be used for documentational
66
+ * purposes in test code to emphasize that a certain request should succeed (e.g. allowed by rules).
67
+ *
68
+ * @public
69
+ * @example
70
+ * ```javascript
71
+ * const alice = testEnv.authenticatedContext('alice');
72
+ * await assertSucceeds(get(doc(alice.firestore(), '/doc/readable/by/alice'), { ... });
73
+ * ```
74
+ */
75
+ export declare function assertSucceeds<T>(pr: Promise<T>): Promise<T>;
@@ -1,17 +1,17 @@
1
- /**
2
- * @license
3
- * Copyright 2019 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
- export {};
1
+ /**
2
+ * @license
3
+ * Copyright 2019 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
+ export {};