diff --git a/call-profile/main_test.go b/call-profile/main_test.go index edc2fe3..acc50f2 100644 --- a/call-profile/main_test.go +++ b/call-profile/main_test.go @@ -319,6 +319,7 @@ func TestHandlerIntegration(t *testing.T) { "githubId": "johndoe", "linkedin": "johndoe", "website": "https://johndoe.com", + "dob": "1990-01-15", }, mockServer: func() *httptest.Server { return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -337,7 +338,8 @@ func TestHandlerIntegration(t *testing.T) { "designation": "Developer", "github_id": "johndoe", "linkedin_id": "johndoe", - "website": "https://johndoe.com" + "website": "https://johndoe.com", + "dob": "1990-01-15" }`)) } })) @@ -522,6 +524,7 @@ func TestHandlerWithRealFirestore(t *testing.T) { "githubId": "integrationtest", "linkedin": "integrationtest", "website": "https://integrationtest.com", + "dob": "1992-05-20", } server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -540,7 +543,8 @@ func TestHandlerWithRealFirestore(t *testing.T) { "designation": "Tester", "github_id": "integrationtest", "linkedin_id": "integrationtest", - "website": "https://integrationtest.com" + "website": "https://integrationtest.com", + "dob": "1992-05-20" }`)) } })) diff --git a/call-profile/testdata.go b/call-profile/testdata.go index eea13eb..f11d6ef 100644 --- a/call-profile/testdata.go +++ b/call-profile/testdata.go @@ -163,6 +163,7 @@ var ResValidationTests = []struct { TwitterId: "johndoe", InstagramId: "johndoe", Website: "https://johndoe.com", + DOB: "1990-01-15", }, IsValid: true, Description: "Complete valid Res struct", @@ -241,6 +242,78 @@ var ResValidationTests = []struct { IsValid: false, Description: "Invalid website URL should fail validation", }, + { + Name: "InvalidDOBFormat_Slash", + Res: utils.Res{ + FirstName: "John", + LastName: "Doe", + Email: "john.doe@example.com", + Phone: "1234567890", + YOE: 5, + Company: "Tech Corp", + Designation: "Developer", + GithubId: "johndoe", + LinkedIn: "johndoe", + Website: "https://johndoe.com", + DOB: "01/15/1990", + }, + IsValid: false, + Description: "DOB with slash separator should fail validation", + }, + { + Name: "InvalidDOBFormat_WrongFormat", + Res: utils.Res{ + FirstName: "John", + LastName: "Doe", + Email: "john.doe@example.com", + Phone: "1234567890", + YOE: 5, + Company: "Tech Corp", + Designation: "Developer", + GithubId: "johndoe", + LinkedIn: "johndoe", + Website: "https://johndoe.com", + DOB: "invalid-date", + }, + IsValid: false, + Description: "Invalid date string should fail validation", + }, + { + Name: "ValidDOB_EmptyString", + Res: utils.Res{ + FirstName: "John", + LastName: "Doe", + Email: "john.doe@example.com", + Phone: "1234567890", + YOE: 5, + Company: "Tech Corp", + Designation: "Developer", + GithubId: "johndoe", + LinkedIn: "johndoe", + Website: "https://johndoe.com", + DOB: "", + }, + IsValid: true, + Description: "Empty DOB string should be valid (optional field)", + }, + { + Name: "ValidDOB_ValidFormat", + Res: utils.Res{ + FirstName: "John", + LastName: "Doe", + Email: "john.doe@example.com", + Phone: "1234567890", + YOE: 5, + Company: "Tech Corp", + Designation: "Developer", + GithubId: "johndoe", + LinkedIn: "johndoe", + Website: "https://johndoe.com", + DOB: "1990-01-15", + }, + IsValid: true, + Description: "Valid DOB in YYYY-MM-DD format should pass validation", + }, } var MockResponses = struct { @@ -293,3 +366,4 @@ var EmptyUserIdTests = []struct { Description: "Null userId should return skip message", }, } + \ No newline at end of file diff --git a/layer/utils/constants.go b/layer/utils/constants.go index c1552a0..41c3428 100644 --- a/layer/utils/constants.go +++ b/layer/utils/constants.go @@ -28,6 +28,7 @@ type Res struct { TwitterId string `json:"twitter_id"` InstagramId string `json:"instagram_id"` Website string `json:"website"` + DOB string `json:"dob"` } type Diff struct { @@ -46,6 +47,7 @@ type Diff struct { TwitterId string `firestore:"twitter_id,omitempty"` InstagramId string `firestore:"instagram_id,omitempty"` Website string `firestore:"website,omitempty"` + DOB string `firestore:"dob,omitempty"` } type Claims struct { @@ -99,5 +101,6 @@ func diffToMap(diff Diff) map[string]interface{} { "twitter_id": diff.TwitterId, "instagram_id": diff.InstagramId, "website": diff.Website, + "dob": diff.DOB, } } diff --git a/layer/utils/validation.go b/layer/utils/validation.go index 70b2ea5..50c8d10 100644 --- a/layer/utils/validation.go +++ b/layer/utils/validation.go @@ -26,6 +26,7 @@ func resToDiff(res Res, userId string) Diff { TwitterId: res.TwitterId, InstagramId: res.InstagramId, Website: res.Website, + DOB: res.DOB, } } @@ -43,6 +44,7 @@ func DiffToRes(diff Diff) Res { TwitterId: diff.TwitterId, InstagramId: diff.InstagramId, Website: diff.Website, + DOB: diff.DOB, } } @@ -57,5 +59,6 @@ func (res Res) Validate() error { validation.Field(&res.Designation, validation.Required), validation.Field(&res.GithubId, validation.Required), validation.Field(&res.LinkedIn, validation.Required), - validation.Field(&res.Website, is.URL)) + validation.Field(&res.Website, is.URL), + validation.Field(&res.DOB, validation.Date("2006-01-02"))) }