|
| 1 | +/** |
| 2 | + * To run these tests: |
| 3 | + * - Run this file test: pnpm test validateSignupForm |
| 4 | + * - Run with coverage: pnpm test validateSignupForm -- --coverage |
| 5 | + * - Run in watch mode: pnpm test validateSignupForm -- --watch |
| 6 | + */ |
| 7 | + |
1 | 8 | import { Department, Level } from "@/types"; |
2 | 9 | import validateSignupForm, { SignupFormData } from "./validateSignupForm"; |
3 | 10 | import RESPONSE_MESSAGES from "../../constants/RESPONSE_MESSAGES"; |
@@ -52,25 +59,61 @@ describe("validateSignupForm", () => { |
52 | 59 | expect(errors.academicNumber).toBe(RESPONSE_MESSAGES.signup.VALIDATIONS.ACADEMIC_REQUIRED); |
53 | 60 | }); |
54 | 61 |
|
55 | | - it("should validate academic number length", () => { |
| 62 | + it("should validate academic number type", () => { |
56 | 63 | const data = createValidFormData(); |
57 | | - data.academicNumber = "12345"; |
| 64 | + data.academicNumber = 12345 as any; |
58 | 65 | const errors = validateSignupForm(data); |
59 | | - expect(errors.academicNumber).toBe(RESPONSE_MESSAGES.signup.VALIDATIONS.ACADEMIC_LENGTH); |
| 66 | + expect(errors.academicNumber).toBe(RESPONSE_MESSAGES.signup.VALIDATIONS.ACADEMIC_NOT_STRING); |
60 | 67 | }); |
61 | 68 |
|
62 | | - it("should validate academic number format", () => { |
| 69 | + it("should validate academic number format (only numbers)", () => { |
63 | 70 | const data = createValidFormData(); |
64 | | - data.academicNumber = "123abc4567890"; |
| 71 | + data.academicNumber = "123abc45"; |
65 | 72 | const errors = validateSignupForm(data); |
66 | 73 | expect(errors.academicNumber).toBe(RESPONSE_MESSAGES.signup.VALIDATIONS.ACADEMIC_ONLY_NUMBERS); |
67 | 74 | }); |
68 | 75 |
|
69 | | - it("should accept valid academic number", () => { |
| 76 | + it("should validate academic number length (5 digits)", () => { |
70 | 77 | const data = createValidFormData(); |
| 78 | + data.academicNumber = "12345"; |
71 | 79 | const errors = validateSignupForm(data); |
72 | 80 | expect(errors.academicNumber).toBeUndefined(); |
73 | 81 | }); |
| 82 | + |
| 83 | + it("should validate academic number length (6 digits)", () => { |
| 84 | + const data = createValidFormData(); |
| 85 | + data.academicNumber = "123456"; |
| 86 | + const errors = validateSignupForm(data); |
| 87 | + expect(errors.academicNumber).toBeUndefined(); |
| 88 | + }); |
| 89 | + |
| 90 | + it("should validate academic number length (13 digits)", () => { |
| 91 | + const data = createValidFormData(); |
| 92 | + data.academicNumber = "1234567890123"; |
| 93 | + const errors = validateSignupForm(data); |
| 94 | + expect(errors.academicNumber).toBeUndefined(); |
| 95 | + }); |
| 96 | + |
| 97 | + it("should reject academic number with invalid length (4 digits)", () => { |
| 98 | + const data = createValidFormData(); |
| 99 | + data.academicNumber = "1234"; |
| 100 | + const errors = validateSignupForm(data); |
| 101 | + expect(errors.academicNumber).toBe(RESPONSE_MESSAGES.signup.VALIDATIONS.ACADEMIC_LENGTH); |
| 102 | + }); |
| 103 | + |
| 104 | + it("should reject academic number with invalid length (7 digits)", () => { |
| 105 | + const data = createValidFormData(); |
| 106 | + data.academicNumber = "1234567"; |
| 107 | + const errors = validateSignupForm(data); |
| 108 | + expect(errors.academicNumber).toBe(RESPONSE_MESSAGES.signup.VALIDATIONS.ACADEMIC_LENGTH); |
| 109 | + }); |
| 110 | + |
| 111 | + it("should reject academic number with invalid length (14 digits)", () => { |
| 112 | + const data = createValidFormData(); |
| 113 | + data.academicNumber = "12345678901234"; |
| 114 | + const errors = validateSignupForm(data); |
| 115 | + expect(errors.academicNumber).toBe(RESPONSE_MESSAGES.signup.VALIDATIONS.ACADEMIC_LENGTH); |
| 116 | + }); |
74 | 117 | }); |
75 | 118 |
|
76 | 119 | describe("Email Validation", () => { |
|
0 commit comments