1- import { jest } from "@jest/globals" ; //eslint-disable-line-import/no-extraneous-dependencies
1+ import { jest } from "@jest/globals" ; //eslint-disable-line-import/no-extraneous-dependencies
22import request from "supertest" ;
33import app from "#app" ; //Update this import based on your app's
44import connector from "#models/databaseUtil" ; //Update this import
@@ -10,108 +10,108 @@ let server;
1010let agent ;
1111
1212beforeAll ( ( done ) => {
13- server = app . listen ( null , ( ) => {
14- agent = request . agent ( server ) ;
15- connector . set ( "debug" , false ) ;
16- done ( ) ;
17- } ) ;
13+ server = app . listen ( null , ( ) => {
14+ agent = request . agent ( server ) ;
15+ connector . set ( "debug" , false ) ;
16+ done ( ) ;
17+ } ) ;
1818} ) ;
1919
20- function cleanUp ( callback ) {
21- activityModel
20+ function cleanUp ( callback ) {
21+ activityModel
2222 . remove ( {
23- startTime :" 11:45 AM ",
24- duration :2 ,
25- course : "64fc3c8bde9fa947ea1f412f" ,
26- faculty : "64fc3c8bde9fa947ea1f412f" ,
27- type :"LECTURE" ,
28- task :"Practical" ,
29- group : "64fc3c8bde9fa947ea1f412f" ,
30- students :"xyz" ,
23+ startTime : "2023-06-18T14: 11:30Z ",
24+ duration : 2 ,
25+ course : "64fc3c8bde9fa947ea1f412f" ,
26+ faculty : "64fc3c8bde9fa947ea1f412f" ,
27+ type : "LECTURE" ,
28+ task : [ "64fc3c8bde9fa947ea1f412f" ] ,
29+ group : "64fc3c8bde9fa947ea1f412f" ,
30+ students : [ "64fc3c8bde9fa947ea1f412f" ]
3131 } )
32- . then ( ( ) => {
33- connector . disconnect ( ( DBerr ) => {
34- if ( DBerr ) console . log ( "Database disconnect error : " , DBerr ) ;
35- server . close ( ( serverErr ) => {
36- if ( serverErr ) console . log ( serverErr ) ;
37- callback ( ) ;
38- } ) ;
32+ . then ( ( ) => {
33+ connector . disconnect ( ( DBerr ) => {
34+ if ( DBerr ) console . log ( "Database disconnect error : " , DBerr ) ;
35+ server . close ( ( serverErr ) => {
36+ if ( serverErr ) console . log ( serverErr ) ;
37+ callback ( ) ;
3938 } ) ;
39+ } ) ;
4040 } ) ;
4141}
4242
4343
44- afterAll ( ( done ) => {
45- cleanUp ( done ) ;
46- } ) ;
47-
48- describe ( "Activity API" , ( ) => {
49- it ( "should create activity" , async ( ) => {
50- const response = await agent . post ( "/activity/add" ) . send ( {
51- startTime :"11:45 AM" ,
52- duration :2 ,
53- course : "64fc3c8bde9fa947ea1f412f" ,
54- faculty : "64fc3c8bde9fa947ea1f412f" ,
55- type :"LECTURE" ,
56- task :"Practical" ,
57- group : "64fc3c8bde9fa947ea1f412f" ,
58- students :"xyz" ,
59- } ) ;
44+ afterAll ( ( done ) => {
45+ cleanUp ( done ) ;
46+ } ) ;
6047
61- expect ( response . status ) . toBe ( 200 ) ;
62- expect ( response . body . res ) . toMatch ( / a d d e d a c t i v i t y / ) ;
63- } ) ;
48+ describe ( "Activity API" , ( ) => {
49+ it ( "should create activity" , async ( ) => {
50+ const response = await agent . post ( "/activity/add" ) . send ( {
51+ activityBlueprint : "5f8778b54b553439ac49a03a" ,
52+ startTime : "2023-06-18T14:11:30Z" ,
53+ duration : 2 ,
54+ course : "5f8778b54b553439ac49a03a" ,
55+ faculty : "5f8778b54b553439ac49a03a" ,
56+ type : "LECTURE" ,
57+ task : [ "5f8778b54b553439ac49a03a" ] ,
58+ group : "5f8778b54b553439ac49a03a" ,
59+ students : [ "5f8778b54b553439ac49a03a" ]
60+ } ) ;
61+
62+ expect ( response . status ) . toBe ( 200 ) ;
63+ expect ( response . body . res ) . toMatch ( / a d d e d a c t i v i t y / ) ;
64+ } ) ;
6465
65- describe ( "after adding activity" , ( ) => {
66- beforeEach ( async ( ) => {
67- await agent . post ( "/activity/add" ) . send ( {
68- startTime :"11:45 AM" ,
69- duration :2 ,
70- course : "64fc3c8bde9fa947ea1f412f" ,
66+ describe ( "after adding activity" , ( ) => {
67+ let id ;
68+ beforeEach ( async ( ) => {
69+ id = await agent . post ( "/activity/add" ) . send ( {
70+ activityBlueprint : "64fc3c8bde9fa947ea1f412f" ,
71+ startTime : "2023-06-18T14:11:30Z" ,
72+ duration : 2 ,
73+ course : "64fc3c8bde9fa947ea1f412f" ,
7174 faculty : "64fc3c8bde9fa947ea1f412f" ,
72- type :"LECTURE" ,
73- task :"Practical" ,
75+ type : "LECTURE" ,
76+ task : [ "64fc3c8bde9fa947ea1f412f" ] ,
7477 group : "64fc3c8bde9fa947ea1f412f" ,
75- students :"xyz" ,
76- } ) ;
77- } ) ;
78+ students : [ "64fc3c8bde9fa947ea1f412f" ]
79+ } ) ;
80+ id = JSON . parse ( id . res . text ) . id ;
81+ } ) ;
7882
79- afterEach ( async ( ) => {
80- await activityModel . remove ( {
81- startTime :"11:45 AM" ,
82- duration :2 ,
83- course : "64fc3c8bde9fa947ea1f412f" ,
83+ afterEach ( async ( ) => {
84+ await activityModel . remove ( {
85+ activityBlueprint : "64fc3c8bde9fa947ea1f412f" ,
86+ startTime : "2023-06-18T14:11:30Z" ,
87+ duration : 2 ,
88+ course : "64fc3c8bde9fa947ea1f412f" ,
8489 faculty : "64fc3c8bde9fa947ea1f412f" ,
85- type :"LECTURE" ,
86- task :"Practical" ,
90+ type : "LECTURE" ,
91+ task : [ "64fc3c8bde9fa947ea1f412f" ] ,
8792 group : "64fc3c8bde9fa947ea1f412f" ,
88- students :"xyz" ,
89- } ) ;
90- } ) ;
91-
92- it ( "should read activity" , async ( ) => {
93- const response = await agent
94- . post ( "/activity/list" )
95- . send ( { startTime :"11:45 AM" } ) ;
96- expect ( response . status ) . toBe ( 200 ) ;
97- expect ( response . body . res ) . toBeDefined ( ) ;
98- } ) ;
93+ students : [ "64fc3c8bde9fa947ea1f412f" ]
94+ } ) ;
95+ } ) ;
9996
100- it ( "should update activity" , async ( ) => {
101- const response = await agent
102- . post ( "/activity/update" )
103- . send ( {
104- startTime :"11:45 AM" ,
105- duration :2 ,
106- course : "64fc3c8bde9fa947ea1f412f" ,
107- faculty : "64fc3c8bde9fa947ea1f412f" ,
108- type :"LECTURE" ,
109- task :"Practical" ,
110- group : "64fc3c8bde9fa947ea1f412f" ,
111- students :"xyz" , } ) ;
97+ it ( "should read activity" , async ( ) => {
98+ const response = await agent
99+ . get ( "/activity/list" )
100+ . send ( { startTime : "2023-06-18T14:11:30Z" } ) ;
101+ expect ( response . status ) . toBe ( 200 ) ;
102+ expect ( response . body . res ) . toBeDefined ( ) ;
103+ } ) ;
112104
113- expect ( response . status ) . toBe ( 200 ) ;
114- expect ( response . body . res ) . toMatch ( / u p d a t e d a c t i v i t y / ) ;
115- } ) ;
105+ it ( "should update activity" , async ( ) => {
106+ console . log ( id )
107+ const response = await agent
108+ . post ( `/activity/update/${ id } ` )
109+ . send ( {
110+ duration : 5 ,
116111 } ) ;
112+
113+ expect ( response . status ) . toBe ( 200 ) ;
114+ expect ( response . body . res ) . toMatch ( / u p d a t e d a c t i v i t y / ) ;
117115 } ) ;
116+ } ) ;
117+ } ) ;
0 commit comments