Skip to content

Commit f735326

Browse files
committed
feat: add date validation for DOB field in Res struct
1 parent 7c03fa7 commit f735326

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

call-profile/testdata.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,78 @@ var ResValidationTests = []struct {
242242
IsValid: false,
243243
Description: "Invalid website URL should fail validation",
244244
},
245+
{
246+
Name: "InvalidDOBFormat_Slash",
247+
Res: utils.Res{
248+
FirstName: "John",
249+
LastName: "Doe",
250+
251+
Phone: "1234567890",
252+
YOE: 5,
253+
Company: "Tech Corp",
254+
Designation: "Developer",
255+
GithubId: "johndoe",
256+
LinkedIn: "johndoe",
257+
Website: "https://johndoe.com",
258+
DOB: "01/15/1990",
259+
},
260+
IsValid: false,
261+
Description: "DOB with slash separator should fail validation",
262+
},
263+
{
264+
Name: "InvalidDOBFormat_WrongFormat",
265+
Res: utils.Res{
266+
FirstName: "John",
267+
LastName: "Doe",
268+
269+
Phone: "1234567890",
270+
YOE: 5,
271+
Company: "Tech Corp",
272+
Designation: "Developer",
273+
GithubId: "johndoe",
274+
LinkedIn: "johndoe",
275+
Website: "https://johndoe.com",
276+
DOB: "invalid-date",
277+
},
278+
IsValid: false,
279+
Description: "Invalid date string should fail validation",
280+
},
281+
{
282+
Name: "ValidDOB_EmptyString",
283+
Res: utils.Res{
284+
FirstName: "John",
285+
LastName: "Doe",
286+
287+
Phone: "1234567890",
288+
YOE: 5,
289+
Company: "Tech Corp",
290+
Designation: "Developer",
291+
GithubId: "johndoe",
292+
LinkedIn: "johndoe",
293+
Website: "https://johndoe.com",
294+
DOB: "",
295+
},
296+
IsValid: true,
297+
Description: "Empty DOB string should be valid (optional field)",
298+
},
299+
{
300+
Name: "ValidDOB_ValidFormat",
301+
Res: utils.Res{
302+
FirstName: "John",
303+
LastName: "Doe",
304+
305+
Phone: "1234567890",
306+
YOE: 5,
307+
Company: "Tech Corp",
308+
Designation: "Developer",
309+
GithubId: "johndoe",
310+
LinkedIn: "johndoe",
311+
Website: "https://johndoe.com",
312+
DOB: "1990-01-15",
313+
},
314+
IsValid: true,
315+
Description: "Valid DOB in YYYY-MM-DD format should pass validation",
316+
},
245317
}
246318

247319
var MockResponses = struct {

layer/utils/validation.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@ func (res Res) Validate() error {
5959
validation.Field(&res.Designation, validation.Required),
6060
validation.Field(&res.GithubId, validation.Required),
6161
validation.Field(&res.LinkedIn, validation.Required),
62-
validation.Field(&res.Website, is.URL))
62+
validation.Field(&res.Website, is.URL),
63+
validation.Field(&res.DOB, validation.Date("2006-01-02")))
6364
}

0 commit comments

Comments
 (0)