Skip to content

Commit

Permalink
test: add schema extension tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEdoRan committed Jun 20, 2024
1 parent 79ec8eb commit ff952c1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/next-safe-action/src/__tests__/happy-path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,32 @@ test("action with input schema passed via async function and return data gives b
assert.deepStrictEqual(actualResult, expectedResult);
});

test("action with input schema extended via async function and return data gives back an object with correct `data`", async () => {
const userId = "ed6f5b84-6bca-4d01-9a51-c3d0c49a7996";
const password = "password";

const action = ac
.schema(z.object({ password: z.string() }))
.schema(async (prevSchema) => prevSchema.extend({ userId: z.string().uuid() }))
.action(async ({ parsedInput }) => {
return {
userId: parsedInput.userId,
password: parsedInput.password,
};
});

const actualResult = await action({ password, userId });

const expectedResult = {
data: {
password,
userId,
},
};

assert.deepStrictEqual(actualResult, expectedResult);
});

test("action with no input schema, bind args input schemas and return data gives back an object with correct `data`", async () => {
const username = "johndoe";
const age = 30;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,32 @@ test("typeschema - action with input schema passed via async function and return
assert.deepStrictEqual(actualResult, expectedResult);
});

test("typeschema - action with input schema extended via async function and return data gives back an object with correct `data`", async () => {
const userId = "ed6f5b84-6bca-4d01-9a51-c3d0c49a7996";
const password = "password";

const action = ac
.schema(z.object({ password: z.string() }))
.schema(async (prevSchema) => prevSchema.extend({ userId: z.string().uuid() }))
.action(async ({ parsedInput }) => {
return {
userId: parsedInput.userId,
password: parsedInput.password,
};
});

const actualResult = await action({ password, userId });

const expectedResult = {
data: {
password,
userId,
},
};

assert.deepStrictEqual(actualResult, expectedResult);
});

test("typeschema - action with no input schema, bind args input schemas and return data gives back an object with correct `data`", async () => {
const username = "johndoe";
const age = 30;
Expand Down

0 comments on commit ff952c1

Please sign in to comment.