2024-06-18 16:44:58 +00:00
|
|
|
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
|
|
|
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.getEnvVarOnDemand('S3_KEY'),
|
|
|
|
accessSecret: await testQenv.getEnvVarOnDemand('S3_SECRET'),
|
2024-07-04 16:39:27 +00:00
|
|
|
endpoint: await testQenv.getEnvVarOnDemand('S3_ENDPOINT'),
|
2024-06-18 16:44:58 +00:00
|
|
|
});
|
|
|
|
expect(testSmartbucket).toBeInstanceOf(smartbucket.SmartBucket);
|
|
|
|
myBucket = await testSmartbucket.getBucketByName('testzone');
|
|
|
|
expect(myBucket).toBeInstanceOf(smartbucket.Bucket);
|
|
|
|
expect(myBucket.name).toEqual('testzone');
|
|
|
|
});
|
|
|
|
|
2024-11-18 21:08:39 +00:00
|
|
|
tap.test('should put a file into the trash', async () => {
|
|
|
|
const path = 'hithere/socool.txt';
|
|
|
|
const file = await myBucket.fastPut({
|
|
|
|
path,
|
|
|
|
contents: 'hi there!',
|
|
|
|
});
|
|
|
|
expect(await file.getMetaData().then((meta) => meta.metadataFile.getJsonData())).toEqual({});
|
|
|
|
await file.delete({ mode: 'trash' });
|
|
|
|
expect(await file.getMetaData().then((meta) => meta.metadataFile.getJsonData())).toEqual({
|
|
|
|
custom_recycle: {
|
|
|
|
deletedAt: 123,
|
|
|
|
originalPath: 'hithere/socool.txt',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2024-11-18 10:24:11 +00:00
|
|
|
|
2024-11-18 21:08:39 +00:00
|
|
|
export default tap.start();
|