Skip to content

Commit 55c7e26

Browse files
committed
feat: unsupported parsing domains
1 parent 07b700b commit 55c7e26

2 files changed

Lines changed: 77 additions & 5 deletions

File tree

__tests__/schema/opportunity.ts

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import * as brokkrCommon from '../../src/common/brokkr';
8989
import { updateRecruiterSubscriptionFlags } from '../../src/common';
9090
import { SubscriptionStatus } from '../../src/common/plus';
9191
import { OpportunityPreviewStatus } from '../../src/common/opportunity/types';
92+
import { unsupportedOpportunityDomains } from '../../src/common/schema/opportunities';
9293

9394
// Mock Slack WebClient
9495
const mockConversationsCreate = jest.fn();
@@ -5387,7 +5388,7 @@ describe('mutation parseOpportunity', () => {
53875388
expect(body.errors).toBeDefined();
53885389
expect(body.errors[0].extensions.code).toBe('ZOD_VALIDATION_ERROR');
53895390
expect(body.errors[0].extensions.issues[0].message).toEqual(
5390-
'Only one of url or file can be provided.',
5391+
'Only one of url or file can be provided for job description.',
53915392
);
53925393
});
53935394

@@ -5409,7 +5410,7 @@ describe('mutation parseOpportunity', () => {
54095410
expect(body.errors).toBeDefined();
54105411
expect(body.errors[0].extensions.code).toBe('ZOD_VALIDATION_ERROR');
54115412
expect(body.errors[0].extensions.issues[0].message).toEqual(
5412-
'Either url or file must be provided.',
5413+
'Either url or file must be provided for job description.',
54135414
);
54145415
});
54155416

@@ -5678,6 +5679,59 @@ describe('mutation parseOpportunity', () => {
56785679
'550e8400-e29b-41d4-a716-446655440000',
56795680
);
56805681
});
5682+
5683+
it('should throw when trying to parse opportunities from unsupported domain', async () => {
5684+
trackingId = 'anon1';
5685+
5686+
const fetchSpy = jest.spyOn(globalThis, 'fetch');
5687+
5688+
const pdfResponse = new Response('Mocked fetch response body', {
5689+
status: 200,
5690+
headers: { 'Content-Type': 'application/pdf' },
5691+
});
5692+
5693+
jest
5694+
.spyOn(pdfResponse, 'arrayBuffer')
5695+
.mockResolvedValue(new ArrayBuffer(0));
5696+
5697+
fetchSpy.mockResolvedValue(pdfResponse);
5698+
5699+
fileTypeFromBuffer.mockResolvedValue({
5700+
ext: 'pdf',
5701+
mime: 'application/pdf',
5702+
});
5703+
5704+
for await (const unsupportedDomain of unsupportedOpportunityDomains) {
5705+
// Execute the mutation with a URL
5706+
const res = await authorizeRequest(
5707+
request(app.server)
5708+
.post('/graphql')
5709+
.send({
5710+
query: MUTATION,
5711+
variables: {
5712+
payload: {
5713+
url: `https://${unsupportedDomain}/job`,
5714+
},
5715+
},
5716+
}),
5717+
).expect(200);
5718+
5719+
const body = res.body;
5720+
expect(body.errors).toBeTruthy();
5721+
5722+
expect(body.errors[0].extensions).toEqual({
5723+
code: 'ZOD_VALIDATION_ERROR',
5724+
issues: [
5725+
{
5726+
code: 'custom',
5727+
message:
5728+
'We currently cannot parse jobs from this domain, you can still upload your job description as a file.',
5729+
path: ['url'],
5730+
},
5731+
],
5732+
});
5733+
}
5734+
});
56815735
});
56825736

56835737
describe('mutation createSharedSlackChannel', () => {

src/common/schema/opportunities.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,27 @@ export const opportunityUpdateStateSchema = z.object({
243243
state: z.enum(OpportunityState),
244244
});
245245

246+
export const unsupportedOpportunityDomains = ['linkedin.com'];
247+
246248
export const parseOpportunitySchema = z
247249
.object({
248-
url: urlParseSchema.optional(),
250+
url: urlParseSchema.optional().refine(
251+
(url) => {
252+
if (!url) {
253+
return true;
254+
}
255+
256+
return !unsupportedOpportunityDomains.some(
257+
(domain) =>
258+
url.startsWith(`https://${domain}`) ||
259+
url.startsWith(`https://www.${domain}`),
260+
);
261+
},
262+
{
263+
error:
264+
'We currently cannot parse jobs from this domain, you can still upload your job description as a file.',
265+
},
266+
),
249267
file: fileUploadSchema.optional(),
250268
})
251269
.refine(
@@ -257,7 +275,7 @@ export const parseOpportunitySchema = z
257275
return true;
258276
},
259277
{
260-
error: 'Either url or file must be provided.',
278+
error: 'Either url or file must be provided for job description.',
261279
},
262280
)
263281
.refine(
@@ -269,7 +287,7 @@ export const parseOpportunitySchema = z
269287
return true;
270288
},
271289
{
272-
error: 'Only one of url or file can be provided.',
290+
error: 'Only one of url or file can be provided for job description.',
273291
},
274292
);
275293

0 commit comments

Comments
 (0)