@@ -2,11 +2,11 @@ import { Paginated, OutputEntity } from 'filesrocket'
22import { resolve } from 'path'
33
44import {
5- uploadFile ,
6- uploadManyFiles ,
7- getFiles ,
8- deleteOneFile ,
9- deleteManyFiles
5+ uploadOne ,
6+ uploadMany ,
7+ findOne ,
8+ find ,
9+ remove
1010} from './helpers/file.helper'
1111
1212jest . mock ( 'filesrocket' )
@@ -34,59 +34,81 @@ describe('Uploading files', () => {
3434 const path : string = `test/fixtures/${ name } `
3535
3636 test ( 'Upload many files' , async ( ) => {
37- const results = await uploadManyFiles ( paths )
37+ const results = await uploadMany ( paths )
3838 expect ( results ) . toHaveLength ( paths . length )
3939 } )
4040
4141 test ( 'Upload single file' , async ( ) => {
42- const entity = await uploadFile ( path )
42+ const entity = await uploadOne ( path )
4343 expect ( typeof entity ) . toBe ( 'object' )
4444 expect ( entity . name ) . toBe ( name )
4545 } )
4646
4747 test ( 'Upload many files in a directory' , async ( ) => {
48- const items = await uploadManyFiles ( paths , { path : DIRECTORY_NAME } )
48+ const items = await uploadMany ( paths , { path : DIRECTORY_NAME } )
4949 expect ( items ) . toHaveLength ( FILESNAMES . length )
5050 } )
5151} )
5252
5353describe ( 'Getting files' , ( ) => {
5454 test ( 'Gets 3 files' , async ( ) => {
5555 const SIZE : number = 3
56- const data : Paginated < OutputEntity > = await getFiles ( { size : SIZE } )
56+
57+ const data : Paginated < OutputEntity > = await find ( { size : SIZE } )
58+
5759 expect ( data . items ) . toHaveLength ( SIZE )
5860 } )
5961
6062 test ( 'Get files from a directory' , async ( ) => {
61- const data = await getFiles ( { path : DIRECTORY_NAME } )
63+ const data = await find ( { path : DIRECTORY_NAME } )
64+
6265 expect ( data . items ) . toHaveLength ( FILESNAMES . length )
6366 } )
67+
68+ test ( 'Get one file' , async ( ) => {
69+ const data = await find ( { size : 1 } )
70+
71+ const entity = data . items . at ( 0 )
72+
73+ const file = await findOne ( entity ?. id || '' )
74+
75+ expect ( file ) . toBeTruthy ( )
76+ expect ( file . name ) . toBe ( entity ?. name )
77+ } )
78+
79+ test ( 'Get file does not exist' , async ( ) => {
80+ await expect ( findOne ( 'random.jpg' ) )
81+ . rejects
82+ . toThrowError ( 'File does not exist' )
83+ } )
6484} )
6585
6686describe ( 'Deleting files' , ( ) => {
6787 test ( 'Delete 1 file' , async ( ) => {
68- const data : Paginated < OutputEntity > = await getFiles ( { size : 1 } )
88+ const data : Paginated < OutputEntity > = await find ( { size : 1 } )
6989 const file : OutputEntity = data . items [ 0 ]
7090
71- const entity : OutputEntity = await deleteOneFile ( file . id )
72- expect ( file . name ) . toBe ( entity . name )
73- } )
91+ const entities : OutputEntity [ ] = await remove ( [ file . id ] )
92+ const entity = entities . at ( 0 )
7493
75- test ( 'Delete many files' , async ( ) => {
76- const data = await getFiles ( )
77-
78- const keys : string [ ] = data . items . map ( item => item . id )
79- const items = await deleteManyFiles ( keys )
80-
81- expect ( items ) . toHaveLength ( data . items . length )
94+ expect ( file . name ) . toBe ( entity ?. name )
8295 } )
8396
8497 test ( 'Delete files from a directory' , async ( ) => {
85- const data = await getFiles ( { path : DIRECTORY_NAME } )
98+ const data = await find ( { path : DIRECTORY_NAME } )
8699
87100 const keys : string [ ] = data . items . map ( item => item . Key )
88- const items = await deleteManyFiles ( keys )
101+ const items = await remove ( keys )
89102
90103 expect ( items ) . toHaveLength ( keys . length )
91104 } )
105+
106+ test ( 'Delete many files' , async ( ) => {
107+ const data = await find ( )
108+
109+ const keys : string [ ] = data . items . map ( item => item . id )
110+ const items = await remove ( keys )
111+
112+ expect ( items ) . toHaveLength ( data . items . length )
113+ } )
92114} )
0 commit comments