mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 18:18:56 +00:00
120 lines
2.6 KiB
JavaScript
120 lines
2.6 KiB
JavaScript
import {createMockImport} from 'mock-import';
|
|
import fs from 'node:fs';
|
|
import test from 'supertape';
|
|
import {Volume} from 'memfs';
|
|
import {ufs} from 'unionfs';
|
|
import serveOnce from 'serve-once';
|
|
|
|
const {
|
|
stopAll,
|
|
mockImport,
|
|
reImport,
|
|
} = createMockImport(import.meta.url);
|
|
|
|
const dir = `../../server/`;
|
|
const cloudcmdPath = `${dir}cloudcmd.mjs`;
|
|
const restPath = `${dir}rest/index.js`;
|
|
|
|
const {assign} = Object;
|
|
|
|
test('cloudcmd: rest: move', async (t) => {
|
|
const volume = {
|
|
'/fixture/move.txt': 'hello',
|
|
'/fixture/tmp/a.txt': 'a',
|
|
};
|
|
|
|
const vol = Volume.fromJSON(volume, '/');
|
|
|
|
const unionFS = ufs
|
|
.use(vol)
|
|
.use(fs);
|
|
|
|
assign(unionFS, {
|
|
promises: fs.promises,
|
|
});
|
|
|
|
mockImport('fs', unionFS);
|
|
|
|
await reImport('@cloudcmd/rename-files');
|
|
await reImport('@cloudcmd/move-files');
|
|
await reImport(restPath);
|
|
|
|
const {
|
|
cloudcmd,
|
|
createConfigManager,
|
|
} = await reImport(cloudcmdPath);
|
|
|
|
const configManager = createConfigManager();
|
|
configManager('auth', false);
|
|
configManager('root', '/');
|
|
|
|
const {request} = serveOnce(cloudcmd, {
|
|
configManager,
|
|
});
|
|
|
|
const files = {
|
|
from: '/fixture/',
|
|
to: '/fixture/tmp/',
|
|
names: ['move.txt'],
|
|
};
|
|
|
|
const {body} = await request.put(`/api/v1/move`, {
|
|
body: files,
|
|
});
|
|
|
|
stopAll();
|
|
|
|
t.equal(body, 'move: ok("["move.txt"]")', 'should move');
|
|
t.end();
|
|
});
|
|
|
|
test('cloudcmd: rest: move: no from', async (t) => {
|
|
const {cloudcmd} = await reImport(cloudcmdPath);
|
|
|
|
const {createConfigManager} = cloudcmd;
|
|
|
|
const configManager = createConfigManager();
|
|
configManager('auth', false);
|
|
configManager('root', '/');
|
|
|
|
const {request} = serveOnce(cloudcmd, {
|
|
configManager,
|
|
});
|
|
|
|
const files = {};
|
|
|
|
const {body} = await request.put(`/api/v1/move`, {
|
|
body: files,
|
|
});
|
|
|
|
const expected = '"from" should be filled';
|
|
|
|
t.equal(body, expected);
|
|
t.end();
|
|
});
|
|
|
|
test('cloudcmd: rest: move: no to', async (t) => {
|
|
const {cloudcmd} = await reImport(cloudcmdPath);
|
|
const {createConfigManager} = cloudcmd;
|
|
|
|
const configManager = createConfigManager();
|
|
configManager('auth', false);
|
|
configManager('root', '/');
|
|
|
|
const {request} = serveOnce(cloudcmd, {
|
|
configManager,
|
|
});
|
|
|
|
const files = {
|
|
from: '/',
|
|
};
|
|
|
|
const {body} = await request.put(`/api/v1/move`, {
|
|
body: files,
|
|
});
|
|
|
|
const expected = '"to" should be filled';
|
|
|
|
t.equal(body, expected);
|
|
t.end();
|
|
});
|