Skip to content

Commit

Permalink
add email validation to registration schema
Browse files Browse the repository at this point in the history
  • Loading branch information
aletya committed Jan 4, 2025
1 parent 8b4e5a3 commit 5543802
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/services/registration/registration-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const APPLICATION = {
hackOutreach: [HackOutreach.INSTAGRAM],
} satisfies RegistrationApplicationRequest;

const APPLICATION_INVALID_EMAIL = Object.assign({}, APPLICATION, {
emailAddress: "invalidemail",
});

const UNSUBMITTED_REGISTRATION = { userId: TESTER.id, hasSubmitted: false, ...APPLICATION } satisfies RegistrationApplication;
const UNSUBMITTED_OTHER_REGISTRATION = {
...UNSUBMITTED_REGISTRATION,
Expand Down Expand Up @@ -118,6 +122,13 @@ describe("POST /registration/", () => {
expect(JSON.parse(response.text)).toHaveProperty("error", "BadRequest");
});

it("should provide bad request error when email is invalid", async () => {
const response = await postAsUser("/registration/")
.send(APPLICATION_INVALID_EMAIL)
.expect(StatusCode.ClientErrorBadRequest);
expect(JSON.parse(response.text)).toHaveProperty("error", "BadRequest");
});

it("should provide already submitted error when user has already submitted registration", async () => {
await Models.RegistrationApplication.create(SUBMITTED_REGISTRATION);

Expand Down
2 changes: 1 addition & 1 deletion src/services/registration/registration-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const RegistrationApplicationRequestSchema = z
isProApplicant: z.boolean(),
preferredName: z.string(),
legalName: z.string(),
emailAddress: z.string(),
emailAddress: z.string().email({ message: "Invalid email syntax." }),
gender: GenderSchema,
race: z.array(RaceSchema),
resumeFileName: z.string().optional(),
Expand Down

0 comments on commit 5543802

Please sign in to comment.