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
84 changes: 84 additions & 0 deletions __tests__/schema/opportunity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,90 @@ describe('mutation acceptOpportunityMatch', () => {
});
});

describe('mutation rejectOpportunityMatch', () => {
const MUTATION = /* GraphQL */ `
mutation RejectOpportunityMatch($id: ID!) {
rejectOpportunityMatch(id: $id) {
_
}
}
`;

it('should require authentication', async () => {
await testMutationErrorCode(
client,
{
mutation: MUTATION,
variables: {
id: '550e8400-e29b-41d4-a716-446655440001',
},
},
'UNAUTHENTICATED',
);
});

it('should accept opportunity match for authenticated user', async () => {
loggedUser = '1';

expect(
await con.getRepository(OpportunityMatch).countBy({
opportunityId: '550e8400-e29b-41d4-a716-446655440001',
userId: '1',
status: OpportunityMatchStatus.Pending,
}),
).toEqual(1);

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(OpportunityMatch).countBy({
opportunityId: '550e8400-e29b-41d4-a716-446655440001',
userId: '1',
status: OpportunityMatchStatus.CandidateRejected,
}),
).toEqual(1);
});

it('should return error when the match is not pending', async () => {
loggedUser = '2';

await testMutationErrorCode(
client,
{
mutation: MUTATION,
variables: {
id: '550e8400-e29b-41d4-a716-446655440001',
},
},
'FORBIDDEN',
'Access denied! Match is not pending',
);
});

it('should return error when the opportunity is not live', async () => {
loggedUser = '1';

await testMutationErrorCode(
client,
{
mutation: MUTATION,
variables: {
id: '550e8400-e29b-41d4-a716-446655440003',
},
},
'FORBIDDEN',
'Access denied! Opportunity is not live',
);
});
});

describe('mutation candidateAddKeywords', () => {
const MUTATION = /* GraphQL */ `
mutation CandidateAddKeywords($keywords: [String!]!) {
Expand Down
59 changes: 59 additions & 0 deletions src/schema/opportunity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ export const typeDefs = /* GraphQL */ `
id: ID!
): EmptyResponse @auth

rejectOpportunityMatch(
"""
Id of the Opportunity
"""
id: ID!
): EmptyResponse @auth

candidateAddKeywords(
"""
Keywords to add to candidate profile
Expand Down Expand Up @@ -602,6 +609,58 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<

return { _: true };
},
rejectOpportunityMatch: async (
_,
{ id }: { id: string },
{ userId, con, log }: AuthContext,
): Promise<GQLEmptyResponse> => {
const match = await con.getRepository(OpportunityMatch).findOne({
where: {
opportunityId: id,
userId,
},
relations: {
opportunity: true,
},
});

if (!match) {
log.error(
{ opportunityId: id, userId },
'No match found for opportunity',
);
throw new ForbiddenError('Access denied! No match found');
}

if (match.status !== OpportunityMatchStatus.Pending) {
log.error(
{ opportunityId: id, userId, status: match.status },
'Match is not pending',
);
throw new ForbiddenError(`Access denied! Match is not pending`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does pending match mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"new match" where the user has not interacted with it.

}

const opportunity = await match.opportunity;
if (opportunity.state !== OpportunityState.LIVE) {
log.error(
{ opportunityId: id, userId, state: opportunity.state },
'Opportunity is not live',
);
throw new ForbiddenError(`Access denied! Opportunity is not live`);
}

await con.getRepository(OpportunityMatch).update(
{
opportunityId: id,
userId,
},
{
status: OpportunityMatchStatus.CandidateRejected,
},
);

return { _: true };
},
candidateAddKeywords: async (
_,
payload: z.infer<typeof userCandidateToggleKeywordSchema>,
Expand Down
Loading