Add test for 4.0 → 5.0 DB upgrade

With a mechanism for specifying a zipped DB copy to use as the initial
DB when resetting the DB in tests
This commit is contained in:
Dan Stillman 2021-08-16 19:50:44 -04:00
parent 0f96c20f3c
commit eac98d1c2e
3 changed files with 33 additions and 2 deletions

View file

@ -624,8 +624,19 @@ async function resetDB(options = {}) {
var db = Zotero.DataDirectory.getDatabase(); var db = Zotero.DataDirectory.getDatabase();
await Zotero.reinit( await Zotero.reinit(
async function () { async function () {
// Swap in the initial copy we made of the DB // Extract a zipped DB file into place as the initial DB
await OS.File.copy(db + '-test-template', db); if (options.dbFile && options.dbFile.endsWith('.zip')) {
let zipReader = Components.classes['@mozilla.org/libjar/zip-reader;1']
.createInstance(Components.interfaces.nsIZipReader);
zipReader.open(Zotero.File.pathToFile(options.dbFile));
zipReader.extract('zotero.sqlite', Zotero.File.pathToFile(db));
zipReader.close();
}
// Otherwise swap in the initial copy we made of the DB, or an alternative non-zip file
// if given
else {
await OS.File.copy(options.dbFile || db + '-test-template', db);
}
_defaultGroup = null; _defaultGroup = null;
}, },
false, false,

Binary file not shown.

View file

@ -303,4 +303,24 @@ describe("Zotero.Schema", function() {
await assert.isTrue(await Zotero.Schema.integrityCheck()); await assert.isTrue(await Zotero.Schema.integrityCheck());
}); });
}) })
describe("Database Upgrades", function () {
after(async function () {
await resetDB({
thisArg: this,
skipBundledFiles: true,
});
});
it("should upgrade 4.0 database", async function () {
await resetDB({
thisArg: this,
skipBundledFiles: true,
dbFile: OS.Path.join(getTestDataDirectory().path, 'zotero-4.0.sqlite.zip')
});
// Make sure we can open the Zotero pane without errors
win = await loadZoteroPane();
win.close();
});
});
}) })