Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #9968 from brave/fix/sync-107
Browse files Browse the repository at this point in the history
Set bookmark parent ID to 0 if parentFolderObjectId is empty
  • Loading branch information
bsclifton authored Jul 12, 2017
2 parents 5b5da80 + 8d7de52 commit be93d99
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
6 changes: 4 additions & 2 deletions js/state/syncUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ module.exports.getSiteDataFromRecord = (record, appState, records) => {
if (parentFolderObjectId && parentFolderObjectId.length > 0) {
siteProps.parentFolderId =
getFolderIdByObjectId(new Immutable.List(parentFolderObjectId), appState, records)
} else if (siteProps.hideInToolbar === true) {
siteProps.parentFolderId = -1
} else {
// Null or empty parentFolderObjectId on a record corresponds to
// a top-level bookmark. -1 indicates a hidden bookmark.
siteProps.parentFolderId = siteProps.hideInToolbar ? -1 : 0
}
}
const siteDetail = new Immutable.Map(pickFields(siteProps, SITE_FIELDS))
Expand Down
62 changes: 62 additions & 0 deletions test/unit/state/syncUtilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const syncUtil = require('../../../js/state/syncUtil')
const assert = require('assert')
const Immutable = require('immutable')

describe('syncUtil', () => {
describe('createSiteData()', () => {
Expand Down Expand Up @@ -150,4 +151,65 @@ describe('syncUtil', () => {
assert.deepEqual(syncUtil.ipcSafeObject(deepObject), deepExpected)
})
})

describe('getSiteDataFromRecord()', () => {
it('update bookmark parent folder to null -> overrides existing parent folder', () => {
const objectId = [96, 46, 213, 0, 13, 111, 180, 184, 65, 66, 173, 27, 207, 29, 32, 108]
const records = [{
action: 1,
bookmark: {
isFolder: true,
parentFolderObjectId: null,
site: {
creationTime: 0,
customTitle: '',
favicon: '',
lastAccessedTime: 0,
location: '',
title: 'Folder1'
}
},
deviceId: [1],
objectData: 'bookmark',
objectId,
syncTimestamp: 1499736988267
}]
const existingObject = {
lastAccessedTime: 0,
tags: ['bookmark-folder'],
objectId,
order: 9,
folderId: 2,
customTitle: 'Folder1', // XXX: Android uses title whereas laptop uses customTitle
parentFolderId: 1
}
const appState = {
sites: {
'2': existingObject
},
sync: {
objectsById: {
[objectId.join('|')]: ['sites', '2']
}
}
}
const result = syncUtil.getSiteDataFromRecord(records[0],
Immutable.fromJS(appState), Immutable.fromJS(records))
assert.equal(result.tag, 'bookmark-folder')
assert.deepEqual(result.siteDetail.toJS(),
{
objectId,
title: 'Folder1',
favicon: '',
location: '',
parentFolderId: 0,
folderId: 2,
tags: ['bookmark-folder'],
lastAccessedTime: 0,
creationTime: 0
}
)
assert.deepEqual(result.existingObjectData.toJS(), existingObject)
})
})
})

0 comments on commit be93d99

Please sign in to comment.