Skip to content

Commit f85a1be

Browse files
committed
Updated database emulator script and rules
1 parent 89dfd2a commit f85a1be

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

config/database.rules.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"rules": {
33
".read": true,
4-
".write": true
4+
".write": true,
5+
"testing": {
6+
".indexOn": "testIndex"
7+
}
58
}
69
}

packages/database/test/exp/integration.test.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ describe('Database@exp Tests', () => {
122122

123123
it('can properly handle unknown deep merges', async () => {
124124
// Note: This test requires `testIndex` to be added as an index.
125-
// Without an index, the test will erroneously pass.
126-
// But we are unable to add indexes on the fly to the actual db, so
127-
// running on the emulator is the best way to test this.
125+
// Please run `yarn test:setup` to ensure that this gets added.
128126
const database = getDatabase(defaultApp);
129127
const root = ref(database, 'testing');
130128
await set(root, {});

scripts/emulator-testing/emulators/database-emulator.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import * as request from 'request';
1919

2020
import { Emulator } from './emulator';
2121

22+
import * as rulesJSON from '../../../config/database.rules.json';
23+
2224
export class DatabaseEmulator extends Emulator {
2325
namespace: string;
2426

@@ -35,13 +37,14 @@ export class DatabaseEmulator extends Emulator {
3537
}
3638

3739
setPublicRules(): Promise<number> {
38-
console.log('Setting rule {".read": true, ".write": true} to emulator ...');
40+
const jsonRules = JSON.stringify(rulesJSON);
41+
console.log(`Setting rule ${jsonRules} to emulator ...`);
3942
return new Promise<number>((resolve, reject) => {
4043
request.put(
4144
{
4245
uri: `http://localhost:${this.port}/.settings/rules.json?ns=${this.namespace}`,
4346
headers: { Authorization: 'Bearer owner' },
44-
body: '{ "rules": { ".read": true, ".write": true, "testing": { ".indexOn": "testIndex" } } }' // TODO: If this gets more complex, we should move this to a file.
47+
body: jsonRules
4548
},
4649
(error, response, body) => {
4750
if (error) reject(error);

0 commit comments

Comments
 (0)