Skip to content

Commit 47d6057

Browse files
committed
Address feedback.
1 parent 9b22357 commit 47d6057

File tree

1 file changed

+52
-64
lines changed

1 file changed

+52
-64
lines changed

packages/firestore/test/unit/local/indexeddb_persistence.test.ts

Lines changed: 52 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,23 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
268268

269269
after(() => SimpleDb.delete(INDEXEDDB_TEST_DATABASE_NAME));
270270

271+
function verifyUserHasDocumentOverlay(
272+
txn: SimpleDbTransaction,
273+
user: string,
274+
doc: string,
275+
expected: firestoreV1ApiClientInterfaces.Write
276+
): PersistencePromise<void> {
277+
const key = toDbDocumentOverlayKey(user, DocumentKey.fromPath(doc));
278+
const documentOverlayStore = txn.store<
279+
DbDocumentOverlayKey,
280+
DbDocumentOverlay
281+
>(DbDocumentOverlayStore);
282+
return documentOverlayStore.get(key).next(overlay => {
283+
expect(overlay).to.not.be.null;
284+
expect(overlay!.overlayMutation).to.deep.equal(expected);
285+
});
286+
}
287+
271288
it('can install schema version 1', () => {
272289
return withDb(1, async (db, version, objectStores) => {
273290
expect(version).to.equal(1);
@@ -1070,9 +1087,9 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
10701087
fields: {}
10711088
}
10721089
};
1073-
const testWritePending = {
1090+
const testWriteNewDoc = {
10741091
update: {
1075-
name: 'projects/test-project/databases/(default)/documents/docs/pending',
1092+
name: 'projects/test-project/databases/(default)/documents/docs/newDoc',
10761093
fields: {}
10771094
}
10781095
};
@@ -1103,14 +1120,7 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
11031120
batchId: 4,
11041121
localWriteTimeMs: 1337,
11051122
baseMutations: undefined,
1106-
mutations: [testWritePending]
1107-
},
1108-
{
1109-
userId: 'user1',
1110-
batchId: 5,
1111-
localWriteTimeMs: 1337,
1112-
baseMutations: undefined,
1113-
mutations: [testWritePending]
1123+
mutations: [testWriteNewDoc]
11141124
}
11151125
];
11161126

@@ -1181,75 +1191,53 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
11811191

11821192
return db.runTransaction(
11831193
this.test!.fullTitle(),
1184-
'readwrite',
1194+
'readonly',
11851195
V14_STORES,
11861196
txn => {
11871197
const documentOverlayStore = txn.store<
11881198
DbDocumentOverlayKey,
11891199
DbDocumentOverlay
11901200
>(DbDocumentOverlayStore);
11911201

1192-
// We should have a total of 5 overlays:
1193-
// For user1: testWriteFoo, and testWritePending
1202+
// We should have a total of 4 overlays:
1203+
// For user1: testWriteFoo
11941204
// For user2: testWriteBar, testWriteBaz, and testWritePending
11951205
// For user3: NO OVERLAYS!
11961206
let p = documentOverlayStore.count().next(count => {
1197-
expect(count).to.equal(5);
1198-
});
1199-
p = p.next(() => {
1200-
const key = toDbDocumentOverlayKey(
1201-
'user1',
1202-
DocumentKey.fromPath('docs/foo')
1203-
);
1204-
return documentOverlayStore.get(key).next(overlay => {
1205-
expect(overlay).to.not.be.null;
1206-
expect(overlay!.overlayMutation).to.deep.equal(testWriteFoo);
1207-
});
1207+
expect(count).to.equal(4);
12081208
});
1209-
p = p.next(() => {
1210-
const key = toDbDocumentOverlayKey(
1209+
p = p.next(() =>
1210+
verifyUserHasDocumentOverlay(
1211+
txn,
12111212
'user1',
1212-
DocumentKey.fromPath('docs/pending')
1213-
);
1214-
return documentOverlayStore.get(key).next(overlay => {
1215-
expect(overlay).to.not.be.null;
1216-
expect(overlay!.overlayMutation).to.deep.equal(
1217-
testWritePending
1218-
);
1219-
});
1220-
});
1221-
p = p.next(() => {
1222-
const key = toDbDocumentOverlayKey(
1213+
'docs/foo',
1214+
testWriteFoo
1215+
)
1216+
);
1217+
p = p.next(() =>
1218+
verifyUserHasDocumentOverlay(
1219+
txn,
12231220
'user2',
1224-
DocumentKey.fromPath('docs/bar')
1225-
);
1226-
return documentOverlayStore.get(key).next(overlay => {
1227-
expect(overlay).to.not.be.null;
1228-
expect(overlay!.overlayMutation).to.deep.equal(testWriteBar);
1229-
});
1230-
});
1231-
p = p.next(() => {
1232-
const key = toDbDocumentOverlayKey(
1221+
'docs/bar',
1222+
testWriteBar
1223+
)
1224+
);
1225+
p = p.next(() =>
1226+
verifyUserHasDocumentOverlay(
1227+
txn,
12331228
'user2',
1234-
DocumentKey.fromPath('docs/baz')
1235-
);
1236-
return documentOverlayStore.get(key).next(overlay => {
1237-
expect(overlay).to.not.be.null;
1238-
expect(overlay!.overlayMutation).to.deep.equal(testWriteBaz);
1239-
});
1240-
});
1241-
p = p.next(() => {
1242-
const key = toDbDocumentOverlayKey(
1229+
'docs/baz',
1230+
testWriteBaz
1231+
)
1232+
);
1233+
p = p.next(() =>
1234+
verifyUserHasDocumentOverlay(
1235+
txn,
12431236
'user2',
1244-
DocumentKey.fromPath('docs/pending')
1245-
);
1246-
return documentOverlayStore.get(key).next(overlay => {
1247-
expect(overlay).to.not.be.null;
1248-
expect(overlay!.overlayMutation).to.deep.equal(
1249-
testWritePending
1250-
);
1251-
});
1252-
});
1237+
'docs/newDoc',
1238+
testWriteNewDoc
1239+
)
1240+
);
12531241
return p;
12541242
}
12551243
);

0 commit comments

Comments
 (0)