Skip to content

Commit

Permalink
Do not delete site data when no tags (history)
Browse files Browse the repository at this point in the history
fix brave#7238

Auditors: @bsclfton, @bbondy

Test Plan:
Covered by automatic test
  • Loading branch information
darkdh committed Feb 14, 2017
1 parent 10239a4 commit f5f069a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
19 changes: 14 additions & 5 deletions js/state/siteUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ module.exports.addSite = function (sites, siteDetail, tag, originalSiteDetail) {
*/
module.exports.removeSite = function (sites, siteDetail, tag, reorder = true) {
const key = module.exports.getSiteKey(siteDetail)
if (!key) {
return sites
}

const tags = sites.getIn([key, 'tags'])
if (isBookmarkFolder(tags)) {
Expand All @@ -267,12 +270,18 @@ module.exports.removeSite = function (sites, siteDetail, tag, reorder = true) {
})
})
}
if (sites.size && reorder) {
const order = sites.getIn([key, 'order'])
sites = reorderSite(sites, order)
}
if (isBookmark(tag)) {
if (sites.size && reorder) {
const order = sites.getIn([key, 'order'])
sites = reorderSite(sites, order)
}

return sites.delete(key)
return sites.delete(key)
} else {
let site = sites.get(key)
site = site.set('lastAccessedTime', undefined)
return sites.set(key, site)
}
}

/**
Expand Down
12 changes: 10 additions & 2 deletions test/unit/state/siteUtilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,21 @@ describe('siteUtil', function () {
it('deletes a history entry (has no tags)', function () {
const siteDetail = {
tags: [],
location: testUrl1
location: testUrl1,
lastAccessedTime: 123
}
const expectedSites = {
'https://brave.com/|0|0': {
tags: [],
location: testUrl1,
lastAccessedTime: undefined
}
}
const siteKey = siteUtil.getSiteKey(Immutable.fromJS(siteDetail))
let sites = {}
sites[siteKey] = siteDetail
const processedSites = siteUtil.removeSite(Immutable.fromJS(sites), Immutable.fromJS(siteDetail))
assert.deepEqual(processedSites, Immutable.fromJS({}))
assert.deepEqual(processedSites.toJS(), expectedSites)
})
})
})
Expand Down

0 comments on commit f5f069a

Please sign in to comment.