Skip to content

Commit e68c847

Browse files
feat: allow team members to view opportunity drafts (#3246)
Co-authored-by: Chris Bongers <chrisbongers@gmail.com>
1 parent 52abe77 commit e68c847

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

__tests__/schema/opportunity.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,19 @@ let app: FastifyInstance;
7777
let state: GraphQLTestingState;
7878
let client: GraphQLTestClient;
7979
let loggedUser: string | null = null;
80+
let isTeamMember = false;
8081

8182
beforeAll(async () => {
8283
con = await createOrGetConnection();
8384
state = await initializeGraphQLTesting(
84-
() => new MockContext(con, loggedUser) as unknown as Context,
85+
(req) =>
86+
new MockContext(
87+
con,
88+
loggedUser || undefined,
89+
[],
90+
req,
91+
isTeamMember,
92+
) as Context,
8593
);
8694
client = state.client;
8795
app = state.app;
@@ -304,6 +312,8 @@ describe('query opportunityById', () => {
304312
});
305313

306314
it('should return null for non-live opportunity when user is not a recruiter', async () => {
315+
loggedUser = '2';
316+
307317
await con
308318
.getRepository(Opportunity)
309319
.update(
@@ -317,7 +327,7 @@ describe('query opportunityById', () => {
317327
query: OPPORTUNITY_BY_ID_QUERY,
318328
variables: { id: '550e8400-e29b-41d4-a716-446655440001' },
319329
},
320-
'NOT_FOUND',
330+
'FORBIDDEN',
321331
);
322332
});
323333

@@ -358,6 +368,28 @@ describe('query opportunityById', () => {
358368
'550e8400-e29b-41d4-a716-446655440001',
359369
);
360370
});
371+
372+
it('should return non-live opportunity if user is a team member', async () => {
373+
loggedUser = '2';
374+
isTeamMember = true;
375+
376+
await con
377+
.getRepository(Opportunity)
378+
.update(
379+
{ id: '550e8400-e29b-41d4-a716-446655440001' },
380+
{ state: OpportunityState.DRAFT },
381+
);
382+
383+
const res = await client.query(OPPORTUNITY_BY_ID_QUERY, {
384+
variables: { id: '550e8400-e29b-41d4-a716-446655440001' },
385+
});
386+
387+
expect(res.errors).toBeFalsy();
388+
389+
expect(res.data.opportunityById.id).toEqual(
390+
'550e8400-e29b-41d4-a716-446655440001',
391+
);
392+
});
361393
});
362394

363395
describe('query getOpportunityMatch', () => {

src/schema/opportunity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
380380
},
381381
);
382382

383-
if (opportunity.state !== OpportunityState.LIVE) {
383+
if (opportunity.state !== OpportunityState.LIVE && !ctx.isTeamMember) {
384384
if (!ctx.userId) {
385385
throw new NotFoundError('Not found!');
386386
}

0 commit comments

Comments
 (0)