Skip to content

Commit

Permalink
Merge pull request #260 from bcgov/bug/sync-public
Browse files Browse the repository at this point in the history
Bug fix: Sync public flag on object
  • Loading branch information
TimCsaky authored May 2, 2024
2 parents 8f2b685 + 7cf7aef commit 71ee983
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
28 changes: 12 additions & 16 deletions app/src/services/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/tests/unit/services/sync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
});

Expand Down

0 comments on commit 71ee983

Please sign in to comment.