11import type { TestContext } from '../_Types.js' ;
2- import { objectsUtils as utils } from '@iobroker/db-objects-redis' ;
32
43export function register ( it : Mocha . TestFunction , expect : Chai . ExpectStatic , context : TestContext ) : void {
54 const testName = `${ context . name } ${ context . adapterShortName } files: ` ;
@@ -10,7 +9,7 @@ export function register(it: Mocha.TestFunction, expect: Chai.ExpectStatic, cont
109 const fileName = 'testFile.bin' ;
1110 const dataBinary = Buffer . from ( '1234' ) ;
1211 // create an object of type file first
13- await context . adapter . setForeignObjectAsync ( objId , {
12+ await context . adapter . setForeignObject ( objId , {
1413 type : 'meta' ,
1514 common : {
1615 name : 'Files and more' ,
@@ -224,12 +223,42 @@ export function register(it: Mocha.TestFunction, expect: Chai.ExpectStatic, cont
224223 } ) ;
225224 } ) ;
226225
227- it ( `${ testName } should respond with 'ERROR_NOT_FOUND' if calling readDir on a single file` , async ( ) => {
226+ it ( `${ testName } should read empty directory` , async ( ) => {
227+ const objects = context . objects ;
228+ const id = `${ testId } .meta.files` ;
229+
230+ await objects . setObject ( id , {
231+ type : 'meta' ,
232+ common : { name : 'test' , type : 'meta.user' } ,
233+ native : { } ,
234+ } ) ;
235+
236+ const res = await objects . readDirAsync ( id , '' ) ;
237+ expect ( res ) . to . be . empty ;
238+ } ) ;
239+
240+ it ( `${ testName } should read empty directory with path` , async ( ) => {
241+ const objects = context . objects ;
242+ const id = `${ testId } .meta.files` ;
243+
244+ const res = await objects . readDirAsync ( id , 'random/path' ) ;
245+ expect ( res ) . to . be . empty ;
246+ } ) ;
247+
248+ it ( `${ testName } should not read directory without meta object` , ( ) => {
249+ const objects = context . objects ;
250+ const id = `${ testId } .meta.nonExisting` ;
251+
252+ expect ( objects . readDirAsync ( id , '' ) ) . to . be . eventually . rejectedWith ( `${ id } is not an object of type "meta"` ) ;
253+ } ) ;
254+
255+ it ( `${ testName } should respond with empty array if calling readDir on a single file` , async ( ) => {
228256 const objects = context . objects ;
229257 const fileName = 'dir/notADir.txt' ;
230258
231259 await objects . writeFileAsync ( testId , fileName , 'dataInFile' ) ;
232- expect ( objects . readDirAsync ( testId , fileName ) ) . to . be . eventually . rejectedWith ( utils . ERRORS . ERROR_NOT_FOUND ) ;
260+ const res = await objects . readDirAsync ( testId , fileName ) ;
261+ expect ( res ) . to . be . empty ;
233262 } ) ;
234263
235264 it ( `${ testName } should read file and prevent path traversing` , done => {
0 commit comments