43 lines
1.6 KiB
TypeScript
43 lines
1.6 KiB
TypeScript
|
|
import { tap } from '@git.zone/tstest/tapbundle';
|
||
|
|
import * as smartwebdav from '../ts/index.js';
|
||
|
|
|
||
|
|
import * as smartfile from '@push.rocks/smartfile';
|
||
|
|
import * as qenv from '@push.rocks/qenv';
|
||
|
|
|
||
|
|
let webdavClient: smartwebdav.WebdavClient;
|
||
|
|
const testQenv = new qenv.Qenv('./', './.nogit/');
|
||
|
|
|
||
|
|
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 run WebDAV integration flow', async () => {
|
||
|
|
if (process.env.SMARTWEBDAV_RUN_INTEGRATION_TESTS !== 'true') {
|
||
|
|
console.log('Skipping WebDAV integration test. Set SMARTWEBDAV_RUN_INTEGRATION_TESTS=true to run it.');
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
webdavClient = new smartwebdav.WebdavClient({
|
||
|
|
serverUrl: await requireEnv('SERVER_URL'),
|
||
|
|
authType: smartwebdav.authType.Password,
|
||
|
|
password: await requireEnv('SERVER_TOKEN'),
|
||
|
|
});
|
||
|
|
|
||
|
|
const directoryListed = await webdavClient.listDirectory('/testdir');
|
||
|
|
console.log(directoryListed);
|
||
|
|
|
||
|
|
const smartfileFactory = new smartfile.SmartFileFactory(undefined);
|
||
|
|
const smartfile1 = smartfileFactory.fromString('./testdir/so/awesome/hello.txt', 'hello there', 'utf8');
|
||
|
|
const smartfile2 = smartfileFactory.fromString('./testdir/so/awesome/hello2.txt', 'hello there 2', 'utf8');
|
||
|
|
|
||
|
|
await webdavClient.uploadSmartFileArray([smartfile1, smartfile2]);
|
||
|
|
await webdavClient.ensureDirectory('/testdir/another/dirctory');
|
||
|
|
await webdavClient.deleteDirectory('/testdir/another');
|
||
|
|
});
|
||
|
|
|
||
|
|
export default tap.start();
|