1+ import { jest } from "@jest/globals" ;
2+ import connector from "#models/databaseUtil" ;
3+ import facultyModel from "#models/faculty" ;
4+ import mongoose from "mongoose" ;
5+
6+ jest . mock ( "#util" ) ;
7+ const { agent} = global ;
8+
9+ //test case for deletion
10+ function cleanUp ( callback ) {
11+ facultyModel . remove (
12+ {
13+ ERPID : "test123" ,
14+ dateOfJoining : "2023-06-18T14:11:30Z" ,
15+ dateOfLeaving : "2023-07-18T14:11:30Z" ,
16+ profileLink : "Sanika" ,
17+ qualifications : [ "Ph.D." , "M.Sc." ] ,
18+ totalExperience : 5 ,
19+ achievements : [ "Award 1" , "Award 2" ] ,
20+ areaOfSpecialization : [ "Specialization 1" , "Specialization 2" ] ,
21+ papersPublishedPG : 10 ,
22+ papersPublishedUG : 5 ,
23+ department : [ mongoose . Types . ObjectId ( "5f7b75a5c69e2d4f0c285e52" ) ] ,
24+ preferredSubjects : [ mongoose . Types . ObjectId ( "5f7b75a5c69e2d4f0c285e53" ) ] ,
25+ designation : "Assistant Professor" ,
26+ natureOfAssociation : "Regular" ,
27+ additionalResponsibilities : "Teaching and Research" ,
28+ } ,
29+ )
30+ . then ( ( ) => {
31+ connector . disconnect ( ( DBerr ) => {
32+ if ( DBerr ) console . log ( "Database disconnect error: " , DBerr ) ;
33+ callback ( ) ;
34+ } ) ;
35+ } ) ;
36+ }
37+
38+ afterAll ( ( done ) => {
39+ cleanUp ( done ) ;
40+ } ) ;
41+
42+ describe ( "Faculty API" , ( ) => {
43+ it ( "should create faculty" , async ( ) => {
44+ const response = await agent . post ( "/faculty/create" ) . send ( {
45+ ERPID : "test123" ,
46+ dateOfJoining : "2023-06-18T14:11:30Z" ,
47+ dateOfLeaving : "2023-07-18T14:11:30Z" ,
48+ profileLink : "xyz" ,
49+ qualifications : [ "Ph.D." , "M.Sc." ] ,
50+ totalExperience : 5 ,
51+ achievements : [ "Award 1" , "Award 2" ] ,
52+ areaOfSpecialization : [ "Specialization 1" , "Specialization 2" ] ,
53+ papersPublishedPG : 10 ,
54+ papersPublishedUG : 5 ,
55+ department : [ mongoose . Types . ObjectId ( "5f7b75a5c69e2d4f0c285e52" ) ] ,
56+ preferredSubjects : [ mongoose . Types . ObjectId ( "5f7b75a5c69e2d4f0c285e53" ) ] ,
57+ designation : "Assistant Professor" ,
58+ natureOfAssociation : "Regular" ,
59+ additionalResponsibilities : "Teaching and Research" ,
60+ } ) ;
61+
62+ expect ( response . status ) . toBe ( 200 ) ;
63+ expect ( response . body . res ) . toMatch ( / a d d e d f a c u l t y / ) ;
64+ } ) ;
65+
66+ describe ( "after adding faculty" , ( ) => {
67+ let id ;
68+ beforeEach ( async ( ) => {
69+ id = await agent . post ( "/faculty/create" ) . send (
70+ {
71+ ERPID : "test123" ,
72+ dateOfJoining : "2023-06-18T14:11:30Z" ,
73+ dateOfLeaving : "2023-07-18T14:11:30Z" ,
74+ profileLink : "xyz" ,
75+ qualifications : [ "Ph.D." , "M.Sc." ] ,
76+ totalExperience : 5 ,
77+ achievements : [ "Award 1" , "Award 2" ] ,
78+ areaOfSpecialization : [ "Specialization 1" , "Specialization 2" ] ,
79+ papersPublishedPG : 10 ,
80+ papersPublishedUG : 5 ,
81+ department : [ mongoose . Types . ObjectId ( "5f7b75a5c69e2d4f0c285e52" ) ] ,
82+ preferredSubjects : [ mongoose . Types . ObjectId ( "5f7b75a5c69e2d4f0c285e53" ) ] ,
83+ designation : "Assistant Professor" ,
84+ natureOfAssociation : "Regular" ,
85+ additionalResponsibilities : "Teaching and Research" ,
86+ } ) ;
87+
88+ id = JSON . parse ( id . res . text ) . id ;
89+ } ) ;
90+
91+ afterEach ( async ( ) => {
92+ await facultyModel . remove (
93+ {
94+ ERPID : "test123" ,
95+ dateOfJoining : "2023-06-18T14:11:30Z" ,
96+ dateOfLeaving : "2023-07-18T14:11:30Z" ,
97+ profileLink : "xyz" ,
98+ qualifications : [ "Ph.D." , "M.Sc." ] ,
99+ totalExperience : 5 ,
100+ achievements : [ "Award 1" , "Award 2" ] ,
101+ areaOfSpecialization : [ "Specialization 1" , "Specialization 2" ] ,
102+ papersPublishedPG : 10 ,
103+ papersPublishedUG : 5 ,
104+ department : [ mongoose . Types . ObjectId ( "5f7b75a5c69e2d4f0c285e52" ) ] ,
105+ preferredSubjects : [ mongoose . Types . ObjectId ( "5f7b75a5c69e2d4f0c285e53" ) ] ,
106+ designation : "Assistant Professor" ,
107+ natureOfAssociation : "Regular" ,
108+ additionalResponsibilities : "Teaching and Research" ,
109+ } ) ;
110+ } ) ;
111+
112+ it ( "should read faculty" , async ( ) => {
113+ const response = await agent
114+ . get ( "/faculty/list" )
115+ . send ( { ERPID : "test123" } ) ;
116+
117+ expect ( response . status ) . toBe ( 200 ) ;
118+ expect ( response . body . res ) . toBeDefined ( ) ;
119+ } ) ;
120+
121+ it ( "should update faculty" , async ( ) => {
122+ const response = await agent
123+ . post ( `/faculty/update/${ id } ` )
124+ . send ( { ERPID : "test123" } , { totalExperience : 10 } ) ;
125+ expect ( response . status ) . toBe ( 200 ) ;
126+ expect ( response . body . res ) . toMatch ( / u p d a t e d f a c u l t y / ) ;
127+ } ) ;
128+ } ) ;
129+ } ) ;
0 commit comments