-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add yup for form validation and some basic validation and tests * feat: remove yup and move to more custom validation * chore: update to double quotes
- Loading branch information
Showing
3 changed files
with
37 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Prisma } from '@prisma/client'; | ||
|
||
import validateRegistrationForm from "./validateRegistrationForm"; | ||
|
||
describe("validateRegistrationForm", () => { | ||
it("validates correctly", async () => { | ||
const mockRegistrationInput: Prisma.RegistrationCreateInput = { | ||
firstName: 'firstName', | ||
lastName: 'lastName', | ||
email: 'email', | ||
course: { connect: { id: 1 } }, | ||
} | ||
|
||
const validatedData = await validateRegistrationForm(mockRegistrationInput); | ||
|
||
expect(validatedData).toEqual(undefined); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Prisma } from "@prisma/client"; | ||
|
||
export class ValidationError extends Error {} | ||
|
||
export const validateRegistrationForm = async (requestBody: Prisma.RegistrationCreateInput) => { | ||
if (!requestBody) { | ||
throw new ValidationError("Empty request body"); | ||
} | ||
}; | ||
|
||
export default validateRegistrationForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters