Skip to content

Commit 80072bf

Browse files
fix: cdc trigger for cv achievement (#3570)
1 parent abe3fcd commit 80072bf

File tree

2 files changed

+38
-29
lines changed

2 files changed

+38
-29
lines changed

__tests__/workers/cdc/primary.ts

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6908,13 +6908,14 @@ describe('user_candidate_preference', () => {
69086908
});
69096909

69106910
it('should trigger candidate preference change event on creation', async () => {
6911+
const cv = {
6912+
blob: 'https://example.com/cv.pdf',
6913+
lastModified: new Date('2023-01-01'),
6914+
};
69116915
const candidatePreferenceData = {
69126916
userId: '1',
69136917
status: CandidateStatus.OPEN_TO_OFFERS,
6914-
cv: {
6915-
blob: 'https://example.com/cv.pdf',
6916-
lastModified: new Date('2023-01-01'),
6917-
},
6918+
cv,
69186919
cvParsed: {},
69196920
role: 'Senior Full Stack Developer',
69206921
roleType: 0.8,
@@ -6943,7 +6944,7 @@ describe('user_candidate_preference', () => {
69436944
await expectSuccessfulBackground(
69446945
worker,
69456946
mockChangeMessage<UserCandidatePreference>({
6946-
after: candidatePreferenceData,
6947+
after: { ...candidatePreferenceData, cv: JSON.stringify(cv) },
69476948
op: 'c',
69486949
table: 'user_candidate_preference',
69496950
}),
@@ -6956,14 +6957,15 @@ describe('user_candidate_preference', () => {
69566957
});
69576958

69586959
it('should trigger candidate preference change event on update', async () => {
6960+
const cv = {
6961+
blob: 'https://example.com/cv.pdf',
6962+
lastModified: new Date('2023-01-01'),
6963+
};
69596964
const originalData = {
69606965
userId: '1',
69616966
status: CandidateStatus.OPEN_TO_OFFERS,
69626967
cvParsed: {},
6963-
cv: {
6964-
blob: 'https://example.com/cv.pdf',
6965-
lastModified: new Date('2023-01-01'),
6966-
},
6968+
cv,
69676969
role: 'Senior Full Stack Developer',
69686970
roleType: 0.8,
69696971
employmentType: [0], // EmploymentType.FULL_TIME
@@ -6996,11 +6998,12 @@ describe('user_candidate_preference', () => {
69966998
// Create the UserCandidatePreference record
69976999
await con.getRepository(UserCandidatePreference).save(updatedData);
69987000

7001+
const cvStr = JSON.stringify(cv);
69997002
await expectSuccessfulBackground(
70007003
worker,
70017004
mockChangeMessage<UserCandidatePreference>({
7002-
before: originalData,
7003-
after: updatedData,
7005+
before: { ...originalData, cv: cvStr },
7006+
after: { ...updatedData, cv: cvStr },
70047007
op: 'u',
70057008
table: 'user_candidate_preference',
70067009
}),
@@ -7017,10 +7020,10 @@ describe('user_candidate_preference', () => {
70177020
userId: '1',
70187021
status: CandidateStatus.OPEN_TO_OFFERS,
70197022
cvParsed: {},
7020-
cv: {
7023+
cv: JSON.stringify({
70217024
blob: 'https://example.com/cv.pdf',
70227025
lastModified: new Date('2023-01-01'),
7023-
},
7026+
}),
70247027
role: 'Senior Full Stack Developer',
70257028
roleType: 0.8,
70267029
employmentType: [0], // EmploymentType.FULL_TIME
@@ -7057,10 +7060,10 @@ describe('user_candidate_preference', () => {
70577060
userId: '1',
70587061
status: CandidateStatus.OPEN_TO_OFFERS,
70597062
cvParsed: {},
7060-
cv: {
7063+
cv: JSON.stringify({
70617064
blob: 'https://example.com/cv.pdf',
70627065
lastModified: new Date('2023-01-01'),
7063-
},
7066+
}),
70647067
role: 'Senior Full Stack Developer',
70657068
roleType: 0.8,
70667069
employmentType: [0], // EmploymentType.FULL_TIME
@@ -7093,13 +7096,14 @@ describe('user_candidate_preference', () => {
70937096
});
70947097

70957098
it('should handle disabled candidate status', async () => {
7099+
const cv = {
7100+
blob: '',
7101+
lastModified: new Date('2023-01-01'),
7102+
};
70967103
const candidatePreferenceData = {
70977104
userId: '2',
70987105
status: CandidateStatus.DISABLED,
7099-
cv: {
7100-
blob: '',
7101-
lastModified: new Date('2023-01-01'),
7102-
},
7106+
cv,
71037107
role: '',
71047108
roleType: 0.5,
71057109
employmentType: [],
@@ -7119,7 +7123,7 @@ describe('user_candidate_preference', () => {
71197123
await expectSuccessfulBackground(
71207124
worker,
71217125
mockChangeMessage<UserCandidatePreference>({
7122-
after: candidatePreferenceData,
7126+
after: { ...candidatePreferenceData, cv: JSON.stringify(cv) },
71237127
op: 'c',
71247128
table: 'user_candidate_preference',
71257129
}),
@@ -7140,10 +7144,10 @@ describe('user_candidate_preference', () => {
71407144
userId: 'non-existent-user',
71417145
status: CandidateStatus.OPEN_TO_OFFERS,
71427146
cvParsed: {},
7143-
cv: {
7147+
cv: JSON.stringify({
71447148
blob: 'https://example.com/cv.pdf',
71457149
lastModified: new Date('2023-01-01'),
7146-
},
7150+
}),
71477151
role: 'Senior Developer',
71487152
roleType: 0.8,
71497153
employmentType: [0],
@@ -7167,14 +7171,15 @@ describe('user_candidate_preference', () => {
71677171
});
71687172

71697173
it('should handle complex employment types and locations', async () => {
7174+
const cv = {
7175+
blob: 'https://example.com/cv.pdf',
7176+
lastModified: new Date('2023-01-01'),
7177+
};
71707178
const candidatePreferenceData = {
71717179
userId: '3',
71727180
status: CandidateStatus.OPEN_TO_OFFERS,
71737181
cvParsed: {},
7174-
cv: {
7175-
blob: 'https://example.com/cv.pdf',
7176-
lastModified: new Date('2023-01-01'),
7177-
},
7182+
cv,
71787183
role: 'Full Stack Engineer',
71797184
roleType: 0.9,
71807185
employmentType: [0, 1, 2], // Multiple employment types
@@ -7207,7 +7212,7 @@ describe('user_candidate_preference', () => {
72077212
await expectSuccessfulBackground(
72087213
worker,
72097214
mockChangeMessage<UserCandidatePreference>({
7210-
after: candidatePreferenceData,
7215+
after: { ...candidatePreferenceData, cv: JSON.stringify(cv) },
72117216
op: 'u',
72127217
table: 'user_candidate_preference',
72137218
}),

src/workers/cdc/primary.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,8 +1772,12 @@ const onUserCandidatePreferenceChange = async (
17721772
});
17731773

17741774
// cv field has a blob when uploaded
1775-
const cv = data.payload.after!.cv as { blob?: string } | undefined;
1776-
const previousCv = data.payload.before?.cv as { blob?: string } | undefined;
1775+
const cv = JSON.parse(
1776+
(data.payload.after!.cv as unknown as string) || '{}',
1777+
) as { blob?: string };
1778+
const previousCv = JSON.parse(
1779+
(data.payload.before?.cv as unknown as string) || '{}',
1780+
) as { blob?: string };
17771781
const hasCvBlob = cv?.blob;
17781782
const hadPreviousCvBlob = previousCv?.blob;
17791783

0 commit comments

Comments
 (0)