mirror of
https://github.com/BoostIo/Boostnote
synced 2026-01-27 15:47:15 +00:00
deleting a folder should also delete the attachments -> fixes #1903
This commit is contained in:
@@ -5,6 +5,7 @@ const resolveStorageNotes = require('./resolveStorageNotes')
|
|||||||
const CSON = require('@rokt33r/season')
|
const CSON = require('@rokt33r/season')
|
||||||
const sander = require('sander')
|
const sander = require('sander')
|
||||||
const { findStorage } = require('browser/lib/findStorage')
|
const { findStorage } = require('browser/lib/findStorage')
|
||||||
|
const deleteSingleNote = require('./deleteNote')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {String} storageKey
|
* @param {String} storageKey
|
||||||
@@ -49,11 +50,7 @@ function deleteFolder (storageKey, folderKey) {
|
|||||||
|
|
||||||
const deleteAllNotes = targetNotes
|
const deleteAllNotes = targetNotes
|
||||||
.map(function deleteNote (note) {
|
.map(function deleteNote (note) {
|
||||||
const notePath = path.join(storage.path, 'notes', note.key + '.cson')
|
return deleteSingleNote(storageKey, note.key)
|
||||||
return sander.unlink(notePath)
|
|
||||||
.catch(function (err) {
|
|
||||||
console.warn('Failed to delete', notePath, err)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
return Promise.all(deleteAllNotes)
|
return Promise.all(deleteAllNotes)
|
||||||
.then(() => storage)
|
.then(() => storage)
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
const test = require('ava')
|
const test = require('ava')
|
||||||
const deleteFolder = require('browser/main/lib/dataApi/deleteFolder')
|
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.document = require('jsdom').jsdom('<body></body>')
|
||||||
global.window = document.defaultView
|
global.window = document.defaultView
|
||||||
@@ -24,8 +28,32 @@ test.beforeEach((t) => {
|
|||||||
test.serial('Delete a folder', (t) => {
|
test.serial('Delete a folder', (t) => {
|
||||||
const storageKey = t.context.storage.cache.key
|
const storageKey = t.context.storage.cache.key
|
||||||
const folderKey = t.context.storage.json.folders[0].key
|
const folderKey = t.context.storage.json.folders[0].key
|
||||||
|
let noteKey = undefined
|
||||||
|
|
||||||
|
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()
|
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 () {
|
.then(function doTest () {
|
||||||
return deleteFolder(storageKey, folderKey)
|
return deleteFolder(storageKey, folderKey)
|
||||||
})
|
})
|
||||||
@@ -36,6 +64,9 @@ test.serial('Delete a folder', (t) => {
|
|||||||
t.true(_.find(jsonData.folders, {key: folderKey}) == null)
|
t.true(_.find(jsonData.folders, {key: folderKey}) == null)
|
||||||
const notePaths = sander.readdirSync(data.storage.path, 'notes')
|
const notePaths = sander.readdirSync(data.storage.path, 'notes')
|
||||||
t.is(notePaths.length, t.context.storage.notes.filter((note) => note.folder !== folderKey).length)
|
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))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ const TestDummy = require('../fixtures/TestDummy')
|
|||||||
const os = require('os')
|
const os = require('os')
|
||||||
const faker = require('faker')
|
const faker = require('faker')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
const sander = require('sander')
|
||||||
|
|
||||||
const storagePath = path.join(os.tmpdir(), 'test/export-note')
|
const storagePath = path.join(os.tmpdir(), 'test/export-note')
|
||||||
|
|
||||||
@@ -60,3 +61,8 @@ test.serial('Export a folder', (t) => {
|
|||||||
t.false(fs.existsSync(filePath))
|
t.false(fs.existsSync(filePath))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test.after.always(function after () {
|
||||||
|
localStorage.clear()
|
||||||
|
sander.rimrafSync(storagePath)
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user