1- import { jest } from ' @jest/globals' ; // eslint-disable-line import/no-extraneous-dependencies
2- import request from ' supertest' ;
3- import app from ' #app' ;
4- import connector from ' #models/databaseUtil' ;
5- import examModel from ' #models/exam' ;
1+ import { jest } from " @jest/globals" ; // eslint-disable-line import/no-extraneous-dependencies
2+ import request from " supertest" ;
3+ import app from " #app" ;
4+ import connector from " #models/databaseUtil" ;
5+ import examModel from " #models/exam" ;
66
7- jest . mock ( ' #util' ) ;
7+ jest . mock ( " #util" ) ;
88
99let server ;
1010let agent ;
1111
1212beforeAll ( ( done ) => {
1313 server = app . listen ( null , ( ) => {
1414 agent = request . agent ( server ) ;
15- connector . set ( ' debug' , false ) ;
15+ connector . set ( " debug" , false ) ;
1616 done ( ) ;
1717 } ) ;
1818} ) ;
1919
2020function cleanUp ( callback ) {
2121 examModel
2222 . remove ( {
23- id : '3200594e2b7b532006c073aa' ,
23+ supervisor : "60a0e7e9a09c3f001c834e07" ,
2424 } )
2525 . then ( ( ) => {
2626 connector . disconnect ( ( DBerr ) => {
27- if ( DBerr ) console . log ( ' Database disconnect error: ' , DBerr ) ;
27+ if ( DBerr ) console . log ( " Database disconnect error: " , DBerr ) ;
2828 server . close ( ( serverErr ) => {
2929 if ( serverErr ) console . log ( serverErr ) ;
3030 callback ( ) ;
@@ -37,54 +37,52 @@ afterAll((done) => {
3737 cleanUp ( done ) ;
3838} ) ;
3939
40- describe ( ' exam API' , ( ) => {
41- it ( ' should create exam' , async ( ) => {
42- const response = await agent . post ( ' /exam/add' ) . send ( {
43- date : ' 2023-08-20T14:10 :30Z' ,
44- startTime : ' 2023-05 -18T14:10 :30Z' ,
40+ describe ( " exam API" , ( ) => {
41+ it ( " should create exam" , async ( ) => {
42+ const response = await agent . post ( " /exam/add" ) . send ( {
43+ date : " 2023-06-18T14:11 :30Z" ,
44+ startTime : " 2023-06 -18T14:11 :30Z" ,
4545 duration : 5 ,
46- supervisor : '4500594e2b7b532006c073cv' ,
47- infrastructure : '8500594e2b7b532006c073uj' ,
48- course : '2500594e2b7b532006c073bb' ,
46+ supervisor : [ "5f8778b54b553439ac49a03a" ] ,
47+ infrastructure : [ "5f8778b54b553439ac49a03a" ] ,
48+ course : [ "5f8778b54b553439ac49a03a" ] ,
4949 } ) ;
50- expect ( response . headers [ ' content-type' ] ) . toMatch ( / j s o n / ) ;
50+ expect ( response . headers [ " content-type" ] ) . toMatch ( / j s o n / ) ;
5151 expect ( response . status ) . toBe ( 200 ) ;
5252 expect ( response . body . res ) . toMatch ( / a d d e d e x a m / ) ;
5353 } ) ;
5454
55- describe ( ' after adding exam' , ( ) => {
55+ describe ( " after adding exam" , ( ) => {
5656 let id ;
5757 beforeEach ( async ( ) => {
58- id = await agent . post ( ' /exam/add' ) . send ( {
59- date : ' 2023-08-20T14:10 :30Z' ,
60- startTime : ' 2023-05 -18T14:10 :30Z' ,
58+ id = await agent . post ( " /exam/add" ) . send ( {
59+ date : " 2023-06-18T14:11 :30Z" ,
60+ startTime : " 2023-06 -18T14:11 :30Z" ,
6161 duration : 5 ,
62- supervisor : '4500594e2b7b532006c073cv' ,
63- infrastructure : '8500594e2b7b532006c073uj' ,
64- course : '2500594e2b7b532006c073bb' ,
62+ supervisor : "64453a62c8f2146f2f34c73a" ,
63+ infrastructure : "64453a62c8f2146f2f34c73a" ,
64+ course : "64453a62c8f2146f2f34c73a" ,
6565 } ) ;
6666 id = JSON . parse ( id . res . text ) . id ;
6767 } ) ;
6868
6969 afterEach ( async ( ) => {
70- await examModel . remove ( {
71- id : '3200594e2b7b532006c073aa' ,
72- } ) ;
70+ await examModel . remove ( { supervisor : "64453a62c8f2146f2f34c73a" } ) ;
7371 } ) ;
7472
75- it ( ' should read exam' , async ( ) => {
73+ it ( " should read exam" , async ( ) => {
7674 const response = await agent
77- . get ( ' /exam/list' )
78- . send ( { supervisor : '4500594e2b7b532006c073cv' } ) ;
75+ . get ( " /exam/list" )
76+ . send ( { supervisor : "64453a62c8f2146f2f34c73a" } ) ;
7977 expect ( response . status ) . toBe ( 200 ) ;
8078 expect ( response . body . res ) . toBeDefined ( ) ;
8179 } ) ;
8280
83- it ( ' should update exam' , async ( ) => {
81+ it ( " should update exam" , async ( ) => {
8482 const response = await agent
8583 . post ( `/exam/update/${ id } ` )
86- . send ( { duration : 5 } , { duration : 10 } ) ;
87- expect ( response . headers [ ' content-type' ] ) . toMatch ( / j s o n / ) ;
84+ . send ( { duration : 10 } ) ;
85+ expect ( response . headers [ " content-type" ] ) . toMatch ( / j s o n / ) ;
8886 expect ( response . status ) . toBe ( 200 ) ;
8987 expect ( response . body . res ) . toMatch ( / u p d a t e d e x a m / ) ;
9088 } ) ;
0 commit comments