diff --git a/app/src/services/sync.js b/app/src/services/sync.js index 82ef5d02..1477e3d2 100644 --- a/app/src/services/sync.js +++ b/app/src/services/sync.js @@ -159,22 +159,18 @@ const service = { // Case: already synced - record & update public status as needed if (comsObject) { - if (s3Public === undefined || s3Public === comsObject.public) { - response = await objectService.update({ - id: comsObject.id, - userId: userId, - lastSyncedDate: new Date().toISOString() - }, trx); - } else { - response = await objectService.update({ - id: comsObject.id, - userId: userId, - path: comsObject.path, - public: s3Public, - lastSyncedDate: new Date().toISOString() - }, trx); - modified = true; - } + + response = await objectService.update({ + id: comsObject.id, + userId: userId, + path: comsObject.path, + // update if public in s3 + public: s3Public ? s3Public : comsObject.public, + lastSyncedDate: new Date().toISOString() + }, trx); + + // if public flag changed mark as modified + if (s3Public && !comsObject.public) modified = true; } // Case: not in COMS - insert new COMS object diff --git a/app/tests/unit/services/sync.spec.js b/app/tests/unit/services/sync.spec.js index 8ff047df..c0d24a64 100644 --- a/app/tests/unit/services/sync.spec.js +++ b/app/tests/unit/services/sync.spec.js @@ -424,7 +424,7 @@ describe('syncObject', () => { const result = await service.syncObject(path, bucketId); expect(result).toBeTruthy(); - expect(result.modified).toBeTruthy(); + expect(result.modified).toBeFalsy(); expect(result.object).toEqual(comsObject); expect(ObjectModel.startTransaction).toHaveBeenCalledTimes(1); @@ -448,7 +448,7 @@ describe('syncObject', () => { expect(objectModelTrx.commit).toHaveBeenCalledTimes(1); expect(updateSpy).toHaveBeenCalledTimes(1); expect(updateSpy).toHaveBeenCalledWith(expect.objectContaining({ - id: validUuidv4, path: path, public: false, lastSyncedDate: expect.anything(), userId: SYSTEM_USER + id: validUuidv4, path: path, public: true, lastSyncedDate: expect.anything(), userId: SYSTEM_USER }), expect.any(Object)); });