1- import request from "supertest" ;
21import { jest } from "@jest/globals" ; // eslint-disable-line import/no-extraneous-dependencies
3- import app from "#app" ;
42import attendanceModel from "#models/attendance" ;
53import connector from "#models/databaseUtil" ;
64
75jest . mock ( "#util" ) ;
8-
9- let server ;
10- let agent ;
11- beforeAll ( ( done ) => {
12- server = app . listen ( null , ( ) => {
13- agent = request . agent ( server ) ;
14- connector . set ( "debug" , false ) ;
15- done ( ) ;
16- } ) ;
17- } ) ;
6+ const { agent } = global ;
187
198function cleanUp ( callback ) {
20- attendanceModel . remove ( { student : "xyz " } ) . then ( ( ) => {
9+ attendanceModel . remove ( { student : "64fc3c8bde9fa947ea1f412f " } ) . then ( ( ) => {
2110 connector . disconnect ( ( DBerr ) => {
2211 if ( DBerr ) console . log ( "Database dissconnnect error: " , DBerr ) ;
23- server . close ( ( serverErr ) => {
24- if ( serverErr ) console . log ( serverErr ) ;
25- callback ( ) ;
26- } ) ;
12+ callback ( ) ;
2713 } ) ;
2814 } ) ;
2915}
@@ -35,8 +21,8 @@ afterAll((done) => {
3521describe ( "checking attendance functions" , ( ) => {
3622 it ( "create attendance" , async ( ) => {
3723 const response = await agent . post ( "/attendance/add" ) . send ( {
38- student : "xyz " ,
39- course : "XYZ " ,
24+ student : "64fc3c8bde9fa947ea1f412f " ,
25+ course : "64fc3c8bde9fa947ea1f412f " ,
4026 monthlyAttended : 123 ,
4127 monthlyOccured : 123 ,
4228 cumulativeAttended : 123 ,
@@ -49,32 +35,32 @@ describe("checking attendance functions", () => {
4935 let id ;
5036 beforeEach ( async ( ) => {
5137 id = await agent . post ( "/attendance/add" ) . send ( {
52- student : "xyz " ,
53- course : "XYZ " ,
54- monthlyAttended : 123 ,
55- monthlyOccured : 123 ,
56- cumulativeAttended : 123 ,
57- cumulativeOccured : 123 ,
38+ student : "64fc3c8bde9fa947ea1f412f " ,
39+ course : "64fc3c8bde9fa947ea1f412f " ,
40+ monthlyAttended : 123 ,
41+ monthlyOccured : 123 ,
42+ cumulativeAttended : 123 ,
43+ cumulativeOccured : 123 ,
5844 } ) ;
5945 id = JSON . parse ( id . res . text ) . id ;
6046 } ) ;
6147
6248 afterEach ( async ( ) => {
63- await attendanceModel . remove ( { student : "xyz " } ) ;
49+ await attendanceModel . remove ( { student : "64fc3c8bde9fa947ea1f412f " } ) ;
6450 } ) ;
6551
6652 it ( "read attendance" , async ( ) => {
6753 const response = await agent
6854 . get ( "/attendance/list" )
69- . send ( { student : "xyz " } ) ;
55+ . send ( { student : "64fc3c8bde9fa947ea1f412f " } ) ;
7056 expect ( response . status ) . toBe ( 200 ) ;
7157 expect ( response . body . res ) . toBeDefined ( ) ;
7258 } ) ;
7359
7460 it ( "update attendance" , async ( ) => {
7561 const response = await agent
7662 . post ( `/attendance/update/${ id } ` )
77- . send ( { student : "xyz" } , { student : "123 " } ) ;
63+ . send ( { student : "64fc3c8bde9fa947ea1f412f " } ) ;
7864 expect ( response . headers [ "content-type" ] ) . toMatch ( / j s o n / ) ;
7965 expect ( response . status ) . toBe ( 200 ) ;
8066 expect ( response . body . res ) . toMatch ( / a t t e n d a n c e u p d a t e d / ) ;
0 commit comments