diff --git a/controller/faculty.js b/controller/faculty.js index 696ddfe..9343765 100644 --- a/controller/faculty.js +++ b/controller/faculty.js @@ -1,9 +1,34 @@ +import mongoose from "mongoose"; import { createFaculty, facultyList, deleteFacultyById, updateFacultyById, } from "#services/faculty"; +import { + createEmployeeBank, + // employeeBankList, + // deleteEmployeeBankById, + // updateEmployeeBankById, +} from "#services/employee/empBank"; +import { + addNewEmployeeCurrent, + // getEmployeeCurrent, + // deleteEmployeeCurrentById, + // updateEmployeeCurrentById, +} from "#services/employee/empCurrentDetail"; +import { + createEmployeeEducationHistory, + // employeeEducationHistoryList, + // deleteEmployeeEducationHistoryById, + // updateEmployeeEducationHistoryById, +} from "#services/employee/empEduHistory"; +import { + addNewEmployeePersonal, + // getEmployeePersonal, + // deleteEmployeePersonalById, + // updateEmployeePersonalById, +} from "#services/employee/empPersonal"; import { logger } from "#util"; async function addFaculty(req, res) { @@ -23,7 +48,13 @@ async function addFaculty(req, res) { designation, natureOfAssociation, additionalResponsibilities, + employeePersonalDetails, + employeeBankDetails, + employeeCurrentDetails, + employeeEducationDetails, } = req.body; + const session = await mongoose.startSession(); + session.startTransaction(); try { const newFaculty = await createFaculty( ERPID, @@ -41,9 +72,23 @@ async function addFaculty(req, res) { designation, natureOfAssociation, additionalResponsibilities, + session, ); - res.json({ res: `added faculty ${newFaculty.ERPID}` }); + await Promise.all([ + addNewEmployeePersonal(employeePersonalDetails, session), + createEmployeeEducationHistory(employeeEducationDetails, session), + addNewEmployeeCurrent(employeeCurrentDetails, session), + createEmployeeBank(employeeBankDetails, session), + ]); + res.json({ + res: `added faculty ${newFaculty.ERPID}`, + id: newFaculty.ERPID, + }); + await session.commitTransaction(); + session.endSession(); } catch (error) { + await session.abortTransaction(); + session.endSession(); logger.error("Error while inserting", error); res.status(500); res.json({ err: "Error while inserting in DB" }); diff --git a/models/employee/empBank.js b/models/employee/empBank.js index a7b495b..d11676c 100644 --- a/models/employee/empBank.js +++ b/models/employee/empBank.js @@ -6,39 +6,39 @@ const employeeBankSchema = { required: true, unique: true, }, - bank_name: { + bankName: { type: String, required: true, minLength: 7, }, - bank_acc: { + bankAcc: { type: String, required: true, unique: true, }, - bank_branch: { + bankBranch: { type: String, required: true, }, - bank_ifsc: { + bankIfsc: { type: String, required: true, maxLength: 11, minLength: 11, }, - bank_micr: { + bankMicr: { type: String, required: true, maxLength: 9, minLength: 9, }, - appointment_approve_sg_dte: { + appointmentApproveSgDte: { type: String, }, }; // eslint-disable-next-line no-unused-vars -const EmployeeBank = connector.model("Employee bank", employeeBankSchema); +const EmployeeBank = connector.model("Employee Bank", employeeBankSchema); /// crud operation/// @@ -64,7 +64,7 @@ async function create(employeeBankData) { appointmentApproveSgDte, }); - const empBankDoc = await empBank.save(); + const empBankDoc = await empBank.save({ session: employeeBankData.session }); return empBankDoc; } diff --git a/models/employee/empCurrentDetail.js b/models/employee/empCurrentDetail.js index 1a7a91e..9a93fc8 100644 --- a/models/employee/empCurrentDetail.js +++ b/models/employee/empCurrentDetail.js @@ -2,17 +2,17 @@ import connector from "#models/databaseUtil"; const employeeCurrentEmploymentSchema = { uid: { type: String, require: true }, - date_of_joining: { type: Date, required: true }, - department_name: { type: String, required: true }, + dateOfJoining: { type: Date, required: true }, + departmentName: { type: String, required: true }, designation: { type: String, required: true }, - job_status: { type: String, required: true }, - job_profile: { type: String, required: true }, - current_ctc: { type: Number, required: true }, + jobStatus: { type: String, required: true }, + jobProfile: { type: String, required: true }, + currentCtc: { type: Number, required: true }, }; // eslint-disable-next-line no-unused-vars const EmployeeCurrentEmployment = connector.model( - "EmployeeCurrentEmployement", + "Employee Employment", employeeCurrentEmploymentSchema, ); @@ -26,7 +26,6 @@ async function create(employeeCurrentEmploymentData) { jobProfile, currentCtc, } = employeeCurrentEmploymentData; - const empCurEmp = new EmployeeCurrentEmployment({ uid, dateOfJoining, @@ -37,7 +36,9 @@ async function create(employeeCurrentEmploymentData) { currentCtc, }); - const empCurrentEmploymentDoc = await empCurEmp.save(); + const empCurrentEmploymentDoc = await empCurEmp.save({ + session: employeeCurrentEmploymentData.session, + }); return empCurrentEmploymentDoc; } diff --git a/models/employee/empEduHistory.js b/models/employee/empEduHistory.js index ed43b88..24c5ce2 100644 --- a/models/employee/empEduHistory.js +++ b/models/employee/empEduHistory.js @@ -31,56 +31,17 @@ const employeeEducationHistorySchema = { // eslint-disable-next-line no-unused-vars const EmployeeEducationHistory = connector.model( - "Employee education history", + "Employee Education", employeeEducationHistorySchema, ); // CRUD Operations async function create(employeeEducationHistoryData) { - const { - educationType, - educationName, - specialization, - period, - institutionName, - university, - passingDivision, - fromYear, - uptoYear, - registrationNumber, - aggregatePct, - finalYearPct, - numberOfAttempts, - rank, - passingYear, - uid, - ssc, - hsc, - dip, - iti, - deg, - pgd, - phd, - pdoc, - } = employeeEducationHistoryData; + const { uid, ssc, hsc, dip, iti, deg, pgd, phd, pdoc } = + employeeEducationHistoryData; const empEduHistory = new EmployeeEducationHistory({ - educationType, - educationName, - specialization, - period, - institutionName, - university, - passingDivision, - fromYear, - uptoYear, - registrationNumber, - aggregatePct, - finalYearPct, - numberOfAttempts, - rank, - passingYear, uid, ssc, hsc, @@ -92,7 +53,9 @@ async function create(employeeEducationHistoryData) { pdoc, }); - const empEduHistoryDoc = await empEduHistory.save(); + const empEduHistoryDoc = await empEduHistory.save({ + session: employeeEducationHistoryData.session, + }); return empEduHistoryDoc; } diff --git a/models/employee/empPersonal.js b/models/employee/empPersonal.js index d4e3d48..7cc5a3c 100644 --- a/models/employee/empPersonal.js +++ b/models/employee/empPersonal.js @@ -12,7 +12,7 @@ const employeePersonalSchema = { motherTongue: { type: String, required: true }, gender: { type: String, required: true }, religion: { type: String, required: true }, - numOfChildren: { type: Number }, + numOfChildren: { type: Number, required: true }, originalCastCategory: { type: String, required: true }, caste: { type: String, required: true }, subCaste: { type: String, required: true }, @@ -61,14 +61,16 @@ const employeePersonalSchema = { previousLastName: { type: String }, }; const EmployeePersonal = connector.model( - "EmplyeePersonalData", + "Employee Personal", employeePersonalSchema, ); /// CRUD operations /// async function create(employeePersonalData) { const employeePersonal = new EmployeePersonal(employeePersonalData); - const employeePersonalDoc = await employeePersonal.save(); + const employeePersonalDoc = await employeePersonal.save({ + session: employeePersonalData.session, + }); return employeePersonalDoc; } diff --git a/models/faculty.js b/models/faculty.js index e94a1bf..17f0564 100644 --- a/models/faculty.js +++ b/models/faculty.js @@ -52,7 +52,7 @@ async function remove(filter) { async function create(facultyData) { const faculty = new Faculty(facultyData); - const facultyDoc = await faculty.save(); + const facultyDoc = await faculty.save({ session: facultyData.session }); return facultyDoc; } diff --git a/services/employee/empBank.js b/services/employee/empBank.js index a0daef9..61b51b7 100644 --- a/services/employee/empBank.js +++ b/services/employee/empBank.js @@ -1,15 +1,16 @@ import EmployeeBank from "#models/employee/empBank"; import databaseError from "#error/database"; -export async function createEmployeeBank( - uid, - bankName, - bankAcc, - bankBranch, - bankIfsc, - bankMicr, - appointmentApproveSgDte, -) { +export async function createEmployeeBank(empBankDetails, session) { + const { + uid, + bankName, + bankAcc, + bankBranch, + bankIfsc, + bankMicr, + appointmentApproveSgDte, + } = empBankDetails; const newEmployeeBank = await EmployeeBank.create({ uid, bankName, @@ -18,6 +19,7 @@ export async function createEmployeeBank( bankIfsc, bankMicr, appointmentApproveSgDte, + session, }); if (newEmployeeBank.uid === uid) { return newEmployeeBank; diff --git a/services/employee/empCurrentDetail.js b/services/employee/empCurrentDetail.js index 8b09496..c8361eb 100644 --- a/services/employee/empCurrentDetail.js +++ b/services/employee/empCurrentDetail.js @@ -1,15 +1,16 @@ import databaseError from "#error/database"; -import EmployeeCurrent from "#models/employee/empPersonal"; +import EmployeeCurrent from "#models/employee/empCurrentDetail"; -export async function addNewEmployeeCurrent( - uid, - dateOfJoining, - departmentName, - designation, - jobStatus, - jobProfile, - currentCtc, -) { +export async function addNewEmployeeCurrent(basicEmpDetails, session) { + const { + uid, + dateOfJoining, + departmentName, + designation, + jobStatus, + jobProfile, + currentCtc, + } = basicEmpDetails; const newEmployeeCurrent = await EmployeeCurrent.create({ uid, dateOfJoining, @@ -18,6 +19,7 @@ export async function addNewEmployeeCurrent( jobStatus, jobProfile, currentCtc, + session, }); if (newEmployeeCurrent.uid === uid) { return newEmployeeCurrent; diff --git a/services/employee/empEduHistory.js b/services/employee/empEduHistory.js index 736cd6c..1cb7121 100644 --- a/services/employee/empEduHistory.js +++ b/services/employee/empEduHistory.js @@ -2,47 +2,11 @@ import EmployeeEducationHistory from "#models/employee/empEduHistory"; import databaseError from "#error/database"; export async function createEmployeeEducationHistory( - educationType, - educationName, - specialization, - period, - institutionName, - university, - passingDivision, - fromYear, - uptoYear, - registrationNumber, - aggregatePct, - finalYearPct, - numberOfAttempts, - rank, - passingYear, - uid, - ssc, - hsc, - dip, - iti, - deg, - pgd, - phd, - pdoc, + empEduHistoryDetails, + session, ) { + const { uid, ssc, hsc, dip, iti, deg, pgd, phd, pdoc } = empEduHistoryDetails; const newEmployeeEducationHistory = await EmployeeEducationHistory.create({ - educationType, - educationName, - specialization, - period, - institutionName, - university, - passingDivision, - fromYear, - uptoYear, - registrationNumber, - aggregatePct, - finalYearPct, - numberOfAttempts, - rank, - passingYear, uid, ssc, hsc, @@ -52,6 +16,7 @@ export async function createEmployeeEducationHistory( pgd, phd, pdoc, + session, }); if (newEmployeeEducationHistory.uid === uid) { return newEmployeeEducationHistory; diff --git a/services/employee/empPersonal.js b/services/employee/empPersonal.js index 6d071ad..58819be 100644 --- a/services/employee/empPersonal.js +++ b/services/employee/empPersonal.js @@ -1,69 +1,72 @@ import databaseError from "#error/database"; import EmployeePersonal from "#models/employee/empPersonal"; -export async function addNewEmployeePersonal( - uid, - title, - empFirstName, - empLastName, - bloodGroup, - dob, - birthPlace, - motherTongue, - gender, - religion, - numOfChildren, - originalCastCategory, - caste, - subCaste, - spouseMailAddress, - spouseMobileNo, - emrgContactNo, - emrgContactPersonName, - empMobileNo, - panNumber, - aadharCardNo, - creditCardNumber, - drivingLicenceNo, - drivingLicenceExpiry, - passportNumber, - licId, - identificationMark, - addressTypePermanant, - permanantPlotNo, - permanantStreet, - permanantAddress, - permanantAddress2, - permanantCity, - permanantTahshil, - permanantDistrict, - permanantState, - permanantCountry, - permanantPincode, - addressTypeCorrespondance, - correspondancePlotNo, - correspondanceStreet, - correspondanceAddress, - correspondanceAddress2, - correspondanceCity, - correspondanceTahshil, - correspondanceDistrict, - correspondanceState, - correspondanceCountry, - correspondancePincode, - maritalStatus, - maidenFirstName, - maidenMiddleName, - maidenLastName, - isNameChangedBefore, - previousFirstName, - previousMiddleName, - previousLastName, -) { +export async function addNewEmployeePersonal(employeePersonalDetails, session) { + const { + uid, + title, + empFirstName, + empMiddleName, + empLastName, + bloodGroup, + dob, + birthPlace, + motherTongue, + gender, + religion, + numOfChildren, + originalCastCategory, + caste, + subCaste, + spouseMailAddress = "", + spouseMobileNo = "", + emrgContactNo, + emrgContactPersonName, + empMobileNo, + panNumber, + aadharCardNo, + creditCardNumber = "", + drivingLicenceNo = "", + drivingLicenceExpiry = "", + passportNumber = "", + licId = "", + identificationMark, + addressTypePermanant, + permanantPlotNo, + permanantStreet, + permanantAddress, + permanantAddress2 = "", + permanantCity, + permanantTahshil, + permanantDistrict, + permanantState, + permanantCountry, + permanantPincode, + addressTypeCorrespondance, + correspondancePlotNo, + correspondanceStreet, + correspondanceAddress, + correspondanceAddress2 = "", + correspondanceCity, + correspondanceTahshil, + correspondanceDistrict, + correspondanceState, + correspondanceCountry, + correspondancePincode, + maritalStatus, + maidenFirstName = "", + maidenMiddleName = "", + maidenLastName = "", + isNameChangedBefore, + previousFirstName = "", + previousMiddleName = "", + previousLastName = "", + } = employeePersonalDetails; const newEmployeePersonal = await EmployeePersonal.create({ uid, title, empFirstName, + empMiddleName, empLastName, bloodGroup, dob, @@ -118,6 +121,7 @@ export async function addNewEmployeePersonal( previousFirstName, previousMiddleName, previousLastName, + session, }); if (newEmployeePersonal.uid === uid) { return newEmployeePersonal; diff --git a/services/faculty.js b/services/faculty.js index c8e2b1d..78577f0 100644 --- a/services/faculty.js +++ b/services/faculty.js @@ -17,6 +17,7 @@ export async function createFaculty( designation, natureOfAssociation, additionalResponsibilities, + session, ) { const newFaculty = await Faculty.create({ ERPID, @@ -34,6 +35,7 @@ export async function createFaculty( designation, natureOfAssociation, additionalResponsibilities, + session, }); if (newFaculty.ERPID === ERPID) { return newFaculty; diff --git a/test/config/globalSetup.js b/test/config/globalSetup.js index 4ae3e37..6ff8211 100644 --- a/test/config/globalSetup.js +++ b/test/config/globalSetup.js @@ -1,5 +1,5 @@ import { spawn } from "child_process"; -import { MongoMemoryServer } from "mongodb-memory-server"; +import { MongoMemoryReplSet } from "mongodb-memory-server"; import { config } from "./config.js"; // eslint-disable-line import/extensions function runChildProcessWithTimeout(command, args, timeout) { @@ -36,7 +36,7 @@ export default async function globalSetup() { if (config.Memory) { // Config to decided if an mongodb-memory-server instance should be used // it"s needed in global space, because we don"t want to create a new instance every test-suite - const instance = await MongoMemoryServer.create(); + const instance = await MongoMemoryReplSet.create({ replSet: { count: 4 } }); const uri = instance.getUri(); global.MONGOINSTANCE = instance; process.env.DB_URL = uri.slice(0, uri.lastIndexOf("/")); diff --git a/test/routes/faculty.test.js b/test/routes/faculty.test.js index 5e30440..64708bf 100644 --- a/test/routes/faculty.test.js +++ b/test/routes/faculty.test.js @@ -1,128 +1,549 @@ import { jest } from "@jest/globals"; // eslint-disable-line import/no-extraneous-dependencies import connector from "#models/databaseUtil"; import facultyModel from "#models/faculty"; +import facultyEducationModel from "#models/employee/empEduHistory"; +import facultyPersonalModel from "#models/employee/empPersonal"; +import facultyBankModel from "#models/employee/empBank"; +import facultyCurrentModel from "#models/employee/empCurrentDetail"; jest.mock("#util"); -const {agent} = global; +const { agent } = global; // test case for deletion function cleanUp(callback) { - facultyModel.remove( - { - ERPID: "test123", - dateOfJoining: "2023-06-18T14:11:30Z", - dateOfLeaving: "2023-07-18T14:11:30Z", - profileLink: "Sanika", - qualifications: ["Ph.D.", "M.Sc."], - totalExperience: 5, - achievements: ["Award 1", "Award 2"], - areaOfSpecialization: ["Specialization 1", "Specialization 2"], - papersPublishedPG: 10, - papersPublishedUG: 5, - department: ["5f7b75a5c69e2d4f0c285e52"], - preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"], - designation: "Assistant Professor", - natureOfAssociation: "Regular", - additionalResponsibilities: "Teaching and Research", - }, - ) - .then(() => { - connector.disconnect((DBerr) => { - if (DBerr) console.log("Database disconnect error: ", DBerr); - callback(); - }); - }); + facultyBankModel.remove({ uid: "aaaaa" }); + facultyCurrentModel.remove({ uid: "aaaaa" }); + facultyEducationModel.remove({ uid: "aaaaa" }); + facultyPersonalModel.remove({ uid: "aaaaa" }); + facultyModel + .remove({ + ERPID: "test123", + dateOfJoining: "2023-06-18T14:11:30Z", + dateOfLeaving: "2023-07-18T14:11:30Z", + profileLink: "Sanika", + qualifications: ["Ph.D.", "M.Sc."], + totalExperience: 5, + achievements: ["Award 1", "Award 2"], + areaOfSpecialization: ["Specialization 1", "Specialization 2"], + papersPublishedPG: 10, + papersPublishedUG: 5, + department: ["5f7b75a5c69e2d4f0c285e52"], + preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"], + designation: "Assistant Professor", + natureOfAssociation: "Regular", + additionalResponsibilities: "Teaching and Research", + }) + .then(() => { + connector.disconnect((DBerr) => { + if (DBerr) console.log("Database disconnect error: ", DBerr); + callback(); + }); + }); } afterAll((done) => { - cleanUp(done); + cleanUp(done); }); describe("Faculty API", () => { - it("should create faculty", async () => { - const response = await agent.post("/faculty/create").send({ - ERPID: "test123", - dateOfJoining: "2023-06-18T14:11:30Z", - dateOfLeaving: "2023-07-18T14:11:30Z", - profileLink: "xyz", - qualifications: ["Ph.D.", "M.Sc."], - totalExperience: 5, - achievements: ["Award 1", "Award 2"], - areaOfSpecialization: ["Specialization 1", "Specialization 2"], - papersPublishedPG: 10, - papersPublishedUG: 5, - department: ["5f7b75a5c69e2d4f0c285e52"], - preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"], - designation: "Assistant Professor", - natureOfAssociation: "Regular", - additionalResponsibilities: "Teaching and Research", - }); - - expect(response.status).toBe(200); - expect(response.body.res).toMatch(/added faculty/); + it("should create faculty", async () => { + const response = await agent.post("/faculty/create").send({ + ERPID: "test123", + dateOfJoining: "2023-06-18T14:11:30Z", + dateOfLeaving: "2023-07-18T14:11:30Z", + profileLink: "xyz", + qualifications: ["Ph.D.", "M.Sc."], + totalExperience: 5, + achievements: ["Award 1", "Award 2"], + areaOfSpecialization: ["Specialization 1", "Specialization 2"], + papersPublishedPG: 10, + papersPublishedUG: 5, + department: ["5f7b75a5c69e2d4f0c285e52"], + preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"], + designation: "Assistant Professor", + natureOfAssociation: "Regular", + additionalResponsibilities: "Teaching and Research", + employeePersonalDetails: { + uid: "aaaaa", + title: "Mr", + empFirstName: "Tejas", + empMiddleName: "Ajit", + empLastName: "Nair", + bloodGroup: "A+", + dob: "2023-06-18T14:11:30Z", + birthPlace: "Bangalore", + motherTongue: "Malayalam", + gender: "Male", + religion: "Hindu", + numOfChildren: 0, + originalCastCategory: "General", + caste: "General", + subCaste: "General", + emrgContactNo: 90123108, + emrgContactPersonName: "Me", + empMobileNo: 900123213, + panNumber: 12414125125, + aadharCardNo: 512512421312312, + identificationMark: "on my left cheek", + addressTypePermanant: "Rooftop", + permanantPlotNo: "1323", + permanantStreet: "123123", + permanantAddress: "123123", + permanantCity: "Mumbai", + permanantTahshil: "123213", + permanantDistrict: "123123", + permanantState: "123123", + permanantCountry: "123213", + permanantPincode: 123132, + addressTypeCorrespondance: "12321321", + correspondancePlotNo: "123123", + correspondanceStreet: "123123", + correspondanceAddress: "123123123", + correspondanceCity: "123213", + correspondanceTahshil: "12321312", + correspondanceDistrict: "12321321", + correspondanceState: "3212312", + correspondanceCountry: "12312312", + correspondancePincode: 1231232, + maritalStatus: "123213213", + isNameChangedBefore: false, + }, + employeeEducationDetails: { + uid: "aaaaa", + ssc: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + hsc: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + dip: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + iti: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + deg: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + pgd: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + phd: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + pdoc: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + }, + employeeCurrentDetails: { + uid: "aaaaa", + dateOfJoining: "2023-06-18T14:11:30Z", + departmentName: "COMP", + designation: "Loser", + jobStatus: "jobless", + jobProfile: "none", + currentCtc: 69420, + }, + employeeBankDetails: { + uid: "aaaaa", + bankName: "Bank of Baroda", + bankAcc: "123214215123", + bankBranch: "Kandivali", + bankIfsc: "13212312312", + bankMicr: "123123123", + appointmentApproveSgDte: "12321321", + }, }); + expect(response.status).toBe(200); + expect(response.body.res).toMatch(/added faculty/); + + await Promise.all([ + facultyBankModel.remove({ uid: "aaaaa" }), + facultyCurrentModel.remove({ uid: "aaaaa" }), + facultyEducationModel.remove({ uid: "aaaaa" }), + facultyPersonalModel.remove({ uid: "aaaaa" }), + ]); + }); - describe("after adding faculty", () => { - let id; - beforeEach(async () => { - id = await agent.post("/faculty/create").send( - { - ERPID: "test123", - dateOfJoining: "2023-06-18T14:11:30Z", - dateOfLeaving: "2023-07-18T14:11:30Z", - profileLink: "xyz", - qualifications: ["Ph.D.", "M.Sc."], - totalExperience: 5, - achievements: ["Award 1", "Award 2"], - areaOfSpecialization: ["Specialization 1", "Specialization 2"], - papersPublishedPG: 10, - papersPublishedUG: 5, - department: ["5f7b75a5c69e2d4f0c285e52"], - preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"], - designation: "Assistant Professor", - natureOfAssociation: "Regular", - additionalResponsibilities: "Teaching and Research", - }); + describe("after adding faculty", () => { + let id; + beforeEach(async () => { + id = await agent.post("/faculty/create").send({ + ERPID: "test123", + dateOfJoining: "2023-06-18T14:11:30Z", + dateOfLeaving: "2023-07-18T14:11:30Z", + profileLink: "xyz", + qualifications: ["Ph.D.", "M.Sc."], + totalExperience: 5, + achievements: ["Award 1", "Award 2"], + areaOfSpecialization: ["Specialization 1", "Specialization 2"], + papersPublishedPG: 10, + papersPublishedUG: 5, + department: ["5f7b75a5c69e2d4f0c285e52"], + preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"], + designation: "Assistant Professor", + natureOfAssociation: "Regular", + additionalResponsibilities: "Teaching and Research", + employeePersonalDetails: { + uid: "aaaaa", + title: "Mr", + empFirstName: "Tejas", + empMiddleName: "Ajit", + empLastName: "Nair", + bloodGroup: "A+", + dob: "2023-06-18T14:11:30Z", + birthPlace: "Bangalore", + motherTongue: "Malayalam", + gender: "Male", + religion: "Hindu", + numOfChildren: 0, + originalCastCategory: "General", + caste: "General", + subCaste: "General", + emrgContactNo: 90123108, + emrgContactPersonName: "Me", + empMobileNo: 900123213, + panNumber: 12414125125, + aadharCardNo: 512512421312312, + identificationMark: "on my left cheek", + addressTypePermanant: "Rooftop", + permanantPlotNo: "1323", + permanantStreet: "123123", + permanantAddress: "123123", + permanantCity: "Mumbai", + permanantTahshil: "123213", + permanantDistrict: "123123", + permanantState: "123123", + permanantCountry: "123213", + permanantPincode: 123132, + addressTypeCorrespondance: "12321321", + correspondancePlotNo: "123123", + correspondanceStreet: "123123", + correspondanceAddress: "123123123", + correspondanceCity: "123213", + correspondanceTahshil: "12321312", + correspondanceDistrict: "12321321", + correspondanceState: "3212312", + correspondanceCountry: "12312312", + correspondancePincode: 1231232, + maritalStatus: "123213213", + isNameChangedBefore: false, + }, + employeeEducationDetails: { + uid: "aaaaa", + ssc: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + hsc: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + dip: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + iti: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + deg: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + pgd: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + phd: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + pdoc: { + educationType: "12321312", + educationName: "123123", + specialization: "13213123", + period: "2133", + institutionName: "Mithibia", + university: "MU", + passingDivision: "A", + fromYear: "123213", + uptoYear: "213213", + registrationNumber: "123213213", + aggregatePct: "2923", + finalYearPct: "2021", + numberOfAttempts: 3, + rank: 3, + passingYear: "2020", + }, + }, + employeeCurrentDetails: { + uid: "aaaaa", + dateOfJoining: "2023-06-18T14:11:30Z", + departmentName: "COMP", + designation: "Loser", + jobStatus: "jobless", + jobProfile: "none", + currentCtc: 69420, + }, + employeeBankDetails: { + uid: "aaaaa", + bankName: "Bank of Baroda", + bankAcc: "123214215123", + bankBranch: "Kandivali", + bankIfsc: "13212312312", + bankMicr: "123123123", + appointmentApproveSgDte: "12321321", + }, + }); - id = JSON.parse(id.res.text).id; - }); + id = JSON.parse(id.res.text).id; + }); - afterEach(async () => { - await facultyModel.remove( - { - ERPID: "test123", - dateOfJoining: "2023-06-18T14:11:30Z", - dateOfLeaving: "2023-07-18T14:11:30Z", - profileLink: "xyz", - qualifications: ["Ph.D.", "M.Sc."], - totalExperience: 5, - achievements: ["Award 1", "Award 2"], - areaOfSpecialization: ["Specialization 1", "Specialization 2"], - papersPublishedPG: 10, - papersPublishedUG: 5, - department: ["5f7b75a5c69e2d4f0c285e52"], - preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"], - designation: "Assistant Professor", - natureOfAssociation: "Regular", - additionalResponsibilities: "Teaching and Research", - }); - }); + afterEach(async () => { + await Promise.all([ + facultyBankModel.remove({ uid: "aaaaa" }), + facultyCurrentModel.remove({ uid: "aaaaa" }), + facultyEducationModel.remove({ uid: "aaaaa" }), + facultyPersonalModel.remove({ uid: "aaaaa" }), + facultyModel.remove({ + ERPID: "test123", + dateOfJoining: "2023-06-18T14:11:30Z", + dateOfLeaving: "2023-07-18T14:11:30Z", + profileLink: "xyz", + qualifications: ["Ph.D.", "M.Sc."], + totalExperience: 5, + achievements: ["Award 1", "Award 2"], + areaOfSpecialization: ["Specialization 1", "Specialization 2"], + papersPublishedPG: 10, + papersPublishedUG: 5, + department: ["5f7b75a5c69e2d4f0c285e52"], + preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"], + designation: "Assistant Professor", + natureOfAssociation: "Regular", + additionalResponsibilities: "Teaching and Research", + }), + ]); + }); - it("should read faculty", async () => { - const response = await agent - .get("/faculty/list") - .send({ERPID: "test123"}); + it("should read faculty", async () => { + const response = await agent + .get("/faculty/list") + .send({ ERPID: "test123" }); - expect(response.status).toBe(200); - expect(response.body.res).toBeDefined(); - }); + expect(response.status).toBe(200); + expect(response.body.res).toBeDefined(); + }); - it("should update faculty", async () => { - const response = await agent - .post(`/faculty/update/${id}`) - .send({ ERPID: "test123" }, { totalExperience: 10 }); - expect(response.status).toBe(200); - expect(response.body.res).toMatch(/updated faculty/); - }); + it("should update faculty", async () => { + const response = await agent + .post(`/faculty/update/${id}`) + .send({ ERPID: "test123" }, { totalExperience: 10 }); + expect(response.status).toBe(200); + expect(response.body.res).toMatch(/updated faculty/); }); -}); \ No newline at end of file + }); +});