@@ -217,7 +217,9 @@ describe('Directus Node', () => {
217217 . mockReturnValueOnce ( 'user' )
218218 . mockReturnValueOnce ( 'update' )
219219 . mockReturnValueOnce ( 'user-1' )
220- . mockReturnValueOnce ( { fields :
{ field :
[ { name :
'email' , value :
'[email protected] ' } ] } } ) ; 220+ . mockReturnValueOnce ( {
221+ fields :
{ field :
[ { name :
'email' , value :
'[email protected] ' } ] } , 222+ } ) ;
221223
222224 mockExecuteFunctions . helpers . httpRequest . mockResolvedValue ( {
223225 data :
{ id :
'user-1' , email :
'[email protected] ' } , @@ -244,74 +246,74 @@ describe('Directus Node', () => {
244246
245247 describe ( 'File Operations' , ( ) => {
246248 it ( 'should handle file upload operations' , async ( ) => {
247- mockExecuteFunctions . getNodeParameter
248- . mockReturnValueOnce ( 'file' )
249- . mockReturnValueOnce ( 'upload' ) ;
250-
251- const mockBinaryData = {
252- file : {
253- data : Buffer . from ( 'test file content' ) . toString ( 'base64' ) ,
249+ mockExecuteFunctions . getNodeParameter
250+ . mockReturnValueOnce ( 'file' )
251+ . mockReturnValueOnce ( 'upload' ) ;
252+
253+ const mockBinaryData = {
254+ file : {
255+ data : Buffer . from ( 'test file content' ) . toString ( 'base64' ) ,
256+ fileName : 'test.txt' ,
257+ mimeType : 'text/plain' ,
258+ } ,
259+ } ;
260+ mockExecuteFunctions . getInputData . mockReturnValue ( [ { binary : mockBinaryData } ] ) ;
261+ mockExecuteFunctions . helpers . assertBinaryData . mockReturnValue ( {
254262 fileName : 'test.txt' ,
255263 mimeType : 'text/plain' ,
256- } ,
257- } ;
258- mockExecuteFunctions . getInputData . mockReturnValue ( [ { binary : mockBinaryData } ] ) ;
259- mockExecuteFunctions . helpers . assertBinaryData . mockReturnValue ( {
260- fileName : 'test.txt' ,
261- mimeType : 'text/plain' ,
262- } ) ;
263- mockExecuteFunctions . helpers . getBinaryDataBuffer . mockResolvedValue (
264- Buffer . from ( 'test file content' ) ,
265- ) ;
266- mockExecuteFunctions . helpers . request = vi . fn ( ) . mockResolvedValue ( {
267- data : { id : 'file-1' , filename_download : 'test.txt' } ,
264+ } ) ;
265+ mockExecuteFunctions . helpers . getBinaryDataBuffer . mockResolvedValue (
266+ Buffer . from ( 'test file content' ) ,
267+ ) ;
268+ mockExecuteFunctions . helpers . request = vi . fn ( ) . mockResolvedValue ( {
269+ data : { id : 'file-1' , filename_download : 'test.txt' } ,
270+ } ) ;
271+
272+ const result = await node . execute . call ( mockExecuteFunctions ) ;
273+
274+ expect ( result [ 0 ] [ 0 ] . json ) . toHaveProperty ( 'id' , 'file-1' ) ;
275+ expect ( mockExecuteFunctions . helpers . request ) . toHaveBeenCalled ( ) ;
268276 } ) ;
269277
270- const result = await node . execute . call ( mockExecuteFunctions ) ;
278+ it ( 'should handle file import operations' , async ( ) => {
279+ mockExecuteFunctions . getNodeParameter
280+ . mockReturnValueOnce ( 'file' )
281+ . mockReturnValueOnce ( 'import' )
282+ . mockReturnValueOnce ( 'https://example.com/image.jpg' ) ;
271283
272- expect ( result [ 0 ] [ 0 ] . json ) . toHaveProperty ( 'id' , 'file-1' ) ;
273- expect ( mockExecuteFunctions . helpers . request ) . toHaveBeenCalled ( ) ;
274- } ) ;
284+ mockExecuteFunctions . helpers . httpRequest . mockResolvedValue ( {
285+ data : { id : 'file-2' , filename_download : 'image.jpg' } ,
286+ } ) ;
275287
276- it ( 'should handle file import operations' , async ( ) => {
277- mockExecuteFunctions . getNodeParameter
278- . mockReturnValueOnce ( 'file' )
279- . mockReturnValueOnce ( 'import' )
280- . mockReturnValueOnce ( 'https://example.com/image.jpg' ) ;
288+ const result = await node . execute . call ( mockExecuteFunctions ) ;
281289
282- mockExecuteFunctions . helpers . httpRequest . mockResolvedValue ( {
283- data : { id : 'file-2' , filename_download : 'image.jpg' } ,
290+ expect ( result [ 0 ] [ 0 ] . json ) . toHaveProperty ( 'id' , 'file-2' ) ;
284291 } ) ;
285292
286- const result = await node . execute . call ( mockExecuteFunctions ) ;
293+ it ( 'should handle file get operations' , async ( ) => {
294+ mockExecuteFunctions . getNodeParameter
295+ . mockReturnValueOnce ( 'file' )
296+ . mockReturnValueOnce ( 'get' )
297+ . mockReturnValueOnce ( 'file-3' ) ;
287298
288- expect ( result [ 0 ] [ 0 ] . json ) . toHaveProperty ( 'id' , 'file-2' ) ;
289- } ) ;
299+ mockExecuteFunctions . helpers . httpRequest . mockResolvedValue ( {
300+ data : { id : 'file-3' , filename_download : 'document.pdf' } ,
301+ } ) ;
290302
291- it ( 'should handle file get operations' , async ( ) => {
292- mockExecuteFunctions . getNodeParameter
293- . mockReturnValueOnce ( 'file' )
294- . mockReturnValueOnce ( 'get' )
295- . mockReturnValueOnce ( 'file-3' ) ;
303+ const result = await node . execute . call ( mockExecuteFunctions ) ;
296304
297- mockExecuteFunctions . helpers . httpRequest . mockResolvedValue ( {
298- data : { id : 'file-3' , filename_download : 'document.pdf' } ,
305+ expect ( result [ 0 ] [ 0 ] . json ) . toHaveProperty ( 'id' , 'file-3' ) ;
299306 } ) ;
300307
301- const result = await node . execute . call ( mockExecuteFunctions ) ;
302-
303- expect ( result [ 0 ] [ 0 ] . json ) . toHaveProperty ( 'id' , 'file-3' ) ;
304- } ) ;
305-
306- it ( 'should handle file delete operations' , async ( ) => {
307- mockExecuteFunctions . getNodeParameter
308- . mockReturnValueOnce ( 'file' )
309- . mockReturnValueOnce ( 'delete' )
310- . mockReturnValueOnce ( 'file-4' ) ;
308+ it ( 'should handle file delete operations' , async ( ) => {
309+ mockExecuteFunctions . getNodeParameter
310+ . mockReturnValueOnce ( 'file' )
311+ . mockReturnValueOnce ( 'delete' )
312+ . mockReturnValueOnce ( 'file-4' ) ;
311313
312- mockExecuteFunctions . helpers . httpRequest . mockResolvedValue ( { } ) ;
314+ mockExecuteFunctions . helpers . httpRequest . mockResolvedValue ( { } ) ;
313315
314- const result = await node . execute . call ( mockExecuteFunctions ) ;
316+ const result = await node . execute . call ( mockExecuteFunctions ) ;
315317
316318 expect ( result [ 0 ] [ 0 ] . json ) . toEqual ( { deleted : true , id : 'file-4' } ) ;
317319 } ) ;
0 commit comments