1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 01:36:22 +00:00

Merge pull request #1936 from ehhc/delete_folder

deleting a folder should also delete the attachments -> fixes #1903
This commit is contained in:
Junyoung Choi (Sai)
2018-05-24 14:45:47 +09:00
committed by GitHub
3 changed files with 39 additions and 5 deletions

View File

@@ -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
@@ -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)

View File

@@ -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
@@ -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)
})
@@ -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))
})
})

View File

@@ -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')
@@ -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)
})