@@ -38,7 +38,7 @@ it('should test that copyAttachment should throw an error if sourcePath dosen\'t
38
38
fs . existsSync = jest . fn ( )
39
39
fs . existsSync . mockReturnValue ( false )
40
40
41
- systemUnderTest . copyAttachment ( 'path' , 'storageKey' , 'noteKey' ) . then ( ( ) => { } , error => {
41
+ return systemUnderTest . copyAttachment ( 'path' , 'storageKey' , 'noteKey' ) . then ( ( ) => { } , error => {
42
42
expect ( error ) . toBe ( 'source file does not exist' )
43
43
expect ( fs . existsSync ) . toHaveBeenCalledWith ( 'path' )
44
44
} )
@@ -64,7 +64,7 @@ it('should test that copyAttachment works correctly assuming correct working of
64
64
findStorage . findStorage . mockReturnValue ( dummyStorage )
65
65
uniqueSlug . mockReturnValue ( dummyUniquePath )
66
66
67
- systemUnderTest . copyAttachment ( sourcePath , storageKey , noteKey ) . then (
67
+ return systemUnderTest . copyAttachment ( sourcePath , storageKey , noteKey ) . then (
68
68
function ( newFileName ) {
69
69
expect ( findStorage . findStorage ) . toHaveBeenCalledWith ( storageKey )
70
70
expect ( fs . createReadStream ) . toHaveBeenCalledWith ( sourcePath )
@@ -83,7 +83,7 @@ it('should test that copyAttachment creates a new folder if the attachment folde
83
83
const dummyReadStream = { }
84
84
85
85
dummyReadStream . pipe = jest . fn ( )
86
- dummyReadStream . on = jest . fn ( )
86
+ dummyReadStream . on = jest . fn ( ( event , callback ) => { callback ( ) } )
87
87
fs . createReadStream = jest . fn ( ( ) => dummyReadStream )
88
88
fs . existsSync = jest . fn ( )
89
89
fs . existsSync . mockReturnValueOnce ( true )
@@ -95,7 +95,7 @@ it('should test that copyAttachment creates a new folder if the attachment folde
95
95
findStorage . findStorage . mockReturnValue ( dummyStorage )
96
96
uniqueSlug . mockReturnValue ( 'dummyPath' )
97
97
98
- systemUnderTest . copyAttachment ( 'path' , 'storageKey' , 'noteKey' ) . then (
98
+ return systemUnderTest . copyAttachment ( 'path' , 'storageKey' , 'noteKey' ) . then (
99
99
function ( ) {
100
100
expect ( fs . existsSync ) . toHaveBeenCalledWith ( attachmentFolderPath )
101
101
expect ( fs . mkdirSync ) . toHaveBeenCalledWith ( attachmentFolderPath )
@@ -109,7 +109,7 @@ it('should test that copyAttachment don\'t uses a random file name if not intend
109
109
const dummyReadStream = { }
110
110
111
111
dummyReadStream . pipe = jest . fn ( )
112
- dummyReadStream . on = jest . fn ( )
112
+ dummyReadStream . on = jest . fn ( ( event , callback ) => { callback ( ) } )
113
113
fs . createReadStream = jest . fn ( ( ) => dummyReadStream )
114
114
fs . existsSync = jest . fn ( )
115
115
fs . existsSync . mockReturnValueOnce ( true )
@@ -120,12 +120,152 @@ it('should test that copyAttachment don\'t uses a random file name if not intend
120
120
findStorage . findStorage . mockReturnValue ( dummyStorage )
121
121
uniqueSlug . mockReturnValue ( 'dummyPath' )
122
122
123
- systemUnderTest . copyAttachment ( 'path' , 'storageKey' , 'noteKey' , false ) . then (
123
+ return systemUnderTest . copyAttachment ( 'path' , 'storageKey' , 'noteKey' , false ) . then (
124
124
function ( newFileName ) {
125
125
expect ( newFileName ) . toBe ( 'path' )
126
126
} )
127
127
} )
128
128
129
+ it ( 'should test that copyAttachment with url (with extension, without query)' , function ( ) {
130
+ const dummyStorage = { path : 'dummyStoragePath' }
131
+
132
+ const dummyReadStream = {
133
+ pipe : jest . fn ( ) ,
134
+ on : jest . fn ( ( event , callback ) => { callback ( ) } )
135
+ }
136
+ fs . createReadStream = jest . fn ( ( ) => dummyReadStream )
137
+
138
+ const dummyWriteStream = {
139
+ write : jest . fn ( ( data , callback ) => { callback ( ) } )
140
+ }
141
+ fs . createWriteStream = jest . fn ( ( ) => dummyWriteStream )
142
+
143
+ fs . existsSync = jest . fn ( )
144
+ fs . existsSync . mockReturnValueOnce ( true )
145
+ fs . existsSync . mockReturnValueOnce ( false )
146
+ fs . mkdirSync = jest . fn ( )
147
+
148
+ findStorage . findStorage = jest . fn ( )
149
+ findStorage . findStorage . mockReturnValue ( dummyStorage )
150
+ uniqueSlug . mockReturnValue ( 'dummyPath' )
151
+
152
+ const sourcePath = {
153
+ sourceFilePath : 'http://www.foo.bar/baz/qux.jpg' ,
154
+ type : 'base64' ,
155
+ data : 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
156
+ }
157
+
158
+ return systemUnderTest . copyAttachment ( sourcePath , 'storageKey' , 'noteKey' ) . then (
159
+ function ( newFileName ) {
160
+ expect ( newFileName ) . toBe ( 'dummyPath.jpg' )
161
+ } )
162
+ } )
163
+
164
+ it ( 'should test that copyAttachment with url (with extension, with query)' , function ( ) {
165
+ const dummyStorage = { path : 'dummyStoragePath' }
166
+
167
+ const dummyReadStream = {
168
+ pipe : jest . fn ( ) ,
169
+ on : jest . fn ( ( event , callback ) => { callback ( ) } )
170
+ }
171
+ fs . createReadStream = jest . fn ( ( ) => dummyReadStream )
172
+
173
+ const dummyWriteStream = {
174
+ write : jest . fn ( ( data , callback ) => { callback ( ) } )
175
+ }
176
+ fs . createWriteStream = jest . fn ( ( ) => dummyWriteStream )
177
+
178
+ fs . existsSync = jest . fn ( )
179
+ fs . existsSync . mockReturnValueOnce ( true )
180
+ fs . existsSync . mockReturnValueOnce ( false )
181
+ fs . mkdirSync = jest . fn ( )
182
+
183
+ findStorage . findStorage = jest . fn ( )
184
+ findStorage . findStorage . mockReturnValue ( dummyStorage )
185
+ uniqueSlug . mockReturnValue ( 'dummyPath' )
186
+
187
+ const sourcePath = {
188
+ sourceFilePath : 'http://www.foo.bar/baz/qux.jpg?h=1080' ,
189
+ type : 'base64' ,
190
+ data : 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
191
+ }
192
+
193
+ return systemUnderTest . copyAttachment ( sourcePath , 'storageKey' , 'noteKey' ) . then (
194
+ function ( newFileName ) {
195
+ expect ( newFileName ) . toBe ( 'dummyPath.jpg' )
196
+ } )
197
+ } )
198
+
199
+ it ( 'should test that copyAttachment with url (without extension, without query)' , function ( ) {
200
+ const dummyStorage = { path : 'dummyStoragePath' }
201
+
202
+ const dummyReadStream = {
203
+ pipe : jest . fn ( ) ,
204
+ on : jest . fn ( ( event , callback ) => { callback ( ) } )
205
+ }
206
+ fs . createReadStream = jest . fn ( ( ) => dummyReadStream )
207
+
208
+ const dummyWriteStream = {
209
+ write : jest . fn ( ( data , callback ) => { callback ( ) } )
210
+ }
211
+ fs . createWriteStream = jest . fn ( ( ) => dummyWriteStream )
212
+
213
+ fs . existsSync = jest . fn ( )
214
+ fs . existsSync . mockReturnValueOnce ( true )
215
+ fs . existsSync . mockReturnValueOnce ( false )
216
+ fs . mkdirSync = jest . fn ( )
217
+
218
+ findStorage . findStorage = jest . fn ( )
219
+ findStorage . findStorage . mockReturnValue ( dummyStorage )
220
+ uniqueSlug . mockReturnValue ( 'dummyPath' )
221
+
222
+ const sourcePath = {
223
+ sourceFilePath : 'http://www.foo.bar/baz/qux' ,
224
+ type : 'base64' ,
225
+ data : 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
226
+ }
227
+
228
+ return systemUnderTest . copyAttachment ( sourcePath , 'storageKey' , 'noteKey' ) . then (
229
+ function ( newFileName ) {
230
+ expect ( newFileName ) . toBe ( 'dummyPath.png' )
231
+ } )
232
+ } )
233
+
234
+ it ( 'should test that copyAttachment with url (without extension, with query)' , function ( ) {
235
+ const dummyStorage = { path : 'dummyStoragePath' }
236
+
237
+ const dummyReadStream = {
238
+ pipe : jest . fn ( ) ,
239
+ on : jest . fn ( ( event , callback ) => { callback ( ) } )
240
+ }
241
+ fs . createReadStream = jest . fn ( ( ) => dummyReadStream )
242
+
243
+ const dummyWriteStream = {
244
+ write : jest . fn ( ( data , callback ) => { callback ( ) } )
245
+ }
246
+ fs . createWriteStream = jest . fn ( ( ) => dummyWriteStream )
247
+
248
+ fs . existsSync = jest . fn ( )
249
+ fs . existsSync . mockReturnValueOnce ( true )
250
+ fs . existsSync . mockReturnValueOnce ( false )
251
+ fs . mkdirSync = jest . fn ( )
252
+
253
+ findStorage . findStorage = jest . fn ( )
254
+ findStorage . findStorage . mockReturnValue ( dummyStorage )
255
+ uniqueSlug . mockReturnValue ( 'dummyPath' )
256
+
257
+ const sourcePath = {
258
+ sourceFilePath : 'http://www.foo.bar/baz/qux?h=1080' ,
259
+ type : 'base64' ,
260
+ data : 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
261
+ }
262
+
263
+ return systemUnderTest . copyAttachment ( sourcePath , 'storageKey' , 'noteKey' ) . then (
264
+ function ( newFileName ) {
265
+ expect ( newFileName ) . toBe ( 'dummyPath.png' )
266
+ } )
267
+ } )
268
+
129
269
it ( 'should replace the all ":storage" path with the actual storage path' , function ( ) {
130
270
const storageFolder = systemUnderTest . DESTINATION_FOLDER
131
271
const noteKey = '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c'
0 commit comments