diff --git a/__tests__/schema/opportunity.ts b/__tests__/schema/opportunity.ts index b30f7f3553..9cc5b89af0 100644 --- a/__tests__/schema/opportunity.ts +++ b/__tests__/schema/opportunity.ts @@ -420,40 +420,6 @@ describe('query getOpportunityMatch', () => { }); }); - it('should clear alert when alert matches opportunityId', async () => { - loggedUser = '1'; - - await saveFixtures(con, Alerts, [ - { - userId: '1', - opportunityId: '550e8400-e29b-41d4-a716-446655440001', - }, - ]); - - const res = await client.query(GET_OPPORTUNITY_MATCH_QUERY, { - variables: { id: '550e8400-e29b-41d4-a716-446655440001' }, - }); - - expect(res.errors).toBeFalsy(); - expect(res.data.getOpportunityMatch).toEqual({ - status: 'pending', - description: { - reasoning: 'Interested candidate', - }, - }); - expect( - await con.getRepository(Alerts).countBy({ - userId: '1', - opportunityId: '550e8400-e29b-41d4-a716-446655440001', - }), - ).toEqual(0); - expect( - await con - .getRepository(Alerts) - .countBy({ userId: '1', opportunityId: IsNull() }), - ).toEqual(1); - }); - it('should not clear alert when alert does not match opportunityId', async () => { loggedUser = '1'; @@ -1147,6 +1113,38 @@ describe('mutation acceptOpportunityMatch', () => { ).toEqual(1); }); + it('should clear alert when accepting opportunity match', async () => { + loggedUser = '1'; + + await saveFixtures(con, Alerts, [ + { + userId: '1', + opportunityId: '550e8400-e29b-41d4-a716-446655440001', + }, + ]); + + const res = await client.mutate(MUTATION, { + variables: { + id: '550e8400-e29b-41d4-a716-446655440001', + }, + }); + + expect(res.errors).toBeFalsy(); + expect(res.data.acceptOpportunityMatch).toEqual({ _: true }); + + expect( + await con.getRepository(Alerts).countBy({ + userId: '1', + opportunityId: '550e8400-e29b-41d4-a716-446655440001', + }), + ).toEqual(0); + expect( + await con + .getRepository(Alerts) + .countBy({ userId: '1', opportunityId: IsNull() }), + ).toEqual(1); + }); + it('should return error when the match is not pending', async () => { loggedUser = '2'; @@ -1231,6 +1229,38 @@ describe('mutation rejectOpportunityMatch', () => { ).toEqual(1); }); + it('should clear alert when rejecting opportunity match', async () => { + loggedUser = '1'; + + await saveFixtures(con, Alerts, [ + { + userId: '1', + opportunityId: '550e8400-e29b-41d4-a716-446655440001', + }, + ]); + + const res = await client.mutate(MUTATION, { + variables: { + id: '550e8400-e29b-41d4-a716-446655440001', + }, + }); + + expect(res.errors).toBeFalsy(); + expect(res.data.rejectOpportunityMatch).toEqual({ _: true }); + + expect( + await con.getRepository(Alerts).countBy({ + userId: '1', + opportunityId: '550e8400-e29b-41d4-a716-446655440001', + }), + ).toEqual(0); + expect( + await con + .getRepository(Alerts) + .countBy({ userId: '1', opportunityId: IsNull() }), + ).toEqual(1); + }); + it('should return error when the match is not pending', async () => { loggedUser = '2'; diff --git a/src/schema/opportunity.ts b/src/schema/opportunity.ts index 7d4338817c..79842e6d2f 100644 --- a/src/schema/opportunity.ts +++ b/src/schema/opportunity.ts @@ -408,7 +408,7 @@ export const resolvers: IResolvers = traceResolvers< ctx: AuthContext, info, ): Promise => { - const match = await graphorm.queryOneOrFail( + return await graphorm.queryOneOrFail( ctx, info, (builder) => { @@ -418,18 +418,6 @@ export const resolvers: IResolvers = traceResolvers< return builder; }, ); - - await ctx.con.getRepository(Alerts).update( - { - userId: ctx.userId, - opportunityId: id, - }, - { - opportunityId: null, - }, - ); - - return match; }, getCandidatePreferences: async ( _, @@ -607,6 +595,16 @@ export const resolvers: IResolvers = traceResolvers< }, ); + await con.getRepository(Alerts).update( + { + userId, + opportunityId: id, + }, + { + opportunityId: null, + }, + ); + return { _: true }; }, rejectOpportunityMatch: async ( @@ -659,6 +657,16 @@ export const resolvers: IResolvers = traceResolvers< }, ); + await con.getRepository(Alerts).update( + { + userId, + opportunityId: id, + }, + { + opportunityId: null, + }, + ); + return { _: true }; }, candidateAddKeywords: async (