import { expect, expectAsync, tap } from '@push.rocks/tapbundle'; import { jestExpect } from '@push.rocks/tapbundle/node'; import { Qenv } from '@push.rocks/qenv'; import * as smartbucket from '../ts/index.js'; const testQenv = new Qenv('./', './.nogit/'); let testSmartbucket: smartbucket.SmartBucket; let myBucket: smartbucket.Bucket; let baseDirectory: smartbucket.Directory; tap.test('should create a valid smartbucket', async () => { testSmartbucket = new smartbucket.SmartBucket({ accessKey: await testQenv.getEnvVarOnDemandStrict('S3_ACCESSKEY'), accessSecret: await testQenv.getEnvVarOnDemandStrict('S3_ACCESSSECRET'), endpoint: await testQenv.getEnvVarOnDemandStrict('S3_ENDPOINT'), }); expect(testSmartbucket).toBeInstanceOf(smartbucket.SmartBucket); myBucket = await testSmartbucket.getBucketByNameStrict(await testQenv.getEnvVarOnDemandStrict('S3_BUCKET'),); expect(myBucket).toBeInstanceOf(smartbucket.Bucket); expect(myBucket.name).toEqual('test-pushrocks-smartbucket'); }); tap.test('should clean all contents', async () => { await myBucket.cleanAllContents(); expect(await myBucket.fastExists({ path: 'hithere/socool.txt' })).toBeFalse(); expect(await myBucket.fastExists({ path: 'trashtest/trashme.txt' })).toBeFalse(); }); tap.test('should delete a file into the normally', async () => { const path = 'trashtest/trashme.txt'; const file = await myBucket.fastPut({ path, contents: 'I\'m in the trash test content!', }); const fileMetadata = await (await file.getMetaData()).metadataFile.getContents(); console.log(fileMetadata.toString()); expect(await file.getMetaData().then((meta) => meta.metadataFile.getJsonData())).toEqual({}); await file.delete({ mode: 'permanent' }); expect((await (await myBucket.getBaseDirectory()).listFiles()).length).toEqual(0); expect((await (await myBucket.getBaseDirectory()).listDirectories()).length).toEqual(0); }); tap.test('should put a file into the trash', async () => { const path = 'trashtest/trashme.txt'; const file = await myBucket.fastPut({ path, contents: 'I\'m in the trash test content!', }); const fileMetadata = await (await file.getMetaData()).metadataFile.getContents(); console.log(fileMetadata.toString()); expect(await file.getMetaData().then((meta) => meta.metadataFile.getJsonData())).toEqual({}); await file.delete({ mode: 'trash' }); jestExpect(await file.getMetaData().then((meta) => meta.metadataFile.getJsonData())).toEqual({ custom_recycle: { deletedAt: jestExpect.any(Number), originalPath: "trashtest/trashme.txt", }, }); }); export default tap.start();