Skip to content

Commit

Permalink
feat: add example for valibot
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Oct 14, 2023
1 parent 8a83bba commit 1edff78
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 21 deletions.
29 changes: 29 additions & 0 deletions example/cypress/e2e/greeter.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// <reference types="cypress" />

export { };

context("/api/greeter", () => {
beforeEach(() => {
cy.visit("/");
});

it("should get error when navigate to /api/greeter", () => {
return cy.request({
method: "GET",
url: "/api/greeter",
failOnStatusCode: false,
}).then((response) => {
expect(response.status).equal(400);
});
});

it("should say greeter name when navigate to /api/greeter?name=Dung", () => {
return cy.request({
method: "GET",
url: "/api/greeter?name=Dung",
}).then((response) => {
expect(response.status).equal(200);
expect(response.body.name).equal("Dung");
});
});
});
12 changes: 8 additions & 4 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"cypress:open": "cypress open",
"dev": "next dev",
"start": "next start",
"cypress:open": "cypress open"
"test": "npm run dev & npm run test:e2e",
"test:e2e": "wait-on http://localhost:3000 && cypress run"
},
"dependencies": {
"caniuse-lite": "1.0.30001547",
Expand All @@ -15,18 +17,20 @@
"joi": "17.11.0",
"next": "13.5.4",
"next-connect": "1.0.0",
"next-validations": "0.3.3",
"next-validations": "0.4.0",
"qs": "6.11.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"swagger-ui-react": "5.9.0",
"valibot": "^0.19.0",
"yup": "1.3.2",
"zod": "3.22.4"
},
"devDependencies": {
"@types/cypress": "1.1.3",
"cypress": "13.3.1",
"eslint": "8.51.0",
"eslint-config-next": "13.5.4"
"eslint-config-next": "13.5.4",
"wait-on": "7.0.1"
}
}
19 changes: 19 additions & 0 deletions example/pages/api/greeter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { withValidation } from 'next-validations';
import * as valibot from 'valibot';

const schema = valibot.object({
name: valibot.string(),
});

const validate = withValidation({
schema,
type: 'Valibot',
mode: 'query',
});

const handler = (req: NextApiRequest, res: NextApiResponse) => {
res.status(200).json(req.query);
};

export default validate(handler);
59 changes: 42 additions & 17 deletions example/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 comment on commit 1edff78

@vercel
Copy link

@vercel vercel bot commented on 1edff78 Oct 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.