Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save schmidt-sebastian/5312687e6a72e7240b11d6dac9c83b77 to your computer and use it in GitHub Desktop.
Save schmidt-sebastian/5312687e6a72e7240b11d6dac9c83b77 to your computer and use it in GitHub Desktop.
===================================================================
--- test/unit/local/indexeddb_schema.test.ts (date 1521229629000)
+++ test/unit/local/indexeddb_schema.test.ts (date 1521229629000)
@@ -21,7 +21,9 @@
createOrUpgradeDb,
DbTarget,
DbTargetGlobal,
- DbTargetGlobalKey
+ DbTargetGlobalKey,
+ V1_STORES,
+ V2_STORES
} from '../../../src/local/indexeddb_schema';
import { SimpleDb, SimpleDbTransaction } from '../../../src/local/simple_db';
import { PersistencePromise } from '../../../src/local/persistence_promise';
@@ -88,11 +90,10 @@
beforeEach(() => SimpleDb.delete(INDEXEDDB_TEST_DATABASE));
it('can install schema version 1', () => {
- return withDb(1, db => {
+ return withDb(1, async db => {
expect(db.version).to.equal(1);
// Version 1 adds all of the stores so far.
- expect(getAllObjectStores(db)).to.have.members(ALL_STORES);
- return Promise.resolve();
+ expect(getAllObjectStores(db)).to.have.members(V1_STORES);
});
});
@@ -101,7 +102,7 @@
expect(db.version).to.equal(2);
// We should have all of the stores, we should have the target global row
// and we should not have any targets counted, because there are none.
- expect(getAllObjectStores(db)).to.have.members(ALL_STORES);
+ expect(getAllObjectStores(db)).to.have.members(V2_STORES);
// Check the target count. We haven't added any targets, so we expect 0.
return getTargetCount(db).then(targetCount => {
expect(targetCount).to.equal(0);
@@ -109,6 +110,13 @@
});
});
+ it('can install schema version 3', () => {
+ return withDb(3, async db => {
+ expect(db.version).to.be.equal(3);
+ expect(getAllObjectStores(db)).to.have.members(ALL_STORES);
+ });
+ });
+
it('can upgrade from schema version 1 to 2', () => {
const expectedTargetCount = 5;
return withDb(1, db => {
@@ -126,11 +134,20 @@
}).then(() =>
withDb(2, db => {
expect(db.version).to.equal(2);
- expect(getAllObjectStores(db)).to.have.members(ALL_STORES);
+ expect(getAllObjectStores(db)).to.have.members(V2_STORES);
return getTargetCount(db).then(targetCount => {
expect(targetCount).to.equal(expectedTargetCount);
});
})
);
});
+
+ it('can upgrade from schema version 2 to 3', () => {
+ return withDb(2, async () => {}).then(() =>
+ withDb(3, async db => {
+ expect(db.version).to.be.equal(3);
+ expect(getAllObjectStores(db)).to.have.members(ALL_STORES);
+ })
+ );
+ });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment