feat(core): add provider defaults, strengthen WebDAV validation, and modernize tests and package metadata
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartexpose from '../ts/index.js';
|
||||
|
||||
const testQenv = new qenv.Qenv('./', './.nogit/');
|
||||
|
||||
let testSmartexpose: smartexpose.SmartExpose;
|
||||
|
||||
const shouldRunIntegrationTests = () => process.env.SMARTEXPOSE_RUN_INTEGRATION_TESTS === 'true';
|
||||
|
||||
class TestExposeProvider extends smartexpose.ExposeProvider {
|
||||
public receivedFileOptions: Parameters<smartexpose.ExposeProvider['exposeFile']>[0] | undefined;
|
||||
public receivedFileArrayOptions: Parameters<smartexpose.ExposeProvider['exposeFileArray']>[0] | undefined;
|
||||
|
||||
public async houseKeeping(): Promise<void> {}
|
||||
|
||||
public async exposeFile(optionsArg: Parameters<smartexpose.ExposeProvider['exposeFile']>[0]) {
|
||||
this.receivedFileOptions = optionsArg;
|
||||
return {
|
||||
url: 'https://example.com/test',
|
||||
id: 'test',
|
||||
status: 'created' as const,
|
||||
};
|
||||
}
|
||||
|
||||
public async exposeFileArray(
|
||||
optionsArg: Parameters<smartexpose.ExposeProvider['exposeFileArray']>[0]
|
||||
) {
|
||||
this.receivedFileArrayOptions = optionsArg;
|
||||
return [
|
||||
{
|
||||
url: 'https://example.com/test',
|
||||
id: 'test',
|
||||
status: 'created' as const,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
public async start(): Promise<void> {}
|
||||
|
||||
public async stop(): Promise<void> {}
|
||||
|
||||
public async wipeAll(): Promise<{ id: string; status: 'deleted' | 'failed' | 'notfound' }[]> {
|
||||
return [];
|
||||
}
|
||||
|
||||
public async deleteFileById(
|
||||
idArg: string
|
||||
): Promise<{ id: string; status: 'deleted' | 'failed' | 'notfound' }> {
|
||||
return {
|
||||
id: idArg,
|
||||
status: 'deleted',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const requireEnv = async (envNameArg: string): Promise<string> => {
|
||||
const envValue = await testQenv.getEnvVarOnDemand(envNameArg);
|
||||
if (!envValue) {
|
||||
throw new Error(`Missing required environment variable: ${envNameArg}`);
|
||||
}
|
||||
return envValue;
|
||||
};
|
||||
|
||||
tap.test('should apply constructor defaults when exposing files', async () => {
|
||||
const smartExpose = new smartexpose.SmartExpose({
|
||||
exposedBaseUrl: 'https://example.com/',
|
||||
deleteAfterMillis: 1234,
|
||||
privateUrl: true,
|
||||
});
|
||||
const testProvider = new TestExposeProvider();
|
||||
smartExpose.provider = testProvider;
|
||||
|
||||
const smartfileFactory = new smartfile.SmartFileFactory(undefined);
|
||||
const smartFile = smartfileFactory.fromString('okidoks', 'hi there', 'utf8');
|
||||
|
||||
await smartExpose.exposeFile({ smartFile });
|
||||
expect(testProvider.receivedFileOptions?.deleteAfterMillis).toEqual(1234);
|
||||
expect(testProvider.receivedFileOptions?.privateUrl).toEqual(true);
|
||||
|
||||
await smartExpose.exposeFileArray({ smartFiles: [smartFile] });
|
||||
expect(testProvider.receivedFileArrayOptions?.deleteAfterMillis).toEqual(1234);
|
||||
expect(testProvider.receivedFileArrayOptions?.privateUrl).toEqual(true);
|
||||
});
|
||||
|
||||
tap.test('should create a valid instance of smartexpose using Webdav', async () => {
|
||||
if (!shouldRunIntegrationTests()) {
|
||||
console.log('Skipping SmartExpose integration test. Set SMARTEXPOSE_RUN_INTEGRATION_TESTS=true to run it.');
|
||||
return;
|
||||
}
|
||||
|
||||
testSmartexpose = new smartexpose.SmartExpose({
|
||||
webdav: {
|
||||
webdavCredentials: {
|
||||
serverUrl: await requireEnv('WEBDAV_SERVER_URL'),
|
||||
password: await requireEnv('WEBDAV_SERVER_TOKEN'),
|
||||
},
|
||||
webdavSubPath: await requireEnv('WEBDAV_SUB_PATH'),
|
||||
},
|
||||
deleteAfterMillis: 30000,
|
||||
privateUrl: true,
|
||||
exposedBaseUrl: await requireEnv('EXPOSED_BASE_URL'),
|
||||
});
|
||||
await testSmartexpose.start();
|
||||
expect(testSmartexpose).toBeInstanceOf(smartexpose.SmartExpose);
|
||||
});
|
||||
|
||||
tap.test('should expose a file', async () => {
|
||||
if (!shouldRunIntegrationTests()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const smartfileFactory = new smartfile.SmartFileFactory(undefined);
|
||||
await testSmartexpose.exposeFile({
|
||||
smartFile: smartfileFactory.fromString('okidoks', 'hi there', 'utf8'),
|
||||
deleteAfterMillis: 10000,
|
||||
privateUrl: true,
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should delete the file', async (toolsArg) => {
|
||||
if (!shouldRunIntegrationTests()) {
|
||||
return;
|
||||
}
|
||||
|
||||
await toolsArg.delayFor(11000);
|
||||
});
|
||||
|
||||
tap.test('should stop the smartexpose', async () => {
|
||||
if (!shouldRunIntegrationTests()) {
|
||||
return;
|
||||
}
|
||||
|
||||
await testSmartexpose.stop();
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -1,44 +0,0 @@
|
||||
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
|
||||
const testQenv = new qenv.Qenv('./', './.nogit/');
|
||||
|
||||
import * as smartexpose from '../ts/index.js'
|
||||
|
||||
let testSmartexpose: smartexpose.SmartExpose;
|
||||
|
||||
tap.test('should create a valid instance of smartexpose using Webdav', async () => {
|
||||
testSmartexpose = new smartexpose.SmartExpose({
|
||||
webdav: {
|
||||
webdavCredentials: {
|
||||
serverUrl: await testQenv.getEnvVarOnDemand('WEBDAV_SERVER_URL'),
|
||||
password: await testQenv.getEnvVarOnDemand('WEBDAV_SERVER_TOKEN'),
|
||||
},
|
||||
webdavSubPath: await testQenv.getEnvVarOnDemand('WEBDAV_SUB_PATH'),
|
||||
},
|
||||
deleteAfterMillis: 30000,
|
||||
privateUrl: true,
|
||||
exposedBaseUrl: await testQenv.getEnvVarOnDemand('EXPOSED_BASE_URL'),
|
||||
});
|
||||
await testSmartexpose.start();
|
||||
expect(testSmartexpose).toBeInstanceOf(smartexpose.SmartExpose);
|
||||
});
|
||||
|
||||
tap.test('should expose a file', async () => {
|
||||
await testSmartexpose.exposeFile({
|
||||
smartFile: await smartfile.SmartFile.fromString('okidoks', 'hi there', 'utf8'),
|
||||
deleteAfterMillis: 10000,
|
||||
privateUrl: true,
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should delete the file', async (toolsArg) => {
|
||||
await toolsArg.delayFor(11000);
|
||||
});
|
||||
|
||||
tap.test('should stop the smartexpose', async () => {
|
||||
await testSmartexpose.stop();
|
||||
})
|
||||
|
||||
export default tap.start();
|
||||
Reference in New Issue
Block a user