Skip to content

Commit 848157f

Browse files
Merge branch 'main' into MI-1067-update-user-profile
2 parents 20a5661 + 0cef5ac commit 848157f

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

__tests__/schema/profile.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ describe('mutation upsertUserGeneralExperience', () => {
622622
description: 'Built a popular browser extension for developers',
623623
startedAt: new Date('2021-01-01'),
624624
url: 'https://github.com/dailydotdev/extension',
625+
customCompanyName: 'Personal Project',
625626
},
626627
},
627628
});
@@ -741,13 +742,15 @@ describe('mutation upsertUserGeneralExperience', () => {
741742
title: 'Self-taught Developer',
742743
startedAt: new Date('2020-01-01'),
743744
companyId: null,
745+
customCompanyName: 'Self-taught',
744746
},
745747
},
746748
});
747749

748750
expect(res.errors).toBeFalsy();
749751
expect(res.data.upsertUserGeneralExperience).toMatchObject({
750752
company: null,
753+
customCompanyName: 'Self-taught',
751754
});
752755
});
753756

@@ -784,6 +787,7 @@ describe('mutation upsertUserGeneralExperience', () => {
784787
type: 'certification',
785788
title: 'Test',
786789
startedAt: new Date('2020-01-01'),
790+
customCompanyName: 'Test Company',
787791
},
788792
},
789793
},
@@ -805,6 +809,7 @@ describe('mutation upsertUserGeneralExperience', () => {
805809
type: 'work',
806810
title: 'Hacked Title',
807811
startedAt: new Date('2021-01-01'),
812+
customCompanyName: 'Some Company',
808813
},
809814
},
810815
},
@@ -829,6 +834,7 @@ describe('mutation upsertUserGeneralExperience', () => {
829834
type: 'project',
830835
title: 'Updated Project Title',
831836
startedAt: new Date('2021-06-01'),
837+
companyId: 'company-1',
832838
},
833839
},
834840
});
@@ -959,6 +965,29 @@ describe('mutation upsertUserGeneralExperience', () => {
959965
);
960966
});
961967

968+
it('should fail when experience has neither companyId nor customCompanyName', async () => {
969+
loggedUser = '1';
970+
971+
const experienceTypes = ['work', 'education', 'project', 'certification'];
972+
973+
for (const type of experienceTypes) {
974+
await testQueryErrorCode(
975+
client,
976+
{
977+
query: UPSERT_USER_GENERAL_EXPERIENCE_MUTATION,
978+
variables: {
979+
input: {
980+
type,
981+
title: 'Test Experience',
982+
startedAt: new Date('2023-01-01'),
983+
},
984+
},
985+
},
986+
'ZOD_VALIDATION_ERROR',
987+
);
988+
}
989+
});
990+
962991
it('should create experience without optional fields', async () => {
963992
loggedUser = '1';
964993

@@ -968,6 +997,7 @@ describe('mutation upsertUserGeneralExperience', () => {
968997
type: 'project',
969998
title: 'Minimal Project',
970999
startedAt: new Date('2023-01-01'),
1000+
customCompanyName: 'Project Organization',
9711001
},
9721002
},
9731003
});
@@ -981,6 +1011,7 @@ describe('mutation upsertUserGeneralExperience', () => {
9811011
endedAt: null,
9821012
url: null,
9831013
company: null,
1014+
customCompanyName: 'Project Organization',
9841015
});
9851016
});
9861017

@@ -1244,6 +1275,7 @@ describe('mutation upsertUserWorkExperience', () => {
12441275
type: 'work',
12451276
title: 'Hacked Title',
12461277
startedAt: new Date('2021-01-01'),
1278+
customCompanyName: 'Some Company',
12471279
skills: [],
12481280
},
12491281
},
@@ -1502,6 +1534,25 @@ describe('mutation upsertUserWorkExperience', () => {
15021534
skills: [],
15031535
});
15041536
});
1537+
1538+
it('should fail when work experience has neither companyId nor customCompanyName', async () => {
1539+
loggedUser = '1';
1540+
1541+
await testQueryErrorCode(
1542+
client,
1543+
{
1544+
query: UPSERT_USER_WORK_EXPERIENCE_MUTATION,
1545+
variables: {
1546+
input: {
1547+
type: 'work',
1548+
title: 'Software Engineer',
1549+
startedAt: new Date('2023-01-01'),
1550+
},
1551+
},
1552+
},
1553+
'ZOD_VALIDATION_ERROR',
1554+
);
1555+
});
15051556
});
15061557

15071558
describe('mutation removeUserExperience', () => {

src/common/schema/profile.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ export const userExperienceInputBaseSchema = z.object({
2222
.trim()
2323
.normalize()
2424
.max(100)
25-
.nonempty()
26-
.nullable()
27-
.optional()
25+
.nullish()
2826
.default(null),
2927
});
3028

@@ -72,6 +70,15 @@ const experienceTypeToSchema: Record<
7270
[UserExperienceType.OpenSource]: userExperienceProjectSchema,
7371
};
7472

73+
const experienceCompanyCopy = {
74+
[UserExperienceType.Work]: 'Company',
75+
[UserExperienceType.Education]: 'School',
76+
[UserExperienceType.Project]: 'Publisher',
77+
[UserExperienceType.Certification]: 'Organization',
78+
[UserExperienceType.OpenSource]: 'Organization',
79+
[UserExperienceType.Volunteering]: 'Organization',
80+
};
81+
7582
export const getExperienceSchema = (type: UserExperienceType) => {
7683
return experienceTypeToSchema[type].superRefine((data, ctx) => {
7784
if (data.endedAt && data.endedAt < data.startedAt) {
@@ -81,6 +88,13 @@ export const getExperienceSchema = (type: UserExperienceType) => {
8188
path: ['endedAt'],
8289
});
8390
}
91+
if (!data.customCompanyName && !data.companyId) {
92+
ctx.addIssue({
93+
code: 'custom',
94+
message: `${experienceCompanyCopy[type]} is required`,
95+
path: ['customCompanyName'],
96+
});
97+
}
8498
});
8599
};
86100

0 commit comments

Comments
 (0)