Skip to content

Commit 06cf450

Browse files
authored
Merge pull request #250 from Real-Dev-Squad/feat/add-dob
feat: add date of birth (dob) field to Res struct and update related tests
2 parents 44fbfc8 + f735326 commit 06cf450

File tree

4 files changed

+87
-3
lines changed

4 files changed

+87
-3
lines changed

call-profile/main_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ func TestHandlerIntegration(t *testing.T) {
319319
"githubId": "johndoe",
320320
"linkedin": "johndoe",
321321
"website": "https://johndoe.com",
322+
"dob": "1990-01-15",
322323
},
323324
mockServer: func() *httptest.Server {
324325
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -337,7 +338,8 @@ func TestHandlerIntegration(t *testing.T) {
337338
"designation": "Developer",
338339
"github_id": "johndoe",
339340
"linkedin_id": "johndoe",
340-
"website": "https://johndoe.com"
341+
"website": "https://johndoe.com",
342+
"dob": "1990-01-15"
341343
}`))
342344
}
343345
}))
@@ -522,6 +524,7 @@ func TestHandlerWithRealFirestore(t *testing.T) {
522524
"githubId": "integrationtest",
523525
"linkedin": "integrationtest",
524526
"website": "https://integrationtest.com",
527+
"dob": "1992-05-20",
525528
}
526529

527530
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -540,7 +543,8 @@ func TestHandlerWithRealFirestore(t *testing.T) {
540543
"designation": "Tester",
541544
"github_id": "integrationtest",
542545
"linkedin_id": "integrationtest",
543-
"website": "https://integrationtest.com"
546+
"website": "https://integrationtest.com",
547+
"dob": "1992-05-20"
544548
}`))
545549
}
546550
}))

call-profile/testdata.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ var ResValidationTests = []struct {
163163
TwitterId: "johndoe",
164164
InstagramId: "johndoe",
165165
Website: "https://johndoe.com",
166+
DOB: "1990-01-15",
166167
},
167168
IsValid: true,
168169
Description: "Complete valid Res struct",
@@ -241,6 +242,78 @@ var ResValidationTests = []struct {
241242
IsValid: false,
242243
Description: "Invalid website URL should fail validation",
243244
},
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+
},
244317
}
245318

246319
var MockResponses = struct {
@@ -293,3 +366,4 @@ var EmptyUserIdTests = []struct {
293366
Description: "Null userId should return skip message",
294367
},
295368
}
369+

layer/utils/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Res struct {
2828
TwitterId string `json:"twitter_id"`
2929
InstagramId string `json:"instagram_id"`
3030
Website string `json:"website"`
31+
DOB string `json:"dob"`
3132
}
3233

3334
type Diff struct {
@@ -46,6 +47,7 @@ type Diff struct {
4647
TwitterId string `firestore:"twitter_id,omitempty"`
4748
InstagramId string `firestore:"instagram_id,omitempty"`
4849
Website string `firestore:"website,omitempty"`
50+
DOB string `firestore:"dob,omitempty"`
4951
}
5052

5153
type Claims struct {
@@ -99,5 +101,6 @@ func diffToMap(diff Diff) map[string]interface{} {
99101
"twitter_id": diff.TwitterId,
100102
"instagram_id": diff.InstagramId,
101103
"website": diff.Website,
104+
"dob": diff.DOB,
102105
}
103106
}

layer/utils/validation.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func resToDiff(res Res, userId string) Diff {
2626
TwitterId: res.TwitterId,
2727
InstagramId: res.InstagramId,
2828
Website: res.Website,
29+
DOB: res.DOB,
2930
}
3031
}
3132

@@ -43,6 +44,7 @@ func DiffToRes(diff Diff) Res {
4344
TwitterId: diff.TwitterId,
4445
InstagramId: diff.InstagramId,
4546
Website: diff.Website,
47+
DOB: diff.DOB,
4648
}
4749
}
4850

@@ -57,5 +59,6 @@ func (res Res) Validate() error {
5759
validation.Field(&res.Designation, validation.Required),
5860
validation.Field(&res.GithubId, validation.Required),
5961
validation.Field(&res.LinkedIn, validation.Required),
60-
validation.Field(&res.Website, is.URL))
62+
validation.Field(&res.Website, is.URL),
63+
validation.Field(&res.DOB, validation.Date("2006-01-02")))
6164
}

0 commit comments

Comments
 (0)