diff --git a/client/dom/io/index.mjs b/client/dom/io/index.mjs index b0c55e0a..d46c78f0 100644 --- a/client/dom/io/index.mjs +++ b/client/dom/io/index.mjs @@ -1,19 +1,32 @@ import {FS} from '#common/cloudfunc'; import {sendRequest as _sendRequest} from './send-request.mjs'; +const {assign} = Object; + const imgPosition = { top: true, }; -export const remove = async (url, data) => { - return await _sendRequest({ +export const remove = async (url, data, overrides = {}) => { + const { + sendRequest = _sendRequest, + } = overrides; + + const request = { method: 'DELETE', url: FS + url, - data, imgPosition: { top: Boolean(data), }, - }); + }; + + if (data) + assign(request, { + data, + url: `${request.url}?files`, + }); + + return await sendRequest(request); }; export const patch = async (url, data) => { diff --git a/client/dom/io/index.spec.mjs b/client/dom/io/index.spec.mjs index ec2f0dfc..e7d87cc2 100644 --- a/client/dom/io/index.spec.mjs +++ b/client/dom/io/index.spec.mjs @@ -19,3 +19,43 @@ test('client: dom: io', (t) => { t.calledWith(sendRequest, [expected]); t.end(); }); + +test('client: dom: io: remove: no files', async (t) => { + const sendRequest = stub(); + + await io.remove('/hello', null, { + sendRequest, + }); + + const expected = { + imgPosition: { + top: false, + }, + method: 'DELETE', + url: '/fs/hello', + }; + + t.calledWith(sendRequest, [expected]); + t.end(); +}); + +test('client: dom: io: remove: files', async (t) => { + const sendRequest = stub(); + const files = ['world']; + + await io.remove('/hello', files, { + sendRequest, + }); + + const expected = { + imgPosition: { + top: true, + }, + data: ['world'], + method: 'DELETE', + url: '/fs/hello?files', + }; + + t.calledWith(sendRequest, [expected]); + t.end(); +}); diff --git a/package.json b/package.json index d9ce8f67..bf18523c 100644 --- a/package.json +++ b/package.json @@ -160,7 +160,7 @@ "@cloudcmd/stub": "^5.0.0", "@iocmd/wait": "^2.1.0", "@putout/eslint-flat": "^4.0.0", - "@putout/plugin-cloudcmd": "^5.0.0", + "@putout/plugin-cloudcmd": "^5.2.0", "@types/node-fetch": "^2.6.11", "auto-globals": "^4.0.0", "babel-loader": "^10.0.0",