Skip to content

Commit e3fc958

Browse files
committed
chore: test
1 parent dd09559 commit e3fc958

1 file changed

Lines changed: 49 additions & 2 deletions

File tree

backend/src/test/restful/file.spec.js

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ function createRouteApp() {
4242
return app;
4343
}
4444

45-
function getHandler(pattern) {
45+
function getHandler(pattern, method = 'GET') {
4646
const app = createRouteApp();
4747
registerFileRoutes(app);
48-
return app.handlers.get(`GET ${pattern}`);
48+
return app.handlers.get(`${method.toUpperCase()} ${pattern}`);
4949
}
5050

5151
function createResponse(routePath) {
@@ -104,6 +104,26 @@ async function requestFile(query = {}, { name = 'local-file' } = {}) {
104104
return res;
105105
}
106106

107+
async function updateFile(data, { name = 'local-file' } = {}) {
108+
const handler = getHandler('/api/file/:name', 'PATCH');
109+
const res = createResponse('/api/file/:name');
110+
111+
await handler(
112+
{
113+
body: data,
114+
headers: {},
115+
method: 'PATCH',
116+
params: { name },
117+
path: `/api/file/${name}`,
118+
query: {},
119+
url: `/api/file/${name}`,
120+
},
121+
res,
122+
);
123+
124+
return res;
125+
}
126+
107127
async function requestShareFile({ query = {}, shareToken } = {}) {
108128
const handler = getHandler('/share/file/:name');
109129
const res = createResponse('/share/file/:name');
@@ -184,6 +204,33 @@ describe('file routes', function () {
184204
$.notify = () => {};
185205
});
186206

207+
it('preserves Add Proxies From Subscription Operator settings when updating a file', async function () {
208+
const process = [
209+
{
210+
id: 'add-proxies-action',
211+
type: 'Add Proxies From Subscription Operator',
212+
args: {
213+
sourceType: 'collection',
214+
sourceName: 'collection-a',
215+
includeUnsupportedProxy: true,
216+
position: 'front',
217+
},
218+
customName: 'add collection nodes',
219+
disabled: true,
220+
},
221+
];
222+
223+
const res = await updateFile({
224+
type: 'mihomoConfig',
225+
sourceType: 'none',
226+
process,
227+
});
228+
229+
expect(res.statusCode).to.equal(200);
230+
expect(res.sent.data.process).to.deep.equal(process);
231+
expect(state[FILES_KEY][0].process).to.deep.equal(process);
232+
});
233+
187234
it('passes Script Operator $options changes to response transformers', async function () {
188235
state[FILES_KEY][0].process = [
189236
{

0 commit comments

Comments
 (0)