Skip to content

Commit

Permalink
Sosynpl[premieroctet#120] WIP added tests, still needs to be finished
Browse files Browse the repository at this point in the history
  • Loading branch information
SeghirOumo committed Jul 12, 2024
1 parent 77622de commit 84b366b
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 10 deletions.
18 changes: 16 additions & 2 deletions backend/web/server/plugins/sosynpl/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ const lodash=require('lodash')
const CustomerFreelance = require("../../models/CustomerFreelance")
const User = require("../../models/User")
const { ROLE_FREELANCE, DEFAULT_SEARCH_RADIUS, AVAILABILITY_ON, ANNOUNCE_STATUS_ACTIVE, DURATION_FILTERS, WORK_MODE, WORK_MODE_SITE, WORK_MODE_REMOTE, WORK_MODE_REMOTE_SITE, WORK_DURATION_LESS_1_MONTH, WORK_DURATION_MORE_6_MONTH, WORK_DURATION__1_TO_6_MONTHS, MOBILITY_FRANCE, MOBILITY_NONE } = require("./consts")
const { buildPopulates, loadFromDb } = require('../../utils/database')
const { computeDistanceKm } = require('../../../utils/functions')
const Announce = require('../../models/Announce')
const { REGIONS_FULL } = require('../../../utils/consts')

const computeSuggestedFreelances = async (userId, params, data) => {
if( !data.job || !data.start_date){
console.log("missing attributes on announce")
return []
}
const MAP_WORKMODE = {
0: WORK_MODE_SITE,
5: WORK_MODE_REMOTE,
}

const workMode = MAP_WORKMODE[data.homework_days] || WORK_MODE_REMOTE_SITE;
const workMode = MAP_WORKMODE[data.homework_days] || WORK_MODE_REMOTE_SITE

const workDuration =
data._duration_days < 30
Expand Down Expand Up @@ -60,6 +63,13 @@ const computeSuggestedFreelances = async (userId, params, data) => {
else return {}
}

const availableFilter = {
$or: [
{available: true,},
{$lte: ['$available_from', data.start_date]}
]
}

const filter = {
main_job: data.job,
work_sector: { $in: data.sectors },
Expand All @@ -70,8 +80,12 @@ const computeSuggestedFreelances = async (userId, params, data) => {
work_mode: workMode,
work_duration: workDuration,
...mobilityFilter(),
...availableFilter,
}
return CustomerFreelance.find(filter)
/*TODO:
Sort by pilars
*/
}

const PROFILE_TEXT_SEARCH_FIELDS=['position', 'description', 'motivation']
Expand Down
134 changes: 126 additions & 8 deletions backend/web/tests/sosynpl/search.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,136 @@
const mongoose = require('mongoose')
const moment = require('moment')
const { MONGOOSE_OPTIONS } = require('../../server/utils/database')
const { faker } = require('@faker-js/faker')
const { MONGOOSE_OPTIONS, loadFromDb } = require('../../server/utils/database')
const Announce = require('../../server/models/Announce')
const Job = require('../../server/models/Job')
const Sector = require('../../server/models/Sector')
const Expertise = require('../../server/models/Expertise')
const Software = require('../../server/models/Software')
const LanguageLevel = require('../../server/models/LanguageLevel')
const CustomerFreelance = require('../../server/models/CustomerFreelance')
const SoftSkill = require('../../server/models/SoftSkill')
require('../../server/plugins/sosynpl/functions')
require('../../server/plugins/sosynpl/announce')
require('../../server/models/JobFile')
require('../../server/models/Application')

describe('Search', () => {
beforeAll(async() => {
const DBNAME=`test${moment().unix()}`
let job, sector, expertise1, expertise2, expertise3, software, language, announce, customerFreelance
let softSkillComm, softSkillConflict, softSkillTeamWork

beforeAll(async () => {
const DBNAME = `test${moment().unix()}`
await mongoose.connect(`mongodb://localhost/${DBNAME}`, MONGOOSE_OPTIONS)
const job = await Job.create({ name: 'Developer', job_file: new mongoose.Types.ObjectId() })
const announce = await Announce.create({

job = new mongoose.Types.ObjectId()
sector = await Sector.create({ name: 'IT' })
expertise1 = await Expertise.create({ name: 'JavaScript' })
expertise2 = await Expertise.create({ name: 'Java' })
expertise3 = await Expertise.create({ name: 'Python' })
software = await Software.create({ name: 'VS Code' })
language = await LanguageLevel.create({ language: 'fr', level: 'LANGUAGE_LEVEL_ADVANCED' })
softSkillComm = await SoftSkill.create({ name: 'Communication', value: 'SOFT_SKILL_COMM' })
softSkillTeamWork = await SoftSkill.create({ name: 'TeamWork', value: 'SOFT_SKILL_TEAMWORK'})
softSkillConflict = await SoftSkill.create({ name: 'Conflict', value: 'SOFT_SKILL_CONFLICT'})

announce = await Announce.create({
user: new mongoose.Types.ObjectId(),
job: job._id,
title: 'Looking for Dev'
job: job,
title: faker.name.jobTitle(),
experience: ['EXPERIENCE_EXPERT'],
start_date: moment(),
duration: faker.datatype.number({ min: 1, max: 12 }),
duration_unit: 'DURATION_MONTH',
sectors: [sector._id],
city: {
address: faker.address.streetAddress(),
city: faker.address.city(),
zip_code: faker.address.zipCode(),
country: faker.address.country()
},
homework_days: faker.datatype.number({ min: 0, max: 5 }),
mobility: 'MOBILITY_FRANCE',
mobility_days_per_month: faker.datatype.number({ min: 1, max: 30 }),
budget: faker.datatype.number({ min: 1000, max: 10000 }),
budget_hidden: faker.datatype.boolean(),
expertises: [expertise1._id, expertise2._id, expertise3._id],
pinned_expertises: [expertise1._id],
softwares: [software._id],
languages: [language._id],
gold_soft_skills: [softSkillComm._id],
silver_soft_skills: [softSkillTeamWork._id],
bronze_soft_skills: [softSkillConflict._id],
})

customerFreelance = await CustomerFreelance.create({
password: faker.internet.password(),
email: faker.internet.email(),
lastname: faker.name.lastName(),
firstname: faker.name.firstName(),
source: 'SOURCE_RECOMMANDATION',
curriculum: new mongoose.Types.ObjectId(),
experience: new mongoose.Types.ObjectId(),
motivation: faker.lorem.sentence(),
main_job: job,
gold_soft_skills: [softSkillComm._id],
silver_soft_skills: [softSkillTeamWork._id],
bronze_soft_skills: [softSkillConflict._id],
work_sector: [sector._id],
expertises: [expertise1._id],
siren: '923145171',
legal_status: 'EI',
company_name: faker.company.name(),
position: faker.name.jobTitle(),
softwares: [software._id],
languages: [language._id],
main_experience: 'EXPERIENCE_EXPERT',
work_mode: 'WORK_MODE_REMOTE_SITE',
work_duration: ['WORK_DURATION__1_TO_6_MONTHS'],
mobility: 'MOBILITY_FRANCE',
cgu_accepted: true,
phone: '0606060606',
address: {
address: faker.address.streetAddress(),
city: faker.address.city(),
zip_code: faker.address.zipCode(),
country: faker.address.country()
}
})
})

afterAll(async () => {
await mongoose.connection.dropDatabase()
await mongoose.connection.close()
})

test('should find suggested freelances based on announce criteria', async () => {
const suggestedFreelances = await loadFromDb({model:'announce', id:announce._id, fields:['suggested_freelances']})
expect(suggestedFreelances.length).toBeGreaterThan(0)
const johnDoe = suggestedFreelances.find(freelance => freelance.email === customerFreelance.email)
expect(johnDoe).toBeTruthy()
expect(johnDoe).toMatchObject({
email: customerFreelance.email,
lastname: customerFreelance.lastname,
firstname: customerFreelance.firstname,
source: customerFreelance.source,
motivation: customerFreelance.motivation,
main_job: customerFreelance.main_job,
work_sector: customerFreelance.work_sector,
expertises: customerFreelance.expertises,
siren: customerFreelance.siren,
legal_status: customerFreelance.legal_status,
company_name: customerFreelance.company_name,
position: customerFreelance.position,
softwares: customerFreelance.softwares,
languages: customerFreelance.languages,
main_experience: customerFreelance.main_experience,
work_mode: customerFreelance.work_mode,
work_duration: customerFreelance.work_duration,
mobility: customerFreelance.mobility,
cgu_accepted: customerFreelance.cgu_accepted,
phone: customerFreelance.phone,
address: customerFreelance.address
})
})
})
})

0 comments on commit 84b366b

Please sign in to comment.