diff --git a/packages/next-safe-action/src/__tests__/action-callbacks.test.ts b/packages/next-safe-action/src/__tests__/action-callbacks.test.ts index 84fb3d6..69c1732 100644 --- a/packages/next-safe-action/src/__tests__/action-callbacks.test.ts +++ b/packages/next-safe-action/src/__tests__/action-callbacks.test.ts @@ -27,13 +27,13 @@ test("action with no input schema and no server errors calls `onSuccess` and `on return; }, { - onSuccess: () => { + onSuccess: async () => { executed++; }, - onError: () => { + onError: async () => { executed++; // should not be called }, - onSettled: () => { + onSettled: async () => { executed++; }, } @@ -57,7 +57,15 @@ test("action with input schemas and no errors calls `onSuccess` and `onSettled` }; }, { - onSuccess: ({ clientInput, bindArgsClientInputs, parsedInput, bindArgsParsedInputs, data, metadata, ctx }) => { + onSuccess: async ({ + clientInput, + bindArgsClientInputs, + parsedInput, + bindArgsParsedInputs, + data, + metadata, + ctx, + }) => { executed++; assert.deepStrictEqual( @@ -75,10 +83,10 @@ test("action with input schemas and no errors calls `onSuccess` and `onSettled` } ); }, - onError: () => { + onError: async () => { executed++; // should not be called }, - onSettled: ({ clientInput, bindArgsClientInputs, result, metadata, ctx }) => { + onSettled: async ({ clientInput, bindArgsClientInputs, result, metadata, ctx }) => { executed++; assert.deepStrictEqual( @@ -115,10 +123,10 @@ test("action with input schemas and server error calls `onError` and `onSettled` throw new Error("Server error"); }, { - onSuccess: () => { + onSuccess: async () => { executed++; // should not be called }, - onError({ error, clientInput, bindArgsClientInputs, metadata, ctx }) { + onError: async ({ error, clientInput, bindArgsClientInputs, metadata, ctx }) => { executed++; assert.deepStrictEqual( @@ -134,7 +142,7 @@ test("action with input schemas and server error calls `onError` and `onSettled` } ); }, - onSettled({ clientInput, bindArgsClientInputs, result, metadata, ctx }) { + onSettled: async ({ clientInput, bindArgsClientInputs, result, metadata, ctx }) => { executed++; assert.deepStrictEqual( @@ -171,10 +179,10 @@ test("action with validation errors calls `onError` and `onSettled` callbacks wi }; }, { - onSuccess: () => { + onSuccess: async () => { executed++; // should not be called }, - onError({ error, clientInput, bindArgsClientInputs, metadata, ctx }) { + onError: async ({ error, clientInput, bindArgsClientInputs, metadata, ctx }) => { executed++; assert.deepStrictEqual( @@ -202,7 +210,7 @@ test("action with validation errors calls `onError` and `onSettled` callbacks wi } ); }, - onSettled({ clientInput, bindArgsClientInputs, result, metadata, ctx }) { + onSettled: async ({ clientInput, bindArgsClientInputs, result, metadata, ctx }) => { executed++; assert.deepStrictEqual( @@ -252,10 +260,10 @@ test("action with server validation error calls `onError` and `onSettled` callba }); }, { - onSuccess: () => { + onSuccess: async () => { executed++; // should not be called }, - onError({ error, clientInput, bindArgsClientInputs, metadata, ctx }) { + onError: async ({ error, clientInput, bindArgsClientInputs, metadata, ctx }) => { executed++; assert.deepStrictEqual( @@ -275,7 +283,7 @@ test("action with server validation error calls `onError` and `onSettled` callba } ); }, - onSettled({ clientInput, bindArgsClientInputs, result, metadata, ctx }) { + onSettled: async ({ clientInput, bindArgsClientInputs, result, metadata, ctx }) => { executed++; assert.deepStrictEqual( diff --git a/packages/next-safe-action/src/__tests__/bind-args-validation-errors.test.ts b/packages/next-safe-action/src/__tests__/bind-args-validation-errors.test.ts index 0fce638..45f18f5 100644 --- a/packages/next-safe-action/src/__tests__/bind-args-validation-errors.test.ts +++ b/packages/next-safe-action/src/__tests__/bind-args-validation-errors.test.ts @@ -56,7 +56,9 @@ test("action with invalid bind args input gives back an object with correct `bin ]; const action = dac - .bindArgsSchemas(bindArgsSchemas, { handleBindArgsValidationErrorsShape: flattenBindArgsValidationErrors }) + .bindArgsSchemas(bindArgsSchemas, { + handleBindArgsValidationErrorsShape: async (ve) => flattenBindArgsValidationErrors(ve), + }) .action(async () => { return { ok: true, @@ -138,7 +140,9 @@ test("action with invalid bind args input gives back an object with correct `bin ]; const action = foac - .bindArgsSchemas(bindArgsSchemas, { handleBindArgsValidationErrorsShape: flattenBindArgsValidationErrors }) + .bindArgsSchemas(bindArgsSchemas, { + handleBindArgsValidationErrorsShape: async (ve) => flattenBindArgsValidationErrors(ve), + }) .action(async () => { return { ok: true, @@ -225,7 +229,9 @@ test("action with invalid bind args input gives back an object with correct `bin ]; const action = flac - .bindArgsSchemas(bindArgsSchemas, { handleBindArgsValidationErrorsShape: formatBindArgsValidationErrors }) + .bindArgsSchemas(bindArgsSchemas, { + handleBindArgsValidationErrorsShape: async (ve) => formatBindArgsValidationErrors(ve), + }) .action(async () => { return { ok: true, diff --git a/packages/next-safe-action/src/__tests__/combined-validation-errors.test.ts b/packages/next-safe-action/src/__tests__/combined-validation-errors.test.ts index 1b7f340..a890a3e 100644 --- a/packages/next-safe-action/src/__tests__/combined-validation-errors.test.ts +++ b/packages/next-safe-action/src/__tests__/combined-validation-errors.test.ts @@ -74,7 +74,9 @@ test("action with invalid bind args input and invalid main input gives back an o const action = dac .schema(schema) - .bindArgsSchemas(bindArgsSchemas, { handleBindArgsValidationErrorsShape: flattenBindArgsValidationErrors }) + .bindArgsSchemas(bindArgsSchemas, { + handleBindArgsValidationErrorsShape: async (ve) => flattenBindArgsValidationErrors(ve), + }) .action(async () => { return { ok: true, @@ -131,7 +133,7 @@ test("action with invalid bind args input and invalid main input gives back an o ]; const action = foac - .schema(schema, { handleValidationErrorsShape: flattenValidationErrors }) + .schema(schema, { handleValidationErrorsShape: async (ve) => flattenValidationErrors(ve) }) .bindArgsSchemas(bindArgsSchemas) .action(async () => { return { @@ -179,7 +181,9 @@ test("action with invalid bind args input and valid main input gives back an obj const action = foac .schema(schema) - .bindArgsSchemas(bindArgsSchemas, { handleBindArgsValidationErrorsShape: flattenBindArgsValidationErrors }) + .bindArgsSchemas(bindArgsSchemas, { + handleBindArgsValidationErrorsShape: async (ve) => flattenBindArgsValidationErrors(ve), + }) .action(async () => { return { ok: true, @@ -287,8 +291,10 @@ test("action with invalid bind args input, invalid main input and root level sch ]; const action = flac - .schema(schema, { handleValidationErrorsShape: formatValidationErrors }) - .bindArgsSchemas(bindArgsSchemas, { handleBindArgsValidationErrorsShape: formatBindArgsValidationErrors }) + .schema(schema, { handleValidationErrorsShape: async (ve) => formatValidationErrors(ve) }) + .bindArgsSchemas(bindArgsSchemas, { + handleBindArgsValidationErrorsShape: async (ve) => formatBindArgsValidationErrors(ve), + }) .action(async () => { return { ok: true, diff --git a/packages/next-safe-action/src/__tests__/middleware.test.ts b/packages/next-safe-action/src/__tests__/middleware.test.ts index 896c196..cccc50f 100644 --- a/packages/next-safe-action/src/__tests__/middleware.test.ts +++ b/packages/next-safe-action/src/__tests__/middleware.test.ts @@ -357,10 +357,10 @@ test("overridden formatted validation errors in execution result from middleware z.object({ username: z.string().max(3), }), - { handleValidationErrorsShape: formatValidationErrors } + { handleValidationErrorsShape: async (ve) => formatValidationErrors(ve) } ) .bindArgsSchemas([z.object({ age: z.number().positive() })], { - handleBindArgsValidationErrorsShape: formatBindArgsValidationErrors, + handleBindArgsValidationErrorsShape: async (ve) => formatBindArgsValidationErrors(ve), }) .use(async ({ next }) => { // Await action execution. diff --git a/packages/next-safe-action/src/__tests__/validation-errors.test.ts b/packages/next-safe-action/src/__tests__/validation-errors.test.ts index db13dce..188f24d 100644 --- a/packages/next-safe-action/src/__tests__/validation-errors.test.ts +++ b/packages/next-safe-action/src/__tests__/validation-errors.test.ts @@ -126,7 +126,7 @@ test("action with invalid input gives back an object with correct `validationErr const action = dac .schema(schema, { - handleValidationErrorsShape: flattenValidationErrors, + handleValidationErrorsShape: async (ve) => flattenValidationErrors(ve), }) .action(async () => { return { @@ -318,7 +318,7 @@ test("action with invalid input gives back an object with correct `validationErr const action = foac .schema(schema, { - handleValidationErrorsShape: flattenValidationErrors, + handleValidationErrorsShape: async (ve) => flattenValidationErrors(ve), }) .action(async () => { return { @@ -452,7 +452,7 @@ test("action with invalid input gives back an object with correct `validationErr const action = flac .schema(schema, { - handleValidationErrorsShape: formatValidationErrors, + handleValidationErrorsShape: async (ve) => formatValidationErrors(ve), }) .action(async () => { return {