Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 64 additions & 34 deletions __tests__/schema/opportunity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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';

Expand Down
34 changes: 21 additions & 13 deletions src/schema/opportunity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
ctx: AuthContext,
info,
): Promise<GQLOpportunityMatch> => {
const match = await graphorm.queryOneOrFail<GQLOpportunityMatch>(
return await graphorm.queryOneOrFail<GQLOpportunityMatch>(
ctx,
info,
(builder) => {
Expand All @@ -418,18 +418,6 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
return builder;
},
);

await ctx.con.getRepository(Alerts).update(
{
userId: ctx.userId,
opportunityId: id,
},
{
opportunityId: null,
},
);

return match;
},
getCandidatePreferences: async (
_,
Expand Down Expand Up @@ -607,6 +595,16 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
},
);

await con.getRepository(Alerts).update(
{
userId,
opportunityId: id,
},
{
opportunityId: null,
},
);

return { _: true };
},
rejectOpportunityMatch: async (
Expand Down Expand Up @@ -659,6 +657,16 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
},
);

await con.getRepository(Alerts).update(
{
userId,
opportunityId: id,
},
{
opportunityId: null,
},
);

return { _: true };
},
candidateAddKeywords: async (
Expand Down
Loading