From 79e4fad482cdbd9ed9957c0213ff311b98fa9da9 Mon Sep 17 00:00:00 2001 From: SeghirOumo Date: Tue, 16 Jul 2024 11:02:04 +0200 Subject: [PATCH] Sosynpl[#120]: changed announce regions to mobility_regions, test if mobility_city is known --- .../web/server/plugins/sosynpl/functions.js | 2 +- .../plugins/sosynpl/schemas/AnnounceSchema.js | 2 +- backend/web/server/plugins/sosynpl/search.js | 9 +-- backend/web/tests/sosynpl/evaluation.test.js | 64 +++++++++++++++++++ package.json | 5 ++ yarn.lock | 22 +++++++ 6 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 backend/web/tests/sosynpl/evaluation.test.js create mode 100644 package.json create mode 100644 yarn.lock diff --git a/backend/web/server/plugins/sosynpl/functions.js b/backend/web/server/plugins/sosynpl/functions.js index f197ea4ed8..ac9bea9bb2 100644 --- a/backend/web/server/plugins/sosynpl/functions.js +++ b/backend/web/server/plugins/sosynpl/functions.js @@ -292,7 +292,7 @@ declareVirtualField({model: 'announce', field: 'received_applications_count', in declareEnumField({model: 'announce', field: 'experience', enumValues: EXPERIENCE}) declareVirtualField({model: 'announce', field: 'average_daily_rate', instance: 'Number', requires:'duration,duration_unit,budget'}) declareVirtualField({model: 'announce', field: '_duration_days', instance: 'Number'}) -declareEnumField({model: 'announce', field: 'regions', enumValues: REGIONS}) +declareEnumField({model: 'announce', field: 'mobility_regions', enumValues: REGIONS}) // SOFT SKILLS declareComputedField({model: 'announce', field: 'available_gold_soft_skills', getterFn: computeAvailableGoldSoftSkills}) declareComputedField({model: 'announce', field: 'available_silver_soft_skills', requires: 'gold_soft_skills', getterFn: computeAvailableSilverSoftSkills}) diff --git a/backend/web/server/plugins/sosynpl/schemas/AnnounceSchema.js b/backend/web/server/plugins/sosynpl/schemas/AnnounceSchema.js index 2e32facd14..df7989ca17 100644 --- a/backend/web/server/plugins/sosynpl/schemas/AnnounceSchema.js +++ b/backend/web/server/plugins/sosynpl/schemas/AnnounceSchema.js @@ -101,7 +101,7 @@ const AnnounceSchema = new Schema({ type: Number, required: [function() { return this.mobility!=MOBILITY_NONE}, `Le nombre de jours de déplacements par mois est obligatoire`], }, - regions: { + mobility_regions: { type: [{ type: String, enum: Object.keys(REGIONS) diff --git a/backend/web/server/plugins/sosynpl/search.js b/backend/web/server/plugins/sosynpl/search.js index 259e73a42f..c1cced0cf7 100644 --- a/backend/web/server/plugins/sosynpl/search.js +++ b/backend/web/server/plugins/sosynpl/search.js @@ -32,7 +32,7 @@ const computeSuggestedFreelances = async (userId, params, data) => { : WORK_DURATION__1_TO_6_MONTHS const getRegionFromZipcode = (zipcode) => { - const departmentCode = zipcode.toString().substring(0, 2) + const departmentCode = String(zipcode).substring(0, 2) const region = lodash.pickBy(REGIONS_FULL, (region) => region.departements.includes(departmentCode) ) @@ -71,7 +71,8 @@ const computeSuggestedFreelances = async (userId, params, data) => { ], } const suggestions = await CustomerFreelance.find(filter) - const regionKey = getRegionFromZipcode(data.city.zip_code) + let regionKey + if(data.city && data.city.zip_code) regionKey = getRegionFromZipcode(data.city.zip_code) if (data.mobility === MOBILITY_NONE) { return suggestions.filter(s => { return ( @@ -83,8 +84,8 @@ const computeSuggestedFreelances = async (userId, params, data) => { if(data.mobility === MOBILITY_REGIONS) { return suggestions.filter(s => { return ( - (s.mobility === MOBILITY_REGIONS && s.mobility_regions.includes(data.regions)) || - (s.mobility === MOBILITY_CITY && data.regions.includes(getRegionFromZipcode(s.mobility_city.zip_code))) + (s.mobility === MOBILITY_REGIONS && s.mobility_regions.includes(data.mobility_regions)) || + (s.mobility === MOBILITY_CITY && data.mobility_regions.includes(getRegionFromZipcode(s.mobility_city.zip_code))) ) }) } diff --git a/backend/web/tests/sosynpl/evaluation.test.js b/backend/web/tests/sosynpl/evaluation.test.js new file mode 100644 index 0000000000..d13187a022 --- /dev/null +++ b/backend/web/tests/sosynpl/evaluation.test.js @@ -0,0 +1,64 @@ +const mongoose = require('mongoose') +const lodash = require('lodash') +const { MONGOOSE_OPTIONS } = require('../../server/utils/database') +const Freelance = require('../../server/models/Freelance') +const JobFile = require('../../server/models/JobFile') +const { JOB_FILE_DATA, JOB_DATA, SECTOR_DATA, CATEGORY_DATA, FREELANCE_DATA, CUSTOMER_DATA } = require('./data/base_data') +const Job = require('../../server/models/Job') +const Sector = require('../../server/models/Sector') +const HardSkillCategory = require('../../server/models/HardSkillCategory') +const HardSkill = require('../../server/models/HardSkill') +const Customer = require('../../server/models/Customer') +const Announce = require('../../server/models/Announce') +const { EXPERIENCE, DURATION_UNIT_DAYS, DURATION_UNIT, MOBILITY_NONE, DURATION_MONTH } = require('../../server/plugins/sosynpl/consts') + +jest.setTimeout(30000000) + +describe('Evaluation', ()=> { + let freelanceId, customerId, announce, application, evaluation, sector + beforeAll(async () => { + const DBNAME=`evalTest` + await mongoose.connect(`mongodb://localhost/${DBNAME}`, MONGOOSE_OPTIONS) + console.log('Opened database', DBNAME) + const jobFile=await JobFile.create({...JOB_FILE_DATA}) + const job=await Job.create({...JOB_DATA, job_file: jobFile}) + const sector=await Sector.create({...SECTOR_DATA}) + const category1=await HardSkillCategory.create({...CATEGORY_DATA, name: `Catégorie 1`}) + const category2=await HardSkillCategory.create({...CATEGORY_DATA, name: `Catégorie 2`}) + freelanceId=(await Freelance.create({...FREELANCE_DATA, main_job: job, work_sector: [sector]}))._id + await Promise.all(lodash.range(4).map(idx => HardSkill.create({name: `Skill 1-${idx}`, code: '12', job_file: jobFile, category: category1}))) + await Promise.all(lodash.range(2).map(idx => HardSkill.create({name: `Skill 2-${idx}`, code: '12', job_file: jobFile, category: category2}))) + + const rouen = { + address: 'Place du Vieux-Marché', + city: 'Rouen', + zip_code: '76000', + country: 'France', + latitude: 49.4431, + longitude: 1.0993, + } + + customerId=await Customer.create({...CUSTOMER_DATA})._id + + const announce=await Announce.create({ + user:customerId, + title:'dev', + experience: Object.keys(EXPERIENCE)[0], + duration: 2, + duration_unit: DURATION_MONTH, + budget: '6969669', + mobility_days_per_month : 2, + mobility: MOBILITY_NONE, + city: rouen, + sectors: [sector._id] + }) + }) + + afterAll(async () => { + await mongoose.connection.dropDatabase() + await mongoose.connection.close() + }) + + it('must get evaluations', async()=>{ + }) +}) \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000000..b873398bff --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "jodit-react": "^4.1.2" + } +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000000..b180e9c6eb --- /dev/null +++ b/yarn.lock @@ -0,0 +1,22 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +autobind-decorator@^2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/autobind-decorator/-/autobind-decorator-2.4.0.tgz#ea9e1c98708cf3b5b356f7cf9f10f265ff18239c" + integrity sha512-OGYhWUO72V6DafbF8PM8rm3EPbfuyMZcJhtm5/n26IDwO18pohE4eNazLoCGhPiXOCD0gEGmrbU3849QvM8bbw== + +jodit-react@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/jodit-react/-/jodit-react-4.1.2.tgz#61ef1d6fa1f37cde7b71f666da8be9f6fb70f913" + integrity sha512-Hs1evpM1IK5zvy/5m5Gk819L8aC+9EmEdQvCoLHVUr/R3vtH4nYFD6wsMRj3ur3J4ZHhaSBjt0N3R7ggwP405Q== + dependencies: + jodit "^4.2.10" + +jodit@^4.2.10: + version "4.2.27" + resolved "https://registry.yarnpkg.com/jodit/-/jodit-4.2.27.tgz#fd6b39a968bd474210e8ab78fc463cdb206d3a6d" + integrity sha512-cqqeunB3HMElnocVhs5Qq2bhgpMIT2vKQPBpKcOTWKvX6GJ0GYAIneMEf43lphJuo+119CvBE8YgljD5iTfsAQ== + dependencies: + autobind-decorator "^2.4.0"