Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Frontend/test/driver.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { type PathParams } from "msw";
import { DefaultBodyType, StrictRequest, type PathParams } from "msw";

type GoTo = (path: string) => Promise<void>;
type DisposeApp = () => void;

export type Method = "get" | "post" | "patch" | "put" | "delete" | "options";

export type MockEndpointOptions = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
body: Record<string, any> | string | number | boolean | null | undefined;
method?: "get" | "post" | "patch" | "put" | "delete" | "options";
method?: Method;
status?: number;
headers?: { [key: string]: string };
};
Expand All @@ -18,7 +21,7 @@ export type MockEndpointDynamicOptions = {
};

type MockEndpoint = (path: string, options: MockEndpointOptions) => void;
type MockEndpointDynamic = (endpoint: string, callBack: (url: URL, params: PathParams) => MockEndpointDynamicOptions) => void;
type MockEndpointDynamic = (endpoint: string, method: Method, callBack: (url: URL, params: PathParams, request: StrictRequest<DefaultBodyType>) => Promise<MockEndpointDynamicOptions>) => void;

export type SetupFactoryOptions = {
driver: Driver;
Expand Down
10 changes: 5 additions & 5 deletions src/Frontend/test/mock-endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { http, HttpResponse, type PathParams } from "msw";
import { DefaultBodyType, http, HttpResponse, StrictRequest, type PathParams } from "msw";
import type { SetupWorker } from "msw/browser";
import { SetupServer } from "msw/node";
import { MockEndpointDynamicOptions, MockEndpointOptions } from "./driver";
import { MockEndpointDynamicOptions, MockEndpointOptions, Method } from "./driver";

export const makeMockEndpoint =
({ mockServer }: { mockServer: SetupServer | SetupWorker }) =>
Expand All @@ -11,11 +11,11 @@ export const makeMockEndpoint =

export const makeMockEndpointDynamic =
({ mockServer }: { mockServer: SetupServer | SetupWorker }) =>
(endpoint: string, callBack: (url: URL, params: PathParams) => MockEndpointDynamicOptions) => {
(endpoint: string, method: Method = "get", callBack: (url: URL, params: PathParams, request: StrictRequest<DefaultBodyType>) => Promise<MockEndpointDynamicOptions>) => {
mockServer.use(
http.get(endpoint, ({ request, params }) => {
http[method](endpoint, async ({ request, params }) => {
const url = new URL(request.url.toString());
const { body, status = 200, headers = {} } = callBack(url, params);
const { body, status = 200, headers = {} } = await callBack(url, params, request);
return HttpResponse.json(body, { status: status, headers: headers });
})
);
Expand Down
10 changes: 5 additions & 5 deletions src/Frontend/test/preconditions/recoverability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,20 @@ export const hasFailedMessage =
edit_of: "",
};

driver.mockEndpointDynamic(`${serviceControlUrl}errors`, (url) => {
driver.mockEndpointDynamic(`${serviceControlUrl}errors`, "get", (url) => {
const status = url.searchParams.get("status");
if (status === "unresolved") {
return {
return Promise.resolve({
body: [failedMessage],
headers: { "Total-Count": "1" },
};
});
}

//For status=archived or status=retryissued
return {
return Promise.resolve({
body: [],
headers: { "Total-Count": "0" },
};
});
});

driver.mockEndpoint(`${serviceControlUrl}messages/${withMessageId}/body`, {
Expand Down