diff --git a/CliClient/tests/services_rest_Api.js b/CliClient/tests/services_rest_Api.js index 27ce5814aa..54469b13c8 100644 --- a/CliClient/tests/services_rest_Api.js +++ b/CliClient/tests/services_rest_Api.js @@ -5,9 +5,10 @@ const { fileContentEqual, setupDatabase, setupDatabaseAndSynchronizer, db, synch const markdownUtils = require('lib/markdownUtils.js'); const Api = require('lib/services/rest/Api'); const Folder = require('lib/models/Folder'); +const Resource = require('lib/models/Resource'); const Note = require('lib/models/Note'); const Tag = require('lib/models/Tag'); -const Resource = require('lib/models/Resource'); +const { shim } = require('lib/shim'); jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; @@ -252,6 +253,28 @@ describe('services_rest_Api', function() { done(); }); + it('should delete resources', async (done) => { + let response = null; + const f = await Folder.save({ title: "mon carnet" }); + + response = await api.route('POST', 'notes', null, JSON.stringify({ + title: 'testing image', + parent_id: f.id, + image_data_url: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAANZJREFUeNoAyAA3/wFwtO3K6gUB/vz2+Prw9fj/+/r+/wBZKAAExOgF4/MC9ff+MRH6Ui4E+/0Bqc/zutj6AgT+/Pz7+vv7++nu82c4DlMqCvLs8goA/gL8/fz09fb59vXa6vzZ6vjT5fbn6voD/fwC8vX4UiT9Zi//APHyAP8ACgUBAPv5APz7BPj2+DIaC2o3E+3o6ywaC5fT6gD6/QD9/QEVf9kD+/dcLQgJA/7v8vqfwOf18wA1IAIEVycAyt//v9XvAPv7APz8LhoIAPz9Ri4OAgwARgx4W/6fVeEAAAAASUVORK5CYII=" + })); + + const resource = (await Resource.all())[0]; + + const filePath = Resource.fullPath(resource); + expect(await shim.fsDriver().exists(filePath)).toBe(true); + + await api.route('DELETE', 'resources/' + resource.id); + expect(await shim.fsDriver().exists(filePath)).toBe(false); + expect(!(await Resource.load(resource.id))).toBe(true); + + done(); + }); + it('should create notes from HTML', async (done) => { let response = null; const f = await Folder.save({ title: "mon carnet" }); diff --git a/CliClient/tests/synchronizer.js b/CliClient/tests/synchronizer.js index 509ebb2449..968e1ed7c6 100644 --- a/CliClient/tests/synchronizer.js +++ b/CliClient/tests/synchronizer.js @@ -947,6 +947,9 @@ describe('Synchronizer', function() { await synchronizer().start(); expect((await remoteNotesFoldersResources()).length).toBe(2); + const remoteBlob = await fileApi().stat('.resource/' + resource1.id); + expect(!remoteBlob).toBe(true); + await switchClient(1); expect(await shim.fsDriver().exists(resourcePath1)).toBe(true); diff --git a/ReactNativeClient/lib/synchronizer.js b/ReactNativeClient/lib/synchronizer.js index 95e45fdddf..0685acbf08 100644 --- a/ReactNativeClient/lib/synchronizer.js +++ b/ReactNativeClient/lib/synchronizer.js @@ -223,6 +223,10 @@ class Synchronizer { this.dispatch({ type: "SYNC_HAS_DISABLED_SYNC_ITEMS" }); } + const resourceRemotePath = resourceId => { + return this.resourceDirName_ + "/" + resourceId; + } + try { await this.api().mkdir(this.syncDirName_); this.api().setTempDirName(this.syncDirName_); @@ -330,7 +334,7 @@ class Synchronizer { action = null; } else { try { - const remoteContentPath = this.resourceDirName_ + "/" + local.id; + const remoteContentPath = resourceRemotePath(local.id); const result = await Resource.fullPathForSyncUpload(local); local = result.resource; const localResourceContentPath = result.path; @@ -461,6 +465,12 @@ class Synchronizer { let path = BaseItem.systemPath(item.item_id); this.logSyncOperation("deleteRemote", null, { id: item.item_id }, "local has been deleted"); await this.api().delete(path); + + if (item.item_type === BaseModel.TYPE_RESOURCE) { + const remoteContentPath = resourceRemotePath(item.item_id); + await this.api().delete(remoteContentPath); + } + await BaseItem.remoteDeletedItem(syncTargetId, item.item_id); } } // DELETE_REMOTE STEP