@@ -89,6 +89,7 @@ import * as brokkrCommon from '../../src/common/brokkr';
8989import { updateRecruiterSubscriptionFlags } from '../../src/common' ;
9090import { SubscriptionStatus } from '../../src/common/plus' ;
9191import { OpportunityPreviewStatus } from '../../src/common/opportunity/types' ;
92+ import { unsupportedOpportunityDomains } from '../../src/common/schema/opportunities' ;
9293
9394// Mock Slack WebClient
9495const 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
56835737describe ( 'mutation createSharedSlackChannel' , ( ) => {
0 commit comments