|
2 | 2 | expectSuccessfulTypedBackground, |
3 | 3 | saveFixtures, |
4 | 4 | createMockBrokkrTransport, |
| 5 | + createMockBrokkrParseGeneralErrorTransport, |
5 | 6 | createGarmrMock, |
6 | 7 | } from '../../helpers'; |
7 | 8 | import { parseOpportunityWorker as worker } from '../../../src/workers/opportunity/parseOpportunity'; |
@@ -285,6 +286,7 @@ describe('parseOpportunity worker', () => { |
285 | 286 |
|
286 | 287 | expect(opportunity!.state).toBe(OpportunityState.ERROR); |
287 | 288 | expect(opportunity!.flags?.parseError).toContain('Brokkr parsing failed'); |
| 289 | + expect(opportunity!.flags?.parseErrorUserMessage).toBeUndefined(); |
288 | 290 | }); |
289 | 291 |
|
290 | 292 | it('should skip if state is not PARSING', async () => { |
@@ -609,6 +611,60 @@ describe('parseOpportunity worker', () => { |
609 | 611 | expect(recruiter).toBeNull(); |
610 | 612 | }); |
611 | 613 |
|
| 614 | + it('should set ERROR state with parseError when Brokkr returns general error', async () => { |
| 615 | + jest.restoreAllMocks(); |
| 616 | + |
| 617 | + const transport = createMockBrokkrParseGeneralErrorTransport( |
| 618 | + 'The document is a list of multiple job opportunities, not a detailed description of a single one', |
| 619 | + ); |
| 620 | + |
| 621 | + jest.spyOn(brokkrCommon, 'getBrokkrClient').mockImplementation( |
| 622 | + (): ServiceClient<typeof BrokkrService> => ({ |
| 623 | + instance: createClient(BrokkrService, transport), |
| 624 | + garmr: createGarmrMock(), |
| 625 | + }), |
| 626 | + ); |
| 627 | + |
| 628 | + mockStorageDownload.mockResolvedValue([Buffer.from('mock-pdf-content')]); |
| 629 | + mockStorageExists.mockResolvedValue([true]); |
| 630 | + |
| 631 | + await con.getRepository(OpportunityJob).save({ |
| 632 | + id: testOpportunityId, |
| 633 | + type: OpportunityType.JOB, |
| 634 | + state: OpportunityState.PARSING, |
| 635 | + title: 'Processing...', |
| 636 | + tldr: '', |
| 637 | + content: new OpportunityContent({}), |
| 638 | + flags: { |
| 639 | + batchSize: 100, |
| 640 | + file: { |
| 641 | + blobName: testBlobName, |
| 642 | + bucketName: RESUME_BUCKET_NAME, |
| 643 | + mimeType: 'application/pdf', |
| 644 | + extension: 'pdf', |
| 645 | + userId: testUserId, |
| 646 | + trackingId: 'anon1', |
| 647 | + }, |
| 648 | + }, |
| 649 | + }); |
| 650 | + |
| 651 | + await expectSuccessfulTypedBackground<'api.v1.opportunity-parse'>(worker, { |
| 652 | + opportunityId: testOpportunityId, |
| 653 | + }); |
| 654 | + |
| 655 | + const opportunity = await con.getRepository(OpportunityJob).findOne({ |
| 656 | + where: { id: testOpportunityId }, |
| 657 | + }); |
| 658 | + |
| 659 | + expect(opportunity!.state).toBe(OpportunityState.ERROR); |
| 660 | + expect(opportunity!.flags?.parseError).toBe( |
| 661 | + 'The document is a list of multiple job opportunities, not a detailed description of a single one', |
| 662 | + ); |
| 663 | + expect(opportunity!.flags?.parseErrorUserMessage).toBe( |
| 664 | + 'The document is a list of multiple job opportunities, not a detailed description of a single one', |
| 665 | + ); |
| 666 | + }); |
| 667 | + |
612 | 668 | it('should assign Europe as continent when no country specified', async () => { |
613 | 669 | // Create a custom mock with just continent: 'Europe' (no country) |
614 | 670 | const transport = createMockBrokkrTransport({ |
|
0 commit comments