Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions browser/main/lib/dataApi/deleteFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const resolveStorageNotes = require('./resolveStorageNotes')
const CSON = require('@rokt33r/season')
const sander = require('sander')
const { findStorage } = require('browser/lib/findStorage')
const deleteSingleNote = require('./deleteNote')

/**
* @param {String} storageKey
Expand Down Expand Up @@ -49,11 +50,7 @@ function deleteFolder (storageKey, folderKey) {

const deleteAllNotes = targetNotes
.map(function deleteNote (note) {
const notePath = path.join(storage.path, 'notes', note.key + '.cson')
return sander.unlink(notePath)
.catch(function (err) {
console.warn('Failed to delete', notePath, err)
})
return deleteSingleNote(storageKey, note.key)
})
return Promise.all(deleteAllNotes)
.then(() => storage)
Expand Down
31 changes: 31 additions & 0 deletions tests/dataApi/deleteFolder-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const test = require('ava')
const deleteFolder = require('browser/main/lib/dataApi/deleteFolder')
const attachmentManagement = require('browser/main/lib/dataApi/attachmentManagement')
const createNote = require('browser/main/lib/dataApi/createNote')
const fs = require('fs')
const faker = require('faker')

global.document = require('jsdom').jsdom('<body></body>')
global.window = document.defaultView
Expand All @@ -24,8 +28,32 @@ test.beforeEach((t) => {
test.serial('Delete a folder', (t) => {
const storageKey = t.context.storage.cache.key
const folderKey = t.context.storage.json.folders[0].key
let noteKey

const input1 = {
type: 'SNIPPET_NOTE',
description: faker.lorem.lines(),
snippets: [{
name: faker.system.fileName(),
mode: 'text',
content: faker.lorem.lines()
}],
tags: faker.lorem.words().split(' '),
folder: folderKey
}
input1.title = input1.description.split('\n').shift()

return Promise.resolve()
.then(function prepare () {
return createNote(storageKey, input1)
.then(function createAttachmentFolder (data) {
fs.mkdirSync(path.join(storagePath, attachmentManagement.DESTINATION_FOLDER))
fs.mkdirSync(path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, data.key))
noteKey = data.key

return data
})
})
.then(function doTest () {
return deleteFolder(storageKey, folderKey)
})
Expand All @@ -36,6 +64,9 @@ test.serial('Delete a folder', (t) => {
t.true(_.find(jsonData.folders, {key: folderKey}) == null)
const notePaths = sander.readdirSync(data.storage.path, 'notes')
t.is(notePaths.length, t.context.storage.notes.filter((note) => note.folder !== folderKey).length)

const attachmentFolderPath = path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, noteKey)
t.false(fs.existsSync(attachmentFolderPath))
})
})

Expand Down
6 changes: 6 additions & 0 deletions tests/dataApi/exportFolder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const TestDummy = require('../fixtures/TestDummy')
const os = require('os')
const faker = require('faker')
const fs = require('fs')
const sander = require('sander')

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

Expand Down Expand Up @@ -60,3 +61,8 @@ test.serial('Export a folder', (t) => {
t.false(fs.existsSync(filePath))
})
})

test.after.always(function after () {
localStorage.clear()
sander.rimrafSync(storagePath)
})