Skip to content

Commit

Permalink
Sosynpl[Mailing premieroctet#45]: added reminder for freelance to add…
Browse files Browse the repository at this point in the history
… freelance finish date when progress is 100%
  • Loading branch information
SeghirOumo committed Aug 6, 2024
1 parent f231a45 commit 12c5b8b
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 42 deletions.
25 changes: 21 additions & 4 deletions backend/web/server/plugins/sosynpl/cron.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const moment=require('moment')
const customCron = require("../../utils/cron");
const { AVAILABILITY_CHECK_PERIODS, AVAILABILITY_UNDEFINED, ROLE_FREELANCE, ROLE_ADMIN, ROLE_CUSTOMER } = require("./consts");
const { sendRemidner2Freelance, sendInterestReminder2Freelance, sendNewSignUps2Admin, sendFirstAnnounceReminder2Customer } = require("./mailing");
const CustomerFreelance = require('../../models/CustomerFreelance')
const { AVAILABILITY_CHECK_PERIODS, AVAILABILITY_UNDEFINED, ROLE_FREELANCE, ROLE_ADMIN, ROLE_CUSTOMER, MISSION_STATUS_CURRENT } = require("./consts");
const { sendRemidner2Freelance, sendInterestReminder2Freelance, sendNewSignUps2Admin, sendFirstAnnounceReminder2Customer, sendMissionFinishConfirm2Freelance } = require("./mailing");
const CustomerFreelance = require('../../models/CustomerFreelance');
const Mission = require('../../models/Mission');
const { loadFromDb } = require('../../utils/database');
require('./functions')


// Freelance whose availability date hasn't been changed for the past 45 days
const checkFreelanceInterest = async () => {
Expand Down Expand Up @@ -125,6 +129,19 @@ const checkCustomerAnnounces = async () => {

customCron.schedule('0 9 * * * *', checkCustomerAnnounces)

//Send mail to freelance when mission finished
const checkFreelanceMission = async () => {
const missions = await loadFromDb({model:'mission', fields:['progress', 'status', 'freelance', 'title']})
missions.forEach(async(m) => {
if (m.status == MISSION_STATUS_CURRENT && m.progress == 1){
await sendMissionFinishConfirm2Freelance(m.freelance, m.title)
}
})
}

//Every monday at 9 am
customCron.schedule('0 9 * * 1', checkFreelanceMission)

module.exports={
availabilityPeriodUpdate, checkFreelanceInterest, checkNewSignUps, checkCustomerAnnounces
availabilityPeriodUpdate, checkFreelanceInterest, checkNewSignUps, checkCustomerAnnounces, checkFreelanceMission
}
18 changes: 17 additions & 1 deletion backend/web/server/plugins/sosynpl/mailing.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const SIB_IDS={
ADMIN_NEW_SIGNUPS_NOTIF: 24,
CUSTOMER_FINISH_MISSION: 29,
CUSTOMER_FIRST_ANNOUCE : 46,
FREELANCE_FINISH_MISSION: 45,
}

const SMS_CONTENTS={
Expand Down Expand Up @@ -175,7 +176,22 @@ const sendFirstAnnounceReminder2Customer = async (customer) => {
}
})
}

//Send mail to freelance to confirm finish mission
const sendMissionFinishConfirm2Freelance = async (freelance, missionTitle) => {
const tagUrl = await getTagUrl('SUPPLIER_MISSION_PROGRESS')
const url=`${computeUrl(tagUrl)}`
return sendNotification({
notification: SIB_IDS.FREELANCE_FINISH_MISSION,
destinee: freelance,
params: {
firstname: freelance.firstname,
mission_name: missionTitle,
decla_endmission: url
}
})
}
module.exports = {
sendCustomerConfirmEmail, sendFreelanceConfirmEmail, sendSuggestion2Freelance, sendApplication2Customer, sendSuspension2User, sendInterestReminder2Freelance,
sendRemidner2Freelance, sendNewSignUps2Admin, sendMissionFinishConfirm2Customer, sendFirstAnnounceReminder2Customer
sendRemidner2Freelance, sendNewSignUps2Admin, sendMissionFinishConfirm2Customer, sendFirstAnnounceReminder2Customer, sendMissionFinishConfirm2Freelance
}
104 changes: 67 additions & 37 deletions backend/web/tests/sosynpl/mailing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const { MONGOOSE_OPTIONS, loadFromDb } = require('../../server/utils/database')
const CustomerFreelance = require('../../server/models/CustomerFreelance')
const Question = require('../../server/models/Question')
const { CUSTOMER_DATA, FREELANCE_DATA, JOB_FILE_DATA, SECTOR_DATA, JOB_DATA, CATEGORY_DATA } = require('./data/base_data')
const { ROLE_ADMIN, SUSPEND_REASON, SUSPEND_REASON_INACTIVE, ROLE_FREELANCE, MOBILITY_CITY, WORK_MODE_REMOTE, COMPANY_SIZE_LESS_10, MOBILITY_FRANCE, LEGAL_STATUS, LEGAL_STATUS_CAE, AVAILABILITY_ON, EXPERIENCE, DURATION_MONTH, MOBILITY_NONE } = require('../../server/plugins/sosynpl/consts')
const { ROLE_ADMIN, SUSPEND_REASON, SUSPEND_REASON_INACTIVE, ROLE_FREELANCE, MOBILITY_CITY, WORK_MODE_REMOTE, COMPANY_SIZE_LESS_10, MOBILITY_FRANCE, LEGAL_STATUS, LEGAL_STATUS_CAE, AVAILABILITY_ON, EXPERIENCE, DURATION_MONTH, MOBILITY_NONE, QUOTATION_STATUS_SENT, REPORT_STATUS_SENT } = require('../../server/plugins/sosynpl/consts')
const { suspendAccount, finishMission } = require('../../server/plugins/sosynpl/actions')
const JobFile = require('../../server/models/JobFile')
const Job = require('../../server/models/Job')
const Sector = require('../../server/models/Sector')
const PageTag_ = require('../../server/models/PageTag_')
const { availabilityPeriodUpdate, checkFreelanceInterest, checkNewSignUps, checkCustomerAnnounces } = require('../../server/plugins/sosynpl/cron')
const { availabilityPeriodUpdate, checkFreelanceInterest, checkNewSignUps, checkCustomerAnnounces, checkFreelanceMission } = require('../../server/plugins/sosynpl/cron')
const HardSkillCategory = require('../../server/models/HardSkillCategory')
const Expertise = require('../../server/models/Expertise')
const HardSkill = require('../../server/models/HardSkill')
Expand All @@ -22,7 +22,10 @@ const Application = require('../../server/models/Application')
require('../../server/plugins/sosynpl/functions')
const lodash = require('lodash')
const Mission = require('../../server/models/Mission')

const { sendMissionFinishConfirm2Freelance } = require('../../server/plugins/sosynpl/mailing')
const Quotation = require('../../server/models/Quotation')
const QuotationDetail = require('../../server/models/QuotationDetail')
const Report = require('../../server/models/Report')

describe('Mailing', () => {
let admin, freelance, customer, application, mission, announce, category1, category2, expertise1, expertise2, expertise3, language, software
Expand Down Expand Up @@ -71,6 +74,7 @@ describe('Mailing', () => {
await PageTag_.create({ tag: 'ADMIN_DASHBOARD', url: '/admin-dashboard' })
await PageTag_.create({ tag: 'LOGIN', url: '/login' })
await PageTag_.create({ tag: 'COMPANY_MISSION_PROGRESS', url: '/company-mission-progress' })
await PageTag_.create({ tag: 'SUPPLIER_MISSION_PROGRESS', url: '/supplier-mission-progress' })

const category1=await HardSkillCategory.create({...CATEGORY_DATA, name: `Catégorie 1`})
const category2=await HardSkillCategory.create({...CATEGORY_DATA, name: `Catégorie 2`})
Expand All @@ -89,39 +93,61 @@ describe('Mailing', () => {
latitude: 49.4431,
longitude: 1.0993,
}
// announce = await Announce.create({
// user: customer._id,
// 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],
// expertises: [expertise1._id, expertise2._id, expertise3._id],
// pinned_expertises: [expertise1._id, expertise2._id, expertise3._id],
// softwares: [software._id],
// languages: [language._id],
// })
// application = await Application.create({
// announce: announce._id,
// customer: customer._id,
// freelance: freelance._id,
// })

// announce.accepted_application = application._id
// await announce.save()

// mission = await Mission.create({
// application: application._id,
// customer: customer._id,
// freelance: freelance._id,
// title: 'dev',
// start_date: new Date(),
// end_date: new Date('2025-06-06'),
// })
announce = await Announce.create({
user: customer._id,
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],
expertises: [expertise1._id, expertise2._id, expertise3._id],
pinned_expertises: [expertise1._id, expertise2._id, expertise3._id],
softwares: [software._id],
languages: [language._id],
})
application = await Application.create({
announce: announce._id,
customer: customer._id,
freelance: freelance._id,
})

announce.accepted_application = application._id
await announce.save()

mission = await Mission.create({
application: application._id,
customer: customer._id,
freelance: freelance._id,
title: 'dev',
start_date: new Date(),
end_date: new Date('2025-06-06'),
})

const report = await Report.create({
mission: mission._id,
status: REPORT_STATUS_SENT,
sent_date: new Date(),
})

const quotation = await Quotation.create({
application: application._id,
expiration_date: new Date('2025-06-06'),
start_date: new Date('2025-01-01'),
end_date: new Date('2025-06-06'),
status: QUOTATION_STATUS_SENT,
})

const quotationDetail = await QuotationDetail.create({
quotation: quotation._id,
label: 'test',
quantity: 20,
price: 600,
vat_rate: 0.8
})
})

afterAll(async () => {
Expand Down Expand Up @@ -150,7 +176,11 @@ describe('Mailing', () => {
const res= await finishMission({value:mission}, freelance)
})

it.only(`must send reminder to customer that hasn't published announce yet`, async() => {
it(`must send reminder to customer that hasn't published announce yet`, async() => {
await checkCustomerAnnounces()
})

it('must check missions progress and send mails to freelance to confirm', async () => {
await checkFreelanceMission()
})
})

0 comments on commit 12c5b8b

Please sign in to comment.