2024-06-18 16:44:58 +00:00
|
|
|
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
2024-11-24 01:25:08 +00:00
|
|
|
import { jestExpect } from '@push.rocks/tapbundle/node';
|
2024-06-18 16:44:58 +00:00
|
|
|
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({
|
2024-11-24 01:25:08 +00:00
|
|
|
accessKey: await testQenv.getEnvVarOnDemandStrict('S3_ACCESSKEY'),
|
|
|
|
accessSecret: await testQenv.getEnvVarOnDemandStrict('S3_ACCESSSECRET'),
|
|
|
|
endpoint: await testQenv.getEnvVarOnDemandStrict('S3_ENDPOINT'),
|
2024-06-18 16:44:58 +00:00
|
|
|
});
|
|
|
|
expect(testSmartbucket).toBeInstanceOf(smartbucket.SmartBucket);
|
2024-11-24 01:25:08 +00:00
|
|
|
myBucket = await testSmartbucket.getBucketByNameStrict(await testQenv.getEnvVarOnDemandStrict('S3_BUCKET'),);
|
2024-06-18 16:44:58 +00:00
|
|
|
expect(myBucket).toBeInstanceOf(smartbucket.Bucket);
|
2024-11-24 01:25:08 +00:00
|
|
|
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);
|
2024-06-18 16:44:58 +00:00
|
|
|
});
|
|
|
|
|
2024-11-18 21:08:39 +00:00
|
|
|
tap.test('should put a file into the trash', async () => {
|
2024-11-24 01:25:08 +00:00
|
|
|
const path = 'trashtest/trashme.txt';
|
2024-11-18 21:08:39 +00:00
|
|
|
const file = await myBucket.fastPut({
|
|
|
|
path,
|
2024-11-24 01:25:08 +00:00
|
|
|
contents: 'I\'m in the trash test content!',
|
2024-11-18 21:08:39 +00:00
|
|
|
});
|
2024-11-24 01:25:08 +00:00
|
|
|
const fileMetadata = await (await file.getMetaData()).metadataFile.getContents();
|
|
|
|
console.log(fileMetadata.toString());
|
2024-11-18 21:08:39 +00:00
|
|
|
expect(await file.getMetaData().then((meta) => meta.metadataFile.getJsonData())).toEqual({});
|
|
|
|
await file.delete({ mode: 'trash' });
|
2024-11-24 01:25:08 +00:00
|
|
|
jestExpect(await file.getMetaData().then((meta) => meta.metadataFile.getJsonData())).toEqual({
|
2024-11-18 21:08:39 +00:00
|
|
|
custom_recycle: {
|
2024-11-24 01:25:08 +00:00
|
|
|
deletedAt: jestExpect.any(Number),
|
|
|
|
originalPath: "trashtest/trashme.txt",
|
2024-11-18 21:08:39 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2024-11-18 10:24:11 +00:00
|
|
|
|
2024-11-18 21:08:39 +00:00
|
|
|
export default tap.start();
|