Skip to content

Commit fbe94aa

Browse files
committed
Included index in our tests
1 parent 52669cd commit fbe94aa

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
lines changed

config/database.rules.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
".read": true,
44
".write": true,
55
"testing": {
6-
".indexOn": "lease"
6+
".indexOn": "testIndex"
77
}
88
}
99
}

packages/database-compat/test/query.test.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4676,26 +4676,22 @@ describe('Query Tests', () => {
46764676
// TODO(mtewani): This repro requires an index to be created.
46774677
await root.remove();
46784678

4679-
const query = root.orderByChild('lease').limitToFirst(2);
4679+
const query = root.orderByChild('testIndex').limitToFirst(2);
46804680

46814681
await root
46824682
.child('i|1')
4683-
.set({ lease: 3, timestamp: Date.now(), action: 'test' });
4683+
.set({ testIndex: 3, timestamp: Date.now(), action: 'test' });
46844684
await root
46854685
.child('i|2')
4686-
.set({ lease: 1, timestamp: Date.now(), action: 'test' });
4686+
.set({ testIndex: 1, timestamp: Date.now(), action: 'test' });
46874687
await root
46884688
.child('i|3')
4689-
.set({ lease: 2, timestamp: Date.now(), action: 'test' });
4689+
.set({ testIndex: 2, timestamp: Date.now(), action: 'test' });
46904690
const childAdded = query.on('child_added', snap => {
46914691
const value = snap.val();
4692-
console.log('onChildAdded', value);
4693-
if(value.timestamp && !value.lease) {
4694-
console.log("ERR: missing value");
4695-
}
46964692
expect(value).to.haveOwnProperty('timestamp');
46974693
expect(value).to.haveOwnProperty('action');
4698-
expect(value).to.haveOwnProperty('lease');
4694+
expect(value).to.haveOwnProperty('testIndex');
46994695
});
47004696
const onValue = root.child('i|1').on('value', snap => {
47014697
console.log('onValue', snap.val());

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

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ import { expect, use } from 'chai';
2121
import chaiAsPromised from 'chai-as-promised';
2222

2323
import {
24+
child,
2425
get,
2526
limitToFirst,
27+
onChildAdded,
2628
onValue,
29+
orderByChild,
2730
query,
2831
refFromURL,
32+
remove,
2933
set,
30-
startAt
34+
startAt,
35+
update
3136
} from '../../src/api/Reference_impl';
3237
import {
3338
getDatabase,
@@ -112,6 +117,51 @@ describe('Database@exp Tests', () => {
112117
unsubscribe();
113118
});
114119

120+
it('can properly handle unknown deep merges', async () => {
121+
const database = getDatabase(defaultApp);
122+
const root = ref(database, 'testing');
123+
await remove(root);
124+
125+
const q = query(root, orderByChild('testIndex'), limitToFirst(2));
126+
127+
const i1 = child(root, 'i1');
128+
await set(root, {
129+
i1: {
130+
testIndex: 3,
131+
timestamp: Date.now(),
132+
action: 'test'
133+
},
134+
i2: {
135+
testIndex: 1,
136+
timestamp: Date.now(),
137+
action: 'test'
138+
},
139+
i3: {
140+
testIndex: 2,
141+
timestamp: Date.now(),
142+
action: 'test'
143+
}
144+
});
145+
const ec = EventAccumulatorFactory.waitsForExactCount(1);
146+
const onChildAddedCb = onChildAdded(q, snap => {
147+
const value = snap.val();
148+
ec.addEvent(snap);
149+
});
150+
const onValueCb = onValue(i1, () => {
151+
//no-op
152+
});
153+
await update(i1, {
154+
timestamp: `${Date.now()}|1`
155+
});
156+
const [result] = await ec.promise;
157+
const value = result.val();
158+
expect(value).to.haveOwnProperty('timestamp');
159+
expect(value).to.haveOwnProperty('action');
160+
expect(value).to.haveOwnProperty('testIndex');
161+
onChildAddedCb();
162+
onValueCb();
163+
});
164+
115165
// Tests to make sure onValue's data does not get mutated after calling get
116166
it('calls onValue only once after get request with a non-default query', async () => {
117167
const db = getDatabase(defaultApp);

packages/rules-unit-testing/src/initialize.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export async function initializeTestEnvironment(
8282
}
8383

8484
if (config.database?.rules) {
85+
console.log('RUNNING RULES');
8586
assertEmulatorRunning(emulators, 'database');
8687
await loadDatabaseRules(
8788
emulators.database,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class DatabaseEmulator extends Emulator {
4141
{
4242
uri: `http://localhost:${this.port}/.settings/rules.json?ns=${this.namespace}`,
4343
headers: { Authorization: 'Bearer owner' },
44-
body: '{ "rules": { ".read": true, ".write": true } }'
44+
body: '{ "rules": { ".read": true, ".write": true, "testing": { ".indexOn": "testIndex" } } }'
4545
},
4646
(error, response, body) => {
4747
if (error) reject(error);

0 commit comments

Comments
 (0)