From cc0a45ce39a5086ba47b38dc2a7cba4b7e6a70da Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Tue, 25 Jan 2022 12:55:58 -0800 Subject: [PATCH] Update rules-unit-testing files --- .../rules-unit-testing/src/impl/discovery.ts | 4 +-- packages/rules-unit-testing/src/impl/rules.ts | 32 +++++++++++-------- .../src/impl/test_environment.ts | 2 +- packages/rules-unit-testing/src/util.ts | 4 +-- repo-scripts/changelog-generator/index.ts | 2 +- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/packages/rules-unit-testing/src/impl/discovery.ts b/packages/rules-unit-testing/src/impl/discovery.ts index 9798f017241..254e96602b1 100644 --- a/packages/rules-unit-testing/src/impl/discovery.ts +++ b/packages/rules-unit-testing/src/impl/discovery.ts @@ -29,7 +29,7 @@ export async function discoverEmulators( hub: HostAndPort, fetch: typeof nodeFetch = nodeFetch ): Promise { - const res = await fetch(makeUrl(hub, '/emulators')); + const res = await fetch(makeUrl(hub, '/emulators').toString()); if (!res.ok) { throw new Error( `HTTP Error ${res.status} when attempting to reach Emulator Hub at ${res.url}, are you sure it is running?` @@ -38,7 +38,7 @@ export async function discoverEmulators( const emulators: DiscoveredEmulators = {}; - const data = await res.json(); + const data = (await res.json()) as any; if (data.database) { emulators.database = { diff --git a/packages/rules-unit-testing/src/impl/rules.ts b/packages/rules-unit-testing/src/impl/rules.ts index 7d4d900367f..ffae954735c 100644 --- a/packages/rules-unit-testing/src/impl/rules.ts +++ b/packages/rules-unit-testing/src/impl/rules.ts @@ -29,7 +29,7 @@ export async function loadDatabaseRules( ): Promise { const url = makeUrl(hostAndPort, '/.settings/rules.json'); url.searchParams.append('ns', databaseName); - const resp = await fetch(url, { + const resp = await fetch(url.toString(), { method: 'PUT', headers: { Authorization: 'Bearer owner' }, body: rules @@ -49,7 +49,10 @@ export async function loadFirestoreRules( rules: string ): Promise { const resp = await fetch( - makeUrl(hostAndPort, `/emulator/v1/projects/${projectId}:securityRules`), + makeUrl( + hostAndPort, + `/emulator/v1/projects/${projectId}:securityRules` + ).toString(), { method: 'PUT', body: JSON.stringify({ @@ -72,17 +75,20 @@ export async function loadStorageRules( hostAndPort: HostAndPort, rules: string ): Promise { - const resp = await fetch(makeUrl(hostAndPort, '/internal/setRules'), { - method: 'PUT', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - rules: { - files: [{ name: 'storage.rules', content: rules }] - } - }) - }); + const resp = await fetch( + makeUrl(hostAndPort, '/internal/setRules').toString(), + { + method: 'PUT', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + rules: { + files: [{ name: 'storage.rules', content: rules }] + } + }) + } + ); if (!resp.ok) { throw new Error(await resp.text()); } diff --git a/packages/rules-unit-testing/src/impl/test_environment.ts b/packages/rules-unit-testing/src/impl/test_environment.ts index 5b32e8776f4..6c69c9fb4bc 100644 --- a/packages/rules-unit-testing/src/impl/test_environment.ts +++ b/packages/rules-unit-testing/src/impl/test_environment.ts @@ -110,7 +110,7 @@ export class RulesTestEnvironmentImpl implements RulesTestEnvironment { makeUrl( this.emulators.firestore, `/emulator/v1/projects/${this.projectId}/databases/(default)/documents` - ), + ).toString(), { method: 'DELETE' } diff --git a/packages/rules-unit-testing/src/util.ts b/packages/rules-unit-testing/src/util.ts index e6f7cc87b9c..b1ee85c2b04 100644 --- a/packages/rules-unit-testing/src/util.ts +++ b/packages/rules-unit-testing/src/util.ts @@ -80,7 +80,7 @@ export async function withFunctionTriggersDisabled( makeUrl(hub, '/functions/disableBackgroundTriggers'); // Disable background triggers const disableRes = await fetch( - makeUrl(hub, '/functions/disableBackgroundTriggers'), + makeUrl(hub, '/functions/disableBackgroundTriggers').toString(), { method: 'PUT' } @@ -98,7 +98,7 @@ export async function withFunctionTriggersDisabled( } finally { // Re-enable background triggers const enableRes = await fetch( - makeUrl(hub, '/functions/enableBackgroundTriggers'), + makeUrl(hub, '/functions/enableBackgroundTriggers').toString(), { method: 'PUT' } diff --git a/repo-scripts/changelog-generator/index.ts b/repo-scripts/changelog-generator/index.ts index 48db9c9ae29..487f25a0d54 100644 --- a/repo-scripts/changelog-generator/index.ts +++ b/repo-scripts/changelog-generator/index.ts @@ -103,7 +103,7 @@ async function getFixedIssueLink( 'Authorization': `Bearer ${process.env.GITHUB_TOKEN}` } } - ).then(data => data.json()); + ).then(data => data.json() as Promise<{ body: string }>); const match = fixedIssueRegex.exec(body); if (!match) {