Skip to content

Commit a996a46

Browse files
committed
Fix: Duplicates with nextcloud-folders adapter
1 parent 0b02f9d commit a996a46

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/lib/adapters/NextcloudFolders.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,9 @@ export default class NextcloudFoldersAdapter extends Adapter {
429429
bm.id = json.item.id + ';' + bm.parentId
430430
}
431431
// add bookmark to cached list
432-
this.list.push(bm)
432+
let upstreamMark = bm.clone()
433+
upstreamMark.id = bm.id.split(';')[0]
434+
this.list.push(upstreamMark)
433435

434436
return bm.id
435437
})

src/test/test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,58 @@ describe('Floccus', function() {
450450
ACCOUNT_DATA.type === 'nextcloud'
451451
)
452452
})
453+
it('should be able to handle duplicates', async function() {
454+
var adapter = account.server
455+
expect((await adapter.getBookmarksTree()).children).to.have.lengthOf(
456+
0
457+
)
458+
459+
const localRoot = account.getData().localRoot
460+
const bookmarkData = {
461+
title: 'url',
462+
url: 'http://ur.l/'
463+
}
464+
const fooFolder = await browser.bookmarks.create({
465+
title: 'foo',
466+
parentId: localRoot
467+
})
468+
const bookmark1 = await browser.bookmarks.create({
469+
...bookmarkData,
470+
parentId: fooFolder.id
471+
})
472+
const barFolder = await browser.bookmarks.create({
473+
title: 'bar',
474+
parentId: fooFolder.id
475+
})
476+
const bookmark2 = await browser.bookmarks.create({
477+
...bookmarkData,
478+
parentId: barFolder.id
479+
})
480+
await account.sync() // propagate to server
481+
482+
await browser.bookmarks.move(barFolder.id, { parentId: localRoot })
483+
await account.sync() // update on server
484+
expect(account.getData().error).to.not.be.ok
485+
486+
const tree = await adapter.getBookmarksTree()
487+
expectTreeEqual(
488+
tree,
489+
new Folder({
490+
title: tree.title,
491+
children: [
492+
new Folder({
493+
title: 'foo',
494+
children: [new Bookmark(bookmarkData)]
495+
}),
496+
new Folder({
497+
title: 'bar',
498+
children: [new Bookmark(bookmarkData)]
499+
})
500+
]
501+
}),
502+
ACCOUNT_DATA.type === 'nextcloud'
503+
)
504+
})
453505
it('should not fail when moving both folders and contents', async function() {
454506
var adapter = account.server
455507
expect((await adapter.getBookmarksTree()).children).to.have.lengthOf(

0 commit comments

Comments
 (0)