From c26680fd7399e8e1fb5e3c10a3f72f592d59e370 Mon Sep 17 00:00:00 2001 From: Birudo un Date: Mon, 18 Mar 2024 20:29:53 +0800 Subject: feat: support skipping already import dictionaries (#769) --- test/database.test.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/database.test.js b/test/database.test.js index a930d68d..9d57ecab 100644 --- a/test/database.test.js +++ b/test/database.test.js @@ -121,7 +121,7 @@ describe('Database', () => { // Setup database const dictionaryDatabase = new DictionaryDatabase(); /** @type {import('dictionary-importer').ImportDetails} */ - const detaultImportDetails = {prefixWildcardsSupported: false}; + const defaultImportDetails = {prefixWildcardsSupported: false}; // Database not open await expect.soft(dictionaryDatabase.deleteDictionary(title, 1000, () => {})).rejects.toThrow('Database not open'); @@ -135,17 +135,17 @@ describe('Database', () => { await expect.soft(dictionaryDatabase.findTagForTitle('tag', title)).rejects.toThrow('Database not open'); await expect.soft(dictionaryDatabase.getDictionaryInfo()).rejects.toThrow('Database not open'); await expect.soft(dictionaryDatabase.getDictionaryCounts([...titles.keys()], true)).rejects.toThrow('Database not open'); - await expect.soft(createDictionaryImporter(expect).importDictionary(dictionaryDatabase, testDictionarySource, detaultImportDetails)).rejects.toThrow('Database is not ready'); + await expect.soft(createDictionaryImporter(expect).importDictionary(dictionaryDatabase, testDictionarySource, defaultImportDetails)).rejects.toThrow('Database is not ready'); await dictionaryDatabase.prepare(); // Already prepared await expect.soft(dictionaryDatabase.prepare()).rejects.toThrow('Database already open'); - await createDictionaryImporter(expect).importDictionary(dictionaryDatabase, testDictionarySource, detaultImportDetails); + await createDictionaryImporter(expect).importDictionary(dictionaryDatabase, testDictionarySource, defaultImportDetails); // Dictionary already imported - await expect.soft(createDictionaryImporter(expect).importDictionary(dictionaryDatabase, testDictionarySource, detaultImportDetails)).rejects.toThrow('Dictionary is already imported'); + expect.soft(await createDictionaryImporter(expect).importDictionary(dictionaryDatabase, testDictionarySource, defaultImportDetails)).toEqual({result: null, errors: [new Error('Dictionary Test Dictionary is already imported, skipped it.')]}); await dictionaryDatabase.close(); }); @@ -200,7 +200,11 @@ describe('Database', () => { testDictionarySource, {prefixWildcardsSupported: true} ); - importDictionaryResult.importDate = fakeImportDate; + + if (importDictionaryResult) { + importDictionaryResult.importDate = fakeImportDate; + } + expect.soft(importDictionaryErrors).toStrictEqual([]); expect.soft(importDictionaryResult).toStrictEqual(testData.expectedSummary); expect.soft(progressEvent1).toBe(true); -- cgit v1.2.3