diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-02-19 20:00:44 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-02-19 20:00:44 -0500 |
commit | 1e573f36c416b3955b2e679c8f3ce7ffa91bf504 (patch) | |
tree | 87604c886aa8bfcdd1787809d6a20e3f2057597f | |
parent | 4f39ac207917c6f4cd1f840ccf338137785e99cc (diff) |
Test some errors
-rw-r--r-- | test/test-database.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/test-database.js b/test/test-database.js index cefa297c..fcf519d7 100644 --- a/test/test-database.js +++ b/test/test-database.js @@ -39,6 +39,18 @@ function countKanjiWithCharacter(kanji, character) { } +async function clearDatabase() { + const indexedDB = global.indexedDB; + for (const {name} of await indexedDB.databases()) { + await new Promise((resolve, reject) => { + const request = indexedDB.deleteDatabase(name); + request.onerror = (e) => reject(e); + request.onsuccess = () => resolve(); + }); + } +} + + async function testDatabase1() { // Load dictionary data const testDictionary = yomichanTest.createTestDictionaryArchive(); @@ -718,8 +730,53 @@ async function testFindTagForTitle1(database, title) { } +async function testDatabase2() { + // Load dictionary data + const testDictionary = yomichanTest.createTestDictionaryArchive(); + const testDictionarySource = await testDictionary.generateAsync({type: 'string'}); + const testDictionaryIndex = JSON.parse(await testDictionary.files['index.json'].async('string')); + + const title = testDictionaryIndex.title; + const titles = [title]; + + // Setup database + const database = new Database(); + + // Error: not prepared + await assert.rejects(async () => await database.purge()); + await assert.rejects(async () => await database.deleteDictionary(title, () => {}, {})); + await assert.rejects(async () => await database.findTermsBulk(['?'], titles, null)); + await assert.rejects(async () => await database.findTermsExactBulk(['?'], ['?'], titles)); + await assert.rejects(async () => await database.findTermsBySequenceBulk([1], title)); + await assert.rejects(async () => await database.findTermMetaBulk(['?'], titles)); + await assert.rejects(async () => await database.findTermMetaBulk(['?'], titles)); + await assert.rejects(async () => await database.findKanjiBulk(['?'], titles)); + await assert.rejects(async () => await database.findKanjiMetaBulk(['?'], titles)); + await assert.rejects(async () => await database.findTagForTitle('tag', title)); + await assert.rejects(async () => await database.getDictionaryInfo()); + await assert.rejects(async () => await database.getDictionaryCounts(titles, true)); + await assert.rejects(async () => await database.importDictionary(testDictionarySource, () => {}, {})); + + await database.prepare(); + + // Error: already prepared + await assert.rejects(async () => await database.prepare()); + + await database.importDictionary(testDictionarySource, () => {}, {}); + + // Error: dictionary already imported + await assert.rejects(async () => await database.importDictionary(testDictionarySource, () => {}, {})); + + await database.close(); +} + + async function main() { await testDatabase1(); + await clearDatabase(); + + await testDatabase2(); + await clearDatabase(); } |