test: client: dom: io: get rid of mock-require

This commit is contained in:
coderiaser 2026-01-12 21:40:54 +02:00
parent 5c1ad5f8ff
commit 14452d05b6
2 changed files with 23 additions and 25 deletions

View file

@ -1,14 +1,14 @@
'use strict'; 'use strict';
const {FS} = require('../../../common/cloudfunc'); const {FS} = require('../../../common/cloudfunc');
const sendRequest = require('./send-request'); const _sendRequest = require('./send-request');
const imgPosition = { const imgPosition = {
top: true, top: true,
}; };
module.exports.delete = async (url, data) => { module.exports.delete = async (url, data) => {
return await sendRequest({ return await _sendRequest({
method: 'DELETE', method: 'DELETE',
url: FS + url, url: FS + url,
data, data,
@ -19,7 +19,7 @@ module.exports.delete = async (url, data) => {
}; };
module.exports.patch = async (url, data) => { module.exports.patch = async (url, data) => {
return await sendRequest({ return await _sendRequest({
method: 'PATCH', method: 'PATCH',
url: FS + url, url: FS + url,
data, data,
@ -28,7 +28,7 @@ module.exports.patch = async (url, data) => {
}; };
module.exports.write = async (url, data) => { module.exports.write = async (url, data) => {
return await sendRequest({ return await _sendRequest({
method: 'PUT', method: 'PUT',
url: FS + url, url: FS + url,
data, data,
@ -36,7 +36,11 @@ module.exports.write = async (url, data) => {
}); });
}; };
module.exports.createDirectory = async (url) => { module.exports.createDirectory = async (url, overrides = {}) => {
const {
sendRequest = _sendRequest,
} = overrides;
return await sendRequest({ return await sendRequest({
method: 'PUT', method: 'PUT',
url: `${FS}${url}?dir`, url: `${FS}${url}?dir`,
@ -47,7 +51,7 @@ module.exports.createDirectory = async (url) => {
module.exports.read = async (url, dataType = 'text') => { module.exports.read = async (url, dataType = 'text') => {
const notLog = !url.includes('?'); const notLog = !url.includes('?');
return await sendRequest({ return await _sendRequest({
method: 'GET', method: 'GET',
url: FS + url, url: FS + url,
notLog, notLog,
@ -56,7 +60,7 @@ module.exports.read = async (url, dataType = 'text') => {
}; };
module.exports.copy = async (from, to, names) => { module.exports.copy = async (from, to, names) => {
return await sendRequest({ return await _sendRequest({
method: 'PUT', method: 'PUT',
url: '/copy', url: '/copy',
data: { data: {
@ -69,7 +73,7 @@ module.exports.copy = async (from, to, names) => {
}; };
module.exports.pack = async (data) => { module.exports.pack = async (data) => {
return await sendRequest({ return await _sendRequest({
method: 'PUT', method: 'PUT',
url: '/pack', url: '/pack',
data, data,
@ -77,7 +81,7 @@ module.exports.pack = async (data) => {
}; };
module.exports.extract = async (data) => { module.exports.extract = async (data) => {
return await sendRequest({ return await _sendRequest({
method: 'PUT', method: 'PUT',
url: '/extract', url: '/extract',
data, data,
@ -85,7 +89,7 @@ module.exports.extract = async (data) => {
}; };
module.exports.move = async (from, to, names) => { module.exports.move = async (from, to, names) => {
return await sendRequest({ return await _sendRequest({
method: 'PUT', method: 'PUT',
url: '/move', url: '/move',
data: { data: {
@ -98,7 +102,7 @@ module.exports.move = async (from, to, names) => {
}; };
module.exports.rename = async (from, to) => { module.exports.rename = async (from, to) => {
return await sendRequest({ return await _sendRequest({
method: 'PUT', method: 'PUT',
url: '/rename', url: '/rename',
data: { data: {
@ -111,7 +115,7 @@ module.exports.rename = async (from, to) => {
module.exports.Config = { module.exports.Config = {
read: async () => { read: async () => {
return await sendRequest({ return await _sendRequest({
method: 'GET', method: 'GET',
url: '/config', url: '/config',
imgPosition, imgPosition,
@ -120,7 +124,7 @@ module.exports.Config = {
}, },
write: async (data) => { write: async (data) => {
return await sendRequest({ return await _sendRequest({
method: 'PATCH', method: 'PATCH',
url: '/config', url: '/config',
data, data,
@ -131,7 +135,7 @@ module.exports.Config = {
module.exports.Markdown = { module.exports.Markdown = {
read: async (url) => { read: async (url) => {
return await sendRequest({ return await _sendRequest({
method: 'GET', method: 'GET',
url: `/markdown${url}`, url: `/markdown${url}`,
imgPosition, imgPosition,
@ -140,7 +144,7 @@ module.exports.Markdown = {
}, },
render: async (data) => { render: async (data) => {
return await sendRequest({ return await _sendRequest({
method: 'PUT', method: 'PUT',
url: '/markdown', url: '/markdown',
data, data,

View file

@ -1,18 +1,14 @@
'use strict'; 'use strict';
const {test, stub} = require('supertape'); const {test, stub} = require('supertape');
const io = require('.');
const mockRequire = require('mock-require');
const {reRequire, stopAll} = mockRequire;
test('client: dom: io', (t) => { test('client: dom: io', (t) => {
const sendRequest = stub(); const sendRequest = stub();
mockRequire('./send-request', sendRequest);
const io = reRequire('.'); io.createDirectory('/hello', {
sendRequest,
io.createDirectory('/hello'); });
const expected = { const expected = {
imgPosition: { imgPosition: {
@ -22,8 +18,6 @@ test('client: dom: io', (t) => {
url: '/fs/hello?dir', url: '/fs/hello?dir',
}; };
stopAll();
t.calledWith(sendRequest, [expected]); t.calledWith(sendRequest, [expected]);
t.end(); t.end();
}); });