summaryrefslogtreecommitdiff
path: root/test/test-database.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/test-database.js')
-rw-r--r--test/test-database.js84
1 files changed, 42 insertions, 42 deletions
diff --git a/test/test-database.js b/test/test-database.js
index 5291c138..535f2e95 100644
--- a/test/test-database.js
+++ b/test/test-database.js
@@ -116,10 +116,10 @@ vm.execute([
'bg/js/request.js',
'bg/js/dictionary-importer.js',
'bg/js/generic-database.js',
- 'bg/js/database.js'
+ 'bg/js/dictionary-database.js'
]);
const DictionaryImporter = vm.get('DictionaryImporter');
-const Database = vm.get('Database');
+const DictionaryDatabase = vm.get('DictionaryDatabase');
function countTermsWithExpression(terms, expression) {
@@ -180,15 +180,15 @@ async function testDatabase1() {
{
cleanup: async () => {
// Test purge
- await database.purge();
- await testDatabaseEmpty1(database);
+ await dictionaryDatabase.purge();
+ await testDatabaseEmpty1(dictionaryDatabase);
}
},
{
cleanup: async () => {
// Test deleteDictionary
let progressEvent = false;
- await database.deleteDictionary(
+ await dictionaryDatabase.deleteDictionary(
title,
{rate: 1000},
() => {
@@ -197,7 +197,7 @@ async function testDatabase1() {
);
assert.ok(progressEvent);
- await testDatabaseEmpty1(database);
+ await testDatabaseEmpty1(dictionaryDatabase);
}
},
{
@@ -207,8 +207,8 @@ async function testDatabase1() {
// Setup database
const dictionaryImporter = new DictionaryImporter();
- const database = new Database();
- await database.prepare();
+ const dictionaryDatabase = new DictionaryDatabase();
+ await dictionaryDatabase.prepare();
for (const {cleanup} of iterations) {
const expectedSummary = {
@@ -222,7 +222,7 @@ async function testDatabase1() {
// Import data
let progressEvent = false;
const {result, errors} = await dictionaryImporter.import(
- database,
+ dictionaryDatabase,
testDictionarySource,
{prefixWildcardsSupported: true},
() => {
@@ -234,11 +234,11 @@ async function testDatabase1() {
assert.ok(progressEvent);
// Get info summary
- const info = await database.getDictionaryInfo();
+ const info = await dictionaryDatabase.getDictionaryInfo();
vm.assert.deepStrictEqual(info, [expectedSummary]);
// Get counts
- const counts = await database.getDictionaryCounts(
+ const counts = await dictionaryDatabase.getDictionaryCounts(
info.map((v) => v.title),
true
);
@@ -248,19 +248,19 @@ async function testDatabase1() {
});
// Test find* functions
- await testFindTermsBulkTest1(database, titles);
- await testTindTermsExactBulk1(database, titles);
- await testFindTermsBySequenceBulk1(database, title);
- await testFindTermMetaBulk1(database, titles);
- await testFindKanjiBulk1(database, titles);
- await testFindKanjiMetaBulk1(database, titles);
- await testFindTagForTitle1(database, title);
+ await testFindTermsBulkTest1(dictionaryDatabase, titles);
+ await testTindTermsExactBulk1(dictionaryDatabase, titles);
+ await testFindTermsBySequenceBulk1(dictionaryDatabase, title);
+ await testFindTermMetaBulk1(dictionaryDatabase, titles);
+ await testFindKanjiBulk1(dictionaryDatabase, titles);
+ await testFindKanjiMetaBulk1(dictionaryDatabase, titles);
+ await testFindTagForTitle1(dictionaryDatabase, title);
// Cleanup
await cleanup();
}
- await database.close();
+ await dictionaryDatabase.close();
}
async function testDatabaseEmpty1(database) {
@@ -861,33 +861,33 @@ async function testDatabase2() {
// Setup database
const dictionaryImporter = new DictionaryImporter();
- const database = new Database();
+ const dictionaryDatabase = new DictionaryDatabase();
// Error: not prepared
- await assert.rejects(async () => await database.deleteDictionary(title, {rate: 1000}, () => {}));
- 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 dictionaryImporter.import(database, testDictionarySource, {}, () => {}));
-
- await database.prepare();
+ await assert.rejects(async () => await dictionaryDatabase.deleteDictionary(title, {rate: 1000}, () => {}));
+ await assert.rejects(async () => await dictionaryDatabase.findTermsBulk(['?'], titles, null));
+ await assert.rejects(async () => await dictionaryDatabase.findTermsExactBulk(['?'], ['?'], titles));
+ await assert.rejects(async () => await dictionaryDatabase.findTermsBySequenceBulk([1], title));
+ await assert.rejects(async () => await dictionaryDatabase.findTermMetaBulk(['?'], titles));
+ await assert.rejects(async () => await dictionaryDatabase.findTermMetaBulk(['?'], titles));
+ await assert.rejects(async () => await dictionaryDatabase.findKanjiBulk(['?'], titles));
+ await assert.rejects(async () => await dictionaryDatabase.findKanjiMetaBulk(['?'], titles));
+ await assert.rejects(async () => await dictionaryDatabase.findTagForTitle('tag', title));
+ await assert.rejects(async () => await dictionaryDatabase.getDictionaryInfo());
+ await assert.rejects(async () => await dictionaryDatabase.getDictionaryCounts(titles, true));
+ await assert.rejects(async () => await dictionaryImporter.import(dictionaryDatabase, testDictionarySource, {}, () => {}));
+
+ await dictionaryDatabase.prepare();
// Error: already prepared
- await assert.rejects(async () => await database.prepare());
+ await assert.rejects(async () => await dictionaryDatabase.prepare());
- await dictionaryImporter.import(database, testDictionarySource, {}, () => {});
+ await dictionaryImporter.import(dictionaryDatabase, testDictionarySource, {}, () => {});
// Error: dictionary already imported
- await assert.rejects(async () => await dictionaryImporter.import(database, testDictionarySource, {}, () => {}));
+ await assert.rejects(async () => await dictionaryImporter.import(dictionaryDatabase, testDictionarySource, {}, () => {}));
- await database.close();
+ await dictionaryDatabase.close();
}
@@ -903,8 +903,8 @@ async function testDatabase3() {
// Setup database
const dictionaryImporter = new DictionaryImporter();
- const database = new Database();
- await database.prepare();
+ const dictionaryDatabase = new DictionaryDatabase();
+ await dictionaryDatabase.prepare();
for (const invalidDictionary of invalidDictionaries) {
const testDictionary = yomichanTest.createTestDictionaryArchive(invalidDictionary);
@@ -912,7 +912,7 @@ async function testDatabase3() {
let error = null;
try {
- await dictionaryImporter.import(database, testDictionarySource, {}, () => {});
+ await dictionaryImporter.import(dictionaryDatabase, testDictionarySource, {}, () => {});
} catch (e) {
error = e;
}
@@ -927,7 +927,7 @@ async function testDatabase3() {
}
}
- await database.close();
+ await dictionaryDatabase.close();
}