From 990591cc80b03091583cbe35aa3af904bf74cc3a Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Tue, 30 Oct 2018 00:17:50 +0000 Subject: [PATCH] Minor improvments --- CliClient/app/command-sync.js | 1 + CliClient/run_test.sh | 1 + CliClient/tests/models_BaseItem.js | 37 +++++++++++++++++++++++++++ CliClient/tests/models_Resource.js | 2 +- ReactNativeClient/lib/synchronizer.js | 5 ++-- 5 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 CliClient/tests/models_BaseItem.js diff --git a/CliClient/app/command-sync.js b/CliClient/app/command-sync.js index b6753fb97..90dc80666 100644 --- a/CliClient/app/command-sync.js +++ b/CliClient/app/command-sync.js @@ -196,6 +196,7 @@ class Command extends BaseCommand { // not going to be running in the background, so the resources need to be // explicitely downloaded below. if (!app().hasGui()) { + this.stdout(_('Downloading resources...')); await ResourceFetcher.instance().fetchAll(); await ResourceFetcher.instance().waitForAllFinished(); } diff --git a/CliClient/run_test.sh b/CliClient/run_test.sh index 89a6801eb..2dfa8a3e7 100755 --- a/CliClient/run_test.sh +++ b/CliClient/run_test.sh @@ -25,6 +25,7 @@ npm test tests-build/ArrayUtils.js npm test tests-build/EnexToMd.js npm test tests-build/HtmlToMd.js npm test tests-build/markdownUtils.js +npm test tests-build/models_BaseItem.js npm test tests-build/models_Folder.js npm test tests-build/models_Note.js npm test tests-build/models_Tag.js diff --git a/CliClient/tests/models_BaseItem.js b/CliClient/tests/models_BaseItem.js new file mode 100644 index 000000000..4a4ca4ea1 --- /dev/null +++ b/CliClient/tests/models_BaseItem.js @@ -0,0 +1,37 @@ +require('app-module-path').addPath(__dirname); + +const { time } = require('lib/time-utils.js'); +const { asyncTest, fileContentEqual, setupDatabase, setupDatabaseAndSynchronizer, db, synchronizer, fileApi, sleep, clearDatabase, switchClient, syncTargetId, objectsEqual, checkThrowAsync } = require('test-utils.js'); +const Folder = require('lib/models/Folder.js'); +const Note = require('lib/models/Note.js'); +const Resource = require('lib/models/Resource.js'); +const BaseModel = require('lib/BaseModel.js'); +const { shim } = require('lib/shim'); + +process.on('unhandledRejection', (reason, p) => { + console.log('Unhandled Rejection at: Promise', p, 'reason:', reason); +}); + +async function allItems() { + let folders = await Folder.all(); + let notes = await Note.all(); + return folders.concat(notes); +} + +describe('models_BaseItem', function() { + + beforeEach(async (done) => { + await setupDatabaseAndSynchronizer(1); + await switchClient(1); + done(); + }); + + it('should be able to exclude keys when syncing', asyncTest(async () => { + let folder1 = await Folder.save({ title: "folder1" }); + let note1 = await Note.save({ title: 'ma note', parent_id: folder1.id }); + await shim.attachFileToNote(note1, __dirname + '/../tests/support/photo.jpg'); + let resource1 = (await Resource.all())[0]; + console.info(await Resource.serializeForSync(resource1)); + })); + +}); \ No newline at end of file diff --git a/CliClient/tests/models_Resource.js b/CliClient/tests/models_Resource.js index 294414361..e4bd7a9a5 100644 --- a/CliClient/tests/models_Resource.js +++ b/CliClient/tests/models_Resource.js @@ -25,7 +25,7 @@ describe('models_Resource', function() { let note1 = await Note.save({ title: 'ma note', parent_id: folder1.id }); await shim.attachFileToNote(note1, __dirname + '/../tests/support/photo.jpg'); let resource1 = (await Resource.all())[0]; - console.info(resource1); + expect(resource1.fetch_status).toBe(Resource.FETCH_STATUS_DONE); })); }); \ No newline at end of file diff --git a/ReactNativeClient/lib/synchronizer.js b/ReactNativeClient/lib/synchronizer.js index f469e5562..b25fd770e 100644 --- a/ReactNativeClient/lib/synchronizer.js +++ b/ReactNativeClient/lib/synchronizer.js @@ -248,7 +248,7 @@ class Synchronizer { reason = "remote does not exist, and local is new and has never been synced"; } else { // Note or item was modified after having been deleted remotely - // "itemConflict" if for all the items except the notes, which are dealt with in a special way + // "itemConflict" is for all the items except the notes, which are dealt with in a special way action = local.type_ == BaseModel.TYPE_NOTE ? "noteConflict" : "itemConflict"; reason = "remote has been deleted, but local has changes"; } @@ -440,7 +440,7 @@ class Synchronizer { // 3. DELTA // ------------------------------------------------------------------------ // Loop through all the remote items, find those that - // have been updated, and apply the changes to local. + // have been created or updated, and apply the changes to local. // ------------------------------------------------------------------------ if (syncSteps.indexOf("delta") >= 0) { @@ -525,6 +525,7 @@ class Synchronizer { this.logger().warn('Rejected by target: ' + path + ': ' + error.message); action = null; } else { + error.message = 'On file ' + path + ': ' + error.message; throw error; } }