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

Merge branch 'master' into Moving_Note_With_Attachment

This commit is contained in:
Junyoung Choi (Sai)
2018-05-17 01:28:47 +09:00
committed by GitHub
15 changed files with 95 additions and 7 deletions

View File

@@ -8,6 +8,7 @@ jest.mock('unique-slug')
const uniqueSlug = require('unique-slug')
const mdurl = require('mdurl')
const fse = require('fs-extra')
const sander = require('sander')
const systemUnderTest = require('browser/main/lib/dataApi/attachmentManagement')
@@ -262,6 +263,19 @@ it('should remove the all ":storage" and noteKey references', function () {
expect(actual).toEqual(expectedOutput)
})
it('should delete the correct attachment folder if a note is deleted', function () {
const dummyStorage = {path: 'dummyStoragePath'}
const storageKey = 'storageKey'
const noteKey = 'noteKey'
findStorage.findStorage = jest.fn(() => dummyStorage)
sander.rimrafSync = jest.fn()
const expectedPathToBeDeleted = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, noteKey)
systemUnderTest.deleteAttachmentFolder(storageKey, noteKey)
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
expect(sander.rimrafSync).toHaveBeenCalledWith(expectedPathToBeDeleted)
})
it('should test that deleteAttachmentsNotPresentInNote deletes all unreferenced attachments ', function () {
const dummyStorage = {path: 'dummyStoragePath'}
const noteKey = 'noteKey'

View File

@@ -14,6 +14,8 @@ const sander = require('sander')
const os = require('os')
const CSON = require('@rokt33r/season')
const faker = require('faker')
const fs = require('fs')
const attachmentManagement = require('browser/main/lib/dataApi/attachmentManagement')
const storagePath = path.join(os.tmpdir(), 'test/delete-note')
@@ -42,6 +44,11 @@ test.serial('Delete a note', (t) => {
return Promise.resolve()
.then(function doTest () {
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))
return data
})
.then(function (data) {
return deleteNote(storageKey, data.key)
})
@@ -52,8 +59,13 @@ test.serial('Delete a note', (t) => {
t.fail('note cson must be deleted.')
} catch (err) {
t.is(err.code, 'ENOENT')
return data
}
})
.then(function assertAttachmentFolderDeleted (data) {
const attachmentFolderPath = path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, data.noteKey)
t.is(fs.existsSync(attachmentFolderPath), false)
})
})
test.after(function after () {