Skip to content

Commit a252c9b

Browse files
authored
feat: opportunity map europe (#3389)
1 parent 15c089c commit a252c9b

5 files changed

Lines changed: 120 additions & 5 deletions

File tree

__tests__/helpers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,11 @@ export const doNotFake: FakeableAPI[] = [
453453
'clearTimeout',
454454
];
455455

456-
export const createMockBrokkrTransport = () =>
456+
export const createMockBrokkrTransport = ({
457+
opportunity,
458+
}: {
459+
opportunity?: Partial<ParseOpportunityResponse['opportunity']>;
460+
} = {}) =>
457461
createRouterTransport(({ service }) => {
458462
service(BrokkrService, {
459463
extractMarkdown: (request) => {
@@ -527,6 +531,7 @@ export const createMockBrokkrTransport = () =>
527531
'This is the interview process of the mocked opportunity.',
528532
}),
529533
}),
534+
...opportunity,
530535
}),
531536
});
532537
},

__tests__/schema/opportunity.ts

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import {
6060
OpportunityType,
6161
SalaryPeriod,
6262
SeniorityLevel,
63+
Location,
6364
} from '@dailydotdev/schema';
6465
import { UserCandidatePreference } from '../../src/entity/user/UserCandidatePreference';
6566
import { QuestionScreening } from '../../src/entity/questions/QuestionScreening';
@@ -5625,8 +5626,6 @@ describe('mutation parseOpportunity', () => {
56255626

56265627
deleteFileFromBucketSpy.mockResolvedValue(true);
56275628

5628-
console.log(await con.getRepository(OpportunityUserRecruiter).find());
5629-
56305629
// Execute the mutation with a file upload
56315630
const res = await authorizeRequest(
56325631
request(app.server)
@@ -5664,6 +5663,106 @@ describe('mutation parseOpportunity', () => {
56645663
'550e8400-e29b-41d4-a716-446655440000',
56655664
);
56665665
});
5666+
5667+
it('should assign opportunity location to Europe when no country specified', async () => {
5668+
loggedUser = '1';
5669+
5670+
fileTypeFromBuffer.mockResolvedValue({
5671+
ext: 'pdf',
5672+
mime: 'application/pdf',
5673+
});
5674+
5675+
const uploadResumeFromBufferSpy = jest.spyOn(
5676+
googleCloud,
5677+
'uploadResumeFromBuffer',
5678+
);
5679+
5680+
uploadResumeFromBufferSpy.mockResolvedValue(
5681+
`https://storage.cloud.google.com/${RESUME_BUCKET_NAME}/file`,
5682+
);
5683+
5684+
const deleteFileFromBucketSpy = jest.spyOn(
5685+
googleCloud,
5686+
'deleteFileFromBucket',
5687+
);
5688+
5689+
deleteFileFromBucketSpy.mockResolvedValue(true);
5690+
5691+
const transport = createMockBrokkrTransport({
5692+
opportunity: {
5693+
location: [
5694+
new Location({
5695+
continent: 'Europe',
5696+
type: 1,
5697+
}),
5698+
],
5699+
},
5700+
});
5701+
5702+
const serviceClient = {
5703+
instance: createClient(BrokkrService, transport),
5704+
garmr: createGarmrMock(),
5705+
};
5706+
5707+
jest
5708+
.spyOn(brokkrCommon, 'getBrokkrClient')
5709+
.mockImplementation((): ServiceClient<typeof BrokkrService> => {
5710+
return serviceClient;
5711+
});
5712+
5713+
await saveFixtures(con, DatasetLocation, [
5714+
{
5715+
country: 'Europe',
5716+
iso2: 'EU',
5717+
iso3: 'EUR',
5718+
},
5719+
]);
5720+
5721+
// Execute the mutation with a file upload
5722+
const res = await authorizeRequest(
5723+
request(app.server)
5724+
.post('/graphql')
5725+
.field(
5726+
'operations',
5727+
JSON.stringify({
5728+
query: MUTATION,
5729+
variables: {
5730+
payload: {
5731+
file: null,
5732+
},
5733+
},
5734+
}),
5735+
)
5736+
.field('map', JSON.stringify({ '0': ['variables.payload.file'] }))
5737+
.attach('0', './__tests__/fixture/screen.pdf'),
5738+
).expect(200);
5739+
5740+
const body = res.body;
5741+
expect(body.errors).toBeFalsy();
5742+
5743+
expect(body.data.parseOpportunity).toMatchObject({
5744+
locations: [
5745+
{
5746+
location: {
5747+
city: null,
5748+
country: 'Europe',
5749+
subdivision: null,
5750+
},
5751+
type: 1,
5752+
},
5753+
],
5754+
});
5755+
5756+
const opportunity = await con.getRepository(OpportunityJob).findOne({
5757+
where: {
5758+
id: body.data.parseOpportunity.id,
5759+
},
5760+
});
5761+
5762+
expect(opportunity!.organizationId).toBe(
5763+
'550e8400-e29b-41d4-a716-446655440000',
5764+
);
5765+
});
56675766
});
56685767

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

src/common/opportunity/parse.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,17 @@ export async function parseOpportunityWithBrokkr(
205205
location: Array.isArray(result.opportunity?.location)
206206
? result.opportunity.location
207207
.map((loc) => {
208+
if (
209+
!loc.country &&
210+
loc.continent?.toLowerCase().trim() === 'europe'
211+
) {
212+
return {
213+
...loc,
214+
country: 'Europe',
215+
iso2: 'EU',
216+
};
217+
}
218+
208219
// Jobs may indicate Remote Europe with no country
209220
if (!loc?.country?.trim() && loc?.continent?.trim()) {
210221
return {

src/common/schema/opportunities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const createOpportunityEditContentSchema = ({
1717
}: {
1818
optional?: boolean;
1919
} = {}) => {
20-
const contentSchema = z.string().max(2000);
20+
const contentSchema = z.string().max(2500);
2121

2222
return z.object({
2323
content: optional ? contentSchema.optional() : contentSchema.nonempty(),

src/schema/opportunity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ export const typeDefs = /* GraphQL */ `
876876
Parse an opportunity from a URL or file upload
877877
"""
878878
parseOpportunity(payload: ParseOpportunityInput!): Opportunity!
879-
@rateLimit(limit: 5, duration: 3600)
879+
@rateLimit(limit: 10, duration: 3600)
880880
881881
"""
882882
Create a shared Slack channel and invite a user by email

0 commit comments

Comments
 (0)