From e70a74b5212055c6b5f67ae0801b5505580788ef Mon Sep 17 00:00:00 2001 From: Edoardo Ranghieri Date: Sun, 11 Aug 2024 20:46:25 +0200 Subject: [PATCH] test(middleware): remove args from `next` function --- .../src/__tests__/middleware.test.ts | 26 +++++++++---------- .../src/__tests__/server-error.test.ts | 8 +++--- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/next-safe-action/src/__tests__/middleware.test.ts b/packages/next-safe-action/src/__tests__/middleware.test.ts index 6b1f02a1..6878605b 100644 --- a/packages/next-safe-action/src/__tests__/middleware.test.ts +++ b/packages/next-safe-action/src/__tests__/middleware.test.ts @@ -70,7 +70,7 @@ test("instance context value is correctly overridden in subsequent middleware", if (ctx.foo !== "baz") { throw new Error("Expected ctx.foo to be 'baz'"); } - return next({ ctx }); + return next(); }) .action(async ({ ctx }) => { return { @@ -130,9 +130,9 @@ test("happy path execution result from middleware is correct", async () => { }) ) .bindArgsSchemas([z.object({ age: z.number().positive() })]) - .use(async ({ next, ctx }) => { + .use(async ({ next }) => { // Await action execution. - const res = await next({ ctx }); + const res = await next(); middlewareResult = res; return res; }) @@ -176,9 +176,9 @@ test("server error execution result from middleware is correct", async () => { }) ) .bindArgsSchemas([z.object({ age: z.number().positive() })]) - .use(async ({ next, ctx }) => { + .use(async ({ next }) => { // Await action execution. - const res = await next({ ctx }); + const res = await next(); middlewareResult = res; return res; }) @@ -212,9 +212,9 @@ test("validation errors in execution result from middleware are correct", async }) ) .bindArgsSchemas([z.object({ age: z.number().positive() })]) - .use(async ({ next, ctx }) => { + .use(async ({ next }) => { // Await action execution. - const res = await next({ ctx }); + const res = await next(); middlewareResult = res; return res; }) @@ -259,9 +259,9 @@ test("server validation errors in execution result from middleware are correct", const action = ac .schema(schema) .bindArgsSchemas([z.object({ age: z.number().positive() })]) - .use(async ({ next, ctx }) => { + .use(async ({ next }) => { // Await action execution. - const res = await next({ ctx }); + const res = await next(); middlewareResult = res; return res; }) @@ -309,9 +309,9 @@ test("flattened validation errors in execution result from middleware are correc }) ) .bindArgsSchemas([z.object({ age: z.number().positive() })]) - .use(async ({ next, ctx }) => { + .use(async ({ next }) => { // Await action execution. - const res = await next({ ctx }); + const res = await next(); middlewareResult = res; return res; }) @@ -360,9 +360,9 @@ test("overridden formatted validation errors in execution result from middleware .bindArgsSchemas([z.object({ age: z.number().positive() })], { handleBindArgsValidationErrorsShape: formatBindArgsValidationErrors, }) - .use(async ({ next, ctx }) => { + .use(async ({ next }) => { // Await action execution. - const res = await next({ ctx }); + const res = await next(); middlewareResult = res; return res; }) diff --git a/packages/next-safe-action/src/__tests__/server-error.test.ts b/packages/next-safe-action/src/__tests__/server-error.test.ts index cf874baa..66a28580 100644 --- a/packages/next-safe-action/src/__tests__/server-error.test.ts +++ b/packages/next-safe-action/src/__tests__/server-error.test.ts @@ -39,7 +39,7 @@ test("unknown error occurred in server code function is masked by default", asyn test("unknown error occurred in middleware function is masked by default", async () => { const action = ac1 - .use(async ({ next, ctx }) => next({ ctx })) + .use(async ({ next }) => next()) .use(async () => { throw new Error("Something bad happened"); }) @@ -74,7 +74,7 @@ test("known error occurred in server code function is unmasked", async () => { test("known error occurred in middleware function is unmasked", async () => { const action = ac1 - .use(async ({ next, ctx }) => next({ ctx })) + .use(async ({ next }) => next()) .use(async () => { throw new ActionError("Something bad happened"); }) @@ -131,7 +131,7 @@ test("error occurred in server code function has the correct shape defined by `h test("error occurred in middleware function has the correct shape defined by `handleReturnedServerError`", async () => { const action = ac2 - .use(async ({ next, ctx }) => next({ ctx })) + .use(async ({ next }) => next()) .use(async () => { throw new Error("Something bad happened"); }) @@ -169,7 +169,7 @@ test("action throws if an error occurred in server code function and `handleRetu test("action throws if an error occurred in middleware function and `handleReturnedServerError` rethrows it", async () => { const action = ac3 - .use(async ({ next, ctx }) => next({ ctx })) + .use(async ({ next }) => next()) .use(async () => { throw new Error("Something bad happened"); })