Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions call-profile/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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"
}`))
}
}))
Expand Down Expand Up @@ -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) {
Expand All @@ -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"
}`))
}
}))
Expand Down
74 changes: 74 additions & 0 deletions call-profile/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -293,3 +366,4 @@ var EmptyUserIdTests = []struct {
Description: "Null userId should return skip message",
},
}

3 changes: 3 additions & 0 deletions layer/utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
}
}
5 changes: 4 additions & 1 deletion layer/utils/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func resToDiff(res Res, userId string) Diff {
TwitterId: res.TwitterId,
InstagramId: res.InstagramId,
Website: res.Website,
DOB: res.DOB,
}
}

Expand All @@ -43,6 +44,7 @@ func DiffToRes(diff Diff) Res {
TwitterId: diff.TwitterId,
InstagramId: diff.InstagramId,
Website: diff.Website,
DOB: diff.DOB,
}
}

Expand All @@ -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")))
}