mirror of
https://github.com/tale/headplane.git
synced 2026-10-27 06:57:53 +00:00
test: accept any route function in the test app without a cast
This commit is contained in:
@@ -26,7 +26,7 @@ describe("machines on a real tailnet", () => {
|
||||
});
|
||||
|
||||
function machine(form: Record<string, string>) {
|
||||
return app.call(machineAction as never, "/machines", { as: owner, form });
|
||||
return app.call(machineAction, "/machines", { as: owner, form });
|
||||
}
|
||||
|
||||
test("a waiting machine registered from its URL comes online for that user", async () => {
|
||||
@@ -110,7 +110,7 @@ describe("DNS on a real tailnet", () => {
|
||||
|
||||
const node = await tailnet.node({ name: "dns-client", user: "alice@" });
|
||||
const { cookie } = await app.signIn("owner");
|
||||
const result = await app.call(dnsAction as never, "/dns", {
|
||||
const result = await app.call(dnsAction, "/dns", {
|
||||
as: cookie,
|
||||
form: {
|
||||
intent: "add_record",
|
||||
|
||||
@@ -21,7 +21,8 @@ export interface TestAppOptions {
|
||||
|
||||
export type TestApp = Awaited<ReturnType<typeof createTestApp>>;
|
||||
|
||||
type RouteFunction = (args: LoaderFunctionArgs & ActionFunctionArgs) => unknown;
|
||||
// Any loader or action, whatever its generated argument types.
|
||||
type RouteFunction = (args: never) => unknown;
|
||||
|
||||
export interface CallOptions {
|
||||
as?: string;
|
||||
@@ -120,7 +121,9 @@ export async function createTestApp(options: TestAppOptions = {}) {
|
||||
};
|
||||
|
||||
try {
|
||||
return await fn(args as unknown as LoaderFunctionArgs & ActionFunctionArgs);
|
||||
return await (fn as (args: LoaderFunctionArgs & ActionFunctionArgs) => unknown)(
|
||||
args as unknown as LoaderFunctionArgs & ActionFunctionArgs,
|
||||
);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ afterEach(async () => {
|
||||
});
|
||||
|
||||
function create(as: string, form: Record<string, string | string[]>) {
|
||||
return app.call(action as never, "/settings/auth-keys", {
|
||||
return app.call(action, "/settings/auth-keys", {
|
||||
as,
|
||||
form: { intent: "create", expiry: "90", ...form },
|
||||
});
|
||||
@@ -90,7 +90,7 @@ describe("self-service auth keys", () => {
|
||||
await create(admin, { user_id: bob.id });
|
||||
await create(admin, { tags: "tag:prod" });
|
||||
|
||||
const data = (await app.call(loader as never, "/settings/auth-keys", {
|
||||
const data = (await app.call(loader, "/settings/auth-keys", {
|
||||
as: await signInAsAlice(),
|
||||
})) as Awaited<ReturnType<typeof loader>>;
|
||||
|
||||
@@ -104,7 +104,7 @@ describe("self-service auth keys", () => {
|
||||
await create(cookie, { user_id: bob.id });
|
||||
await create(cookie, { tags: "tag:prod" });
|
||||
|
||||
const data = (await app.call(loader as never, "/settings/auth-keys", {
|
||||
const data = (await app.call(loader, "/settings/auth-keys", {
|
||||
as: cookie,
|
||||
})) as Awaited<ReturnType<typeof loader>>;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { HEADSCALE_VERSIONS } from "../../harness/versions";
|
||||
import { createTestApp, type TestApp } from "../../support/app";
|
||||
|
||||
async function signIn(app: TestApp, form: Record<string, string>) {
|
||||
return app.call(action as never, "/login", { form });
|
||||
return app.call(action, "/login", { form });
|
||||
}
|
||||
|
||||
describe.for(HEADSCALE_VERSIONS)("API key sign-in on Headscale %s", (version) => {
|
||||
|
||||
@@ -112,7 +112,7 @@ describe("route permissions", () => {
|
||||
});
|
||||
|
||||
function callAction(entry: Entry, as?: string) {
|
||||
return app.call(entry.module.action! as never, entry.path, {
|
||||
return app.call(entry.module.action!, entry.path, {
|
||||
as,
|
||||
form: { ...form, ...(entry.intent ? { intent: entry.intent } : {}) },
|
||||
params: { id: form.node_id },
|
||||
@@ -129,7 +129,7 @@ describe("route permissions", () => {
|
||||
async ([, entry]) => {
|
||||
const callers = MEMBER_VISIBLE.has(entry.file) ? [undefined] : [undefined, "member" as const];
|
||||
for (const role of callers) {
|
||||
const result = await app.call(entry.module.loader! as never, entry.path, {
|
||||
const result = await app.call(entry.module.loader!, entry.path, {
|
||||
as: role && cookies.get(role),
|
||||
params: { id: form.node_id },
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user