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