Skip to content

Commit

Permalink
Update rules-unit-testing files
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubox76 committed Jan 25, 2022
1 parent 887e683 commit cc0a45c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions packages/rules-unit-testing/src/impl/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function discoverEmulators(
hub: HostAndPort,
fetch: typeof nodeFetch = nodeFetch
): Promise<DiscoveredEmulators> {
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?`
Expand All @@ -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 = {
Expand Down
32 changes: 19 additions & 13 deletions packages/rules-unit-testing/src/impl/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function loadDatabaseRules(
): Promise<void> {
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
Expand All @@ -49,7 +49,10 @@ export async function loadFirestoreRules(
rules: string
): Promise<void> {
const resp = await fetch(
makeUrl(hostAndPort, `/emulator/v1/projects/${projectId}:securityRules`),
makeUrl(
hostAndPort,
`/emulator/v1/projects/${projectId}:securityRules`
).toString(),
{
method: 'PUT',
body: JSON.stringify({
Expand All @@ -72,17 +75,20 @@ export async function loadStorageRules(
hostAndPort: HostAndPort,
rules: string
): Promise<void> {
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());
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rules-unit-testing/src/impl/test_environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class RulesTestEnvironmentImpl implements RulesTestEnvironment {
makeUrl(
this.emulators.firestore,
`/emulator/v1/projects/${this.projectId}/databases/(default)/documents`
),
).toString(),
{
method: 'DELETE'
}
Expand Down
4 changes: 2 additions & 2 deletions packages/rules-unit-testing/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function withFunctionTriggersDisabled<TResult>(
makeUrl(hub, '/functions/disableBackgroundTriggers');
// Disable background triggers
const disableRes = await fetch(
makeUrl(hub, '/functions/disableBackgroundTriggers'),
makeUrl(hub, '/functions/disableBackgroundTriggers').toString(),
{
method: 'PUT'
}
Expand All @@ -98,7 +98,7 @@ export async function withFunctionTriggersDisabled<TResult>(
} finally {
// Re-enable background triggers
const enableRes = await fetch(
makeUrl(hub, '/functions/enableBackgroundTriggers'),
makeUrl(hub, '/functions/enableBackgroundTriggers').toString(),
{
method: 'PUT'
}
Expand Down
2 changes: 1 addition & 1 deletion repo-scripts/changelog-generator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit cc0a45c

Please sign in to comment.