Skip to content

Commit b4e01fc

Browse files
authored
fix: opportunity nudge reset (#3261)
1 parent 40da5ac commit b4e01fc

2 files changed

Lines changed: 85 additions & 47 deletions

File tree

__tests__/schema/opportunity.ts

Lines changed: 64 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -420,40 +420,6 @@ describe('query getOpportunityMatch', () => {
420420
});
421421
});
422422

423-
it('should clear alert when alert matches opportunityId', async () => {
424-
loggedUser = '1';
425-
426-
await saveFixtures(con, Alerts, [
427-
{
428-
userId: '1',
429-
opportunityId: '550e8400-e29b-41d4-a716-446655440001',
430-
},
431-
]);
432-
433-
const res = await client.query(GET_OPPORTUNITY_MATCH_QUERY, {
434-
variables: { id: '550e8400-e29b-41d4-a716-446655440001' },
435-
});
436-
437-
expect(res.errors).toBeFalsy();
438-
expect(res.data.getOpportunityMatch).toEqual({
439-
status: 'pending',
440-
description: {
441-
reasoning: 'Interested candidate',
442-
},
443-
});
444-
expect(
445-
await con.getRepository(Alerts).countBy({
446-
userId: '1',
447-
opportunityId: '550e8400-e29b-41d4-a716-446655440001',
448-
}),
449-
).toEqual(0);
450-
expect(
451-
await con
452-
.getRepository(Alerts)
453-
.countBy({ userId: '1', opportunityId: IsNull() }),
454-
).toEqual(1);
455-
});
456-
457423
it('should not clear alert when alert does not match opportunityId', async () => {
458424
loggedUser = '1';
459425

@@ -1147,6 +1113,38 @@ describe('mutation acceptOpportunityMatch', () => {
11471113
).toEqual(1);
11481114
});
11491115

1116+
it('should clear alert when accepting opportunity match', async () => {
1117+
loggedUser = '1';
1118+
1119+
await saveFixtures(con, Alerts, [
1120+
{
1121+
userId: '1',
1122+
opportunityId: '550e8400-e29b-41d4-a716-446655440001',
1123+
},
1124+
]);
1125+
1126+
const res = await client.mutate(MUTATION, {
1127+
variables: {
1128+
id: '550e8400-e29b-41d4-a716-446655440001',
1129+
},
1130+
});
1131+
1132+
expect(res.errors).toBeFalsy();
1133+
expect(res.data.acceptOpportunityMatch).toEqual({ _: true });
1134+
1135+
expect(
1136+
await con.getRepository(Alerts).countBy({
1137+
userId: '1',
1138+
opportunityId: '550e8400-e29b-41d4-a716-446655440001',
1139+
}),
1140+
).toEqual(0);
1141+
expect(
1142+
await con
1143+
.getRepository(Alerts)
1144+
.countBy({ userId: '1', opportunityId: IsNull() }),
1145+
).toEqual(1);
1146+
});
1147+
11501148
it('should return error when the match is not pending', async () => {
11511149
loggedUser = '2';
11521150

@@ -1231,6 +1229,38 @@ describe('mutation rejectOpportunityMatch', () => {
12311229
).toEqual(1);
12321230
});
12331231

1232+
it('should clear alert when rejecting opportunity match', async () => {
1233+
loggedUser = '1';
1234+
1235+
await saveFixtures(con, Alerts, [
1236+
{
1237+
userId: '1',
1238+
opportunityId: '550e8400-e29b-41d4-a716-446655440001',
1239+
},
1240+
]);
1241+
1242+
const res = await client.mutate(MUTATION, {
1243+
variables: {
1244+
id: '550e8400-e29b-41d4-a716-446655440001',
1245+
},
1246+
});
1247+
1248+
expect(res.errors).toBeFalsy();
1249+
expect(res.data.rejectOpportunityMatch).toEqual({ _: true });
1250+
1251+
expect(
1252+
await con.getRepository(Alerts).countBy({
1253+
userId: '1',
1254+
opportunityId: '550e8400-e29b-41d4-a716-446655440001',
1255+
}),
1256+
).toEqual(0);
1257+
expect(
1258+
await con
1259+
.getRepository(Alerts)
1260+
.countBy({ userId: '1', opportunityId: IsNull() }),
1261+
).toEqual(1);
1262+
});
1263+
12341264
it('should return error when the match is not pending', async () => {
12351265
loggedUser = '2';
12361266

src/schema/opportunity.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
408408
ctx: AuthContext,
409409
info,
410410
): Promise<GQLOpportunityMatch> => {
411-
const match = await graphorm.queryOneOrFail<GQLOpportunityMatch>(
411+
return await graphorm.queryOneOrFail<GQLOpportunityMatch>(
412412
ctx,
413413
info,
414414
(builder) => {
@@ -418,18 +418,6 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
418418
return builder;
419419
},
420420
);
421-
422-
await ctx.con.getRepository(Alerts).update(
423-
{
424-
userId: ctx.userId,
425-
opportunityId: id,
426-
},
427-
{
428-
opportunityId: null,
429-
},
430-
);
431-
432-
return match;
433421
},
434422
getCandidatePreferences: async (
435423
_,
@@ -607,6 +595,16 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
607595
},
608596
);
609597

598+
await con.getRepository(Alerts).update(
599+
{
600+
userId,
601+
opportunityId: id,
602+
},
603+
{
604+
opportunityId: null,
605+
},
606+
);
607+
610608
return { _: true };
611609
},
612610
rejectOpportunityMatch: async (
@@ -659,6 +657,16 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
659657
},
660658
);
661659

660+
await con.getRepository(Alerts).update(
661+
{
662+
userId,
663+
opportunityId: id,
664+
},
665+
{
666+
opportunityId: null,
667+
},
668+
);
669+
662670
return { _: true };
663671
},
664672
candidateAddKeywords: async (

0 commit comments

Comments
 (0)