mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-31 15:45:23 +00:00
fix: send plugin form uploads to the plugin's route (Support#1406, Support#1420)
This commit is contained in:
1 parent
db8305e393
commit
f783e6d51d
2 files changed
+29
-3
No files matched your search
@@ -61,7 +61,10 @@ export function createPluginApi(pluginId: string): AxiosInstance {
|
|||||||
property === "options" ||
|
property === "options" ||
|
||||||
property === "post" ||
|
property === "post" ||
|
||||||
property === "put" ||
|
property === "put" ||
|
||||||
property === "patch"
|
property === "patch" ||
|
||||||
|
property === "postForm" ||
|
||||||
|
property === "putForm" ||
|
||||||
|
property === "patchForm"
|
||||||
) {
|
) {
|
||||||
return (url: string, ...rest: unknown[]) =>
|
return (url: string, ...rest: unknown[]) =>
|
||||||
(value as (...args: unknown[]) => unknown).call(
|
(value as (...args: unknown[]) => unknown).call(
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
const state = vi.hoisted(() => ({ electron: false }));
|
const state = vi.hoisted(() => ({ electron: false }));
|
||||||
|
const axiosMethods = vi.hoisted(() => ({
|
||||||
|
get: vi.fn(),
|
||||||
|
postForm: vi.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
vi.mock("@/main-axios", () => ({
|
vi.mock("@/main-axios", () => ({
|
||||||
authApi: { defaults: { baseURL: "http://server:8080/" } },
|
authApi: {
|
||||||
|
defaults: { baseURL: "http://server:8080/" },
|
||||||
|
...axiosMethods,
|
||||||
|
},
|
||||||
createRemoteOriginApiInstance: vi.fn(),
|
createRemoteOriginApiInstance: vi.fn(),
|
||||||
}));
|
}));
|
||||||
vi.mock("@/lib/electron", () => ({ isElectron: () => state.electron }));
|
vi.mock("@/lib/electron", () => ({ isElectron: () => state.electron }));
|
||||||
vi.mock("@/lib/device-id", () => ({ getDeviceId: () => "device-1" }));
|
vi.mock("@/lib/device-id", () => ({ getDeviceId: () => "device-1" }));
|
||||||
|
|
||||||
import { pluginFetch } from "@/lib/plugin-transport";
|
import { createPluginApi, pluginFetch } from "@/lib/plugin-transport";
|
||||||
|
|
||||||
const fetchMock = vi.fn(async () => new Response("ok"));
|
const fetchMock = vi.fn(async () => new Response("ok"));
|
||||||
|
|
||||||
@@ -61,3 +68,19 @@ describe("pluginFetch", () => {
|
|||||||
expect(headers.get("authorization")).toBe("Bearer token-1");
|
expect(headers.get("authorization")).toBe("Bearer token-1");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("createPluginApi", () => {
|
||||||
|
it("puts the plugin's mount point in front of request and form paths", () => {
|
||||||
|
const api = createPluginApi("file-manager");
|
||||||
|
const form = new FormData();
|
||||||
|
api.get("/listFiles");
|
||||||
|
api.postForm("uploadFileStream", form);
|
||||||
|
expect(axiosMethods.get).toHaveBeenCalledWith(
|
||||||
|
"/plugin-api/file-manager/listFiles",
|
||||||
|
);
|
||||||
|
expect(axiosMethods.postForm).toHaveBeenCalledWith(
|
||||||
|
"/plugin-api/file-manager/uploadFileStream",
|
||||||
|
form,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user