Skip to content

Commit 0d296c3

Browse files
authored
Merge pull request #1936 from ehhc/delete_folder
deleting a folder should also delete the attachments -> fixes #1903
2 parents 73caa25 + 199f220 commit 0d296c3

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

browser/main/lib/dataApi/deleteFolder.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const resolveStorageNotes = require('./resolveStorageNotes')
55
const CSON = require('@rokt33r/season')
66
const sander = require('sander')
77
const { findStorage } = require('browser/lib/findStorage')
8+
const deleteSingleNote = require('./deleteNote')
89

910
/**
1011
* @param {String} storageKey
@@ -49,11 +50,7 @@ function deleteFolder (storageKey, folderKey) {
4950

5051
const deleteAllNotes = targetNotes
5152
.map(function deleteNote (note) {
52-
const notePath = path.join(storage.path, 'notes', note.key + '.cson')
53-
return sander.unlink(notePath)
54-
.catch(function (err) {
55-
console.warn('Failed to delete', notePath, err)
56-
})
53+
return deleteSingleNote(storageKey, note.key)
5754
})
5855
return Promise.all(deleteAllNotes)
5956
.then(() => storage)

tests/dataApi/deleteFolder-test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const test = require('ava')
22
const deleteFolder = require('browser/main/lib/dataApi/deleteFolder')
3+
const attachmentManagement = require('browser/main/lib/dataApi/attachmentManagement')
4+
const createNote = require('browser/main/lib/dataApi/createNote')
5+
const fs = require('fs')
6+
const faker = require('faker')
37

48
global.document = require('jsdom').jsdom('<body></body>')
59
global.window = document.defaultView
@@ -24,8 +28,32 @@ test.beforeEach((t) => {
2428
test.serial('Delete a folder', (t) => {
2529
const storageKey = t.context.storage.cache.key
2630
const folderKey = t.context.storage.json.folders[0].key
31+
let noteKey
32+
33+
const input1 = {
34+
type: 'SNIPPET_NOTE',
35+
description: faker.lorem.lines(),
36+
snippets: [{
37+
name: faker.system.fileName(),
38+
mode: 'text',
39+
content: faker.lorem.lines()
40+
}],
41+
tags: faker.lorem.words().split(' '),
42+
folder: folderKey
43+
}
44+
input1.title = input1.description.split('\n').shift()
2745

2846
return Promise.resolve()
47+
.then(function prepare () {
48+
return createNote(storageKey, input1)
49+
.then(function createAttachmentFolder (data) {
50+
fs.mkdirSync(path.join(storagePath, attachmentManagement.DESTINATION_FOLDER))
51+
fs.mkdirSync(path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, data.key))
52+
noteKey = data.key
53+
54+
return data
55+
})
56+
})
2957
.then(function doTest () {
3058
return deleteFolder(storageKey, folderKey)
3159
})
@@ -36,6 +64,9 @@ test.serial('Delete a folder', (t) => {
3664
t.true(_.find(jsonData.folders, {key: folderKey}) == null)
3765
const notePaths = sander.readdirSync(data.storage.path, 'notes')
3866
t.is(notePaths.length, t.context.storage.notes.filter((note) => note.folder !== folderKey).length)
67+
68+
const attachmentFolderPath = path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, noteKey)
69+
t.false(fs.existsSync(attachmentFolderPath))
3970
})
4071
})
4172

tests/dataApi/exportFolder-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const TestDummy = require('../fixtures/TestDummy')
1313
const os = require('os')
1414
const faker = require('faker')
1515
const fs = require('fs')
16+
const sander = require('sander')
1617

1718
const storagePath = path.join(os.tmpdir(), 'test/export-note')
1819

@@ -60,3 +61,8 @@ test.serial('Export a folder', (t) => {
6061
t.false(fs.existsSync(filePath))
6162
})
6263
})
64+
65+
test.after.always(function after () {
66+
localStorage.clear()
67+
sander.rimrafSync(storagePath)
68+
})

0 commit comments

Comments
 (0)