|
| 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 | +/** |
| 19 | + * Run a setup function with background Cloud Functions triggers disabled. This can be used to |
| 20 | + * import data into the Realtime Database or Cloud Firestore emulator without triggering locally |
| 21 | + * emulated Cloud Functions. |
| 22 | + * |
| 23 | + * This method only works with Firebase CLI version 8.13.0 or higher. |
| 24 | + * |
| 25 | + * @param fn an function which returns a promise. |
| 26 | + * @public |
| 27 | + */ |
| 28 | +export async function withFunctionTriggersDisabled<TResult>( |
| 29 | + fn: () => TResult | Promise<TResult> |
| 30 | +): Promise<TResult> { |
| 31 | + throw new Error('unimplemented'); |
| 32 | +} |
| 33 | + |
| 34 | +/** |
| 35 | + * Assert the promise to be rejected with a "permission denied" error. |
| 36 | + * |
| 37 | + * Useful to assert a certain request to be denied by Security Rules. See example below. |
| 38 | + * This function recognizes permission-denied errors from Database, Firestore, and Storage JS SDKs. |
| 39 | + * |
| 40 | + * @param pr the promise to be asserted |
| 41 | + * @returns a Promise that is fulfilled if pr is rejected with "permission denied". If pr is |
| 42 | + * rejected with any other error or resolved, the returned promise rejects. |
| 43 | + * @public |
| 44 | + * @example |
| 45 | + * ```javascript |
| 46 | + * const unauthed = testEnv.unauthenticatedContext(); |
| 47 | + * await assertFails(get(doc(unauthed.firestore(), '/private/doc'), { ... }); |
| 48 | + * ``` |
| 49 | + */ |
| 50 | +export function assertFails(pr: Promise<any>): Promise<any> { |
| 51 | + throw new Error('unimplemented'); |
| 52 | +} |
| 53 | + |
| 54 | +/** |
| 55 | + * Assert the promise to be rejected with a "permission denied" error. |
| 56 | + * |
| 57 | + * This is a no-op function returning the passed promise as-is, but can be used for documentational |
| 58 | + * purposes in test code to emphasize that a certain request should succeed (e.g. allowed by rules). |
| 59 | + * |
| 60 | + * @public |
| 61 | + * @example |
| 62 | + * ```javascript |
| 63 | + * const alice = testEnv.authenticatedContext('alice'); |
| 64 | + * await assertSucceeds(get(doc(alice.firestore(), '/doc/readable/by/alice'), { ... }); |
| 65 | + * ``` |
| 66 | + */ |
| 67 | +export function assertSucceeds<T>(pr: Promise<T>): Promise<T> { |
| 68 | + return pr; |
| 69 | +} |
0 commit comments