1
1
const test = require ( 'ava' )
2
2
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' )
3
7
4
8
global . document = require ( 'jsdom' ) . jsdom ( '<body></body>' )
5
9
global . window = document . defaultView
@@ -24,8 +28,32 @@ test.beforeEach((t) => {
24
28
test . serial ( 'Delete a folder' , ( t ) => {
25
29
const storageKey = t . context . storage . cache . key
26
30
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 ( )
27
45
28
46
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
+ } )
29
57
. then ( function doTest ( ) {
30
58
return deleteFolder ( storageKey , folderKey )
31
59
} )
@@ -36,6 +64,9 @@ test.serial('Delete a folder', (t) => {
36
64
t . true ( _ . find ( jsonData . folders , { key : folderKey } ) == null )
37
65
const notePaths = sander . readdirSync ( data . storage . path , 'notes' )
38
66
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 ) )
39
70
} )
40
71
} )
41
72
0 commit comments