11import { jest } from "@jest/globals" ; // eslint-disable-line import/no-extraneous-dependencies
2- import mongoose from "mongoose" ;
32import departmentmodel from "#models/department" ;
43import connector from "#models/databaseUtil" ;
4+ import accreditationModel from "#models/accreditation" ;
5+ import infrastructureModel from "#models/infrastructure" ;
6+ import organizationModel from "#models/organization" ;
57
68jest . mock ( "#util" ) ;
79const { agent } = global ;
810
11+ let accreditationIds ;
12+ let infrastructureIds ;
13+ let organizationIds ;
14+
915// test case for deletion
1016
1117function cleanUp ( callback ) {
@@ -14,9 +20,9 @@ function cleanUp(callback) {
1420 name : "Electronics" ,
1521 acronym : "COMPS" ,
1622 yearOfStarting : "2020-09-01T00:00:00.000Z" ,
17- accreditations : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03a" ) ] ,
18- infrastructures : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03b" ) ] ,
19- organization : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03b" ) ] ,
23+ accreditations : [ accreditationIds ] ,
24+ infrastructures : [ infrastructureIds ] ,
25+ organization : [ organizationIds ] ,
2026 } )
2127 . then ( ( ) => {
2228 connector . disconnect ( ( DBerr ) => {
@@ -26,6 +32,21 @@ function cleanUp(callback) {
2632 } ) ;
2733}
2834
35+ /* eslint-disable no-underscore-dangle */
36+ async function getIds ( callback ) {
37+ accreditationIds = await accreditationModel . read ( { } , 1 ) ;
38+ accreditationIds = accreditationIds . data [ 0 ] . _id ;
39+ infrastructureIds = await infrastructureModel . read ( { } , 1 ) ;
40+ infrastructureIds = infrastructureIds . data [ 0 ] . _id ;
41+ organizationIds = await organizationModel . read ( { } , 1 ) ;
42+ organizationIds = organizationIds . data [ 0 ] . _id ;
43+ callback ( ) ;
44+ }
45+
46+ beforeAll ( ( done ) => {
47+ getIds ( done ) ;
48+ } ) ;
49+
2950afterAll ( ( done ) => {
3051 cleanUp ( done ) ;
3152} ) ;
@@ -36,9 +57,9 @@ describe("Department CRUD", () => {
3657 name : "Computer" ,
3758 acronym : "COMPS" ,
3859 yearOfStarting : "2020-09-01T00:00:00.000Z" ,
39- accreditations : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03a" ) ] ,
40- infrastructures : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03b" ) ] ,
41- organization : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03b" ) ] ,
60+ accreditations : [ accreditationIds ] ,
61+ infrastructures : [ infrastructureIds ] ,
62+ organization : [ organizationIds ] ,
4263 } ) ;
4364
4465 expect ( response . status ) . toBe ( 200 ) ;
@@ -52,9 +73,9 @@ describe("Department CRUD", () => {
5273 name : "Computer" ,
5374 acronym : "COMPS" ,
5475 yearOfStarting : "2020-09-01T00:00:00.000Z" ,
55- accreditations : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03a" ) ] ,
56- infrastructures : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03b" ) ] ,
57- organization : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03b" ) ] ,
76+ accreditations : [ accreditationIds ] ,
77+ infrastructures : [ infrastructureIds ] ,
78+ organization : [ organizationIds ] ,
5879 } ) ;
5980 id = JSON . parse ( id . res . text ) . id ;
6081 } ) ;
@@ -64,9 +85,9 @@ describe("Department CRUD", () => {
6485 name : "Computer" ,
6586 acronym : "COMPS" ,
6687 yearOfStarting : "2020-09-01T00:00:00.000Z" ,
67- accreditations : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03a" ) ] ,
68- infrastructures : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03b" ) ] ,
69- organization : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03b" ) ] ,
88+ accreditations : [ accreditationIds ] ,
89+ infrastructures : [ infrastructureIds ] ,
90+ organization : [ organizationIds ] ,
7091 } ) ;
7192 } ) ;
7293
@@ -75,9 +96,9 @@ describe("Department CRUD", () => {
7596 name : "Computer" ,
7697 acronym : "COMPS" ,
7798 yearOfStarting : "2020-09-01T00:00:00.000Z" ,
78- accreditations : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03a" ) ] ,
79- infrastructures : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03b" ) ] ,
80- organization : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03b" ) ] ,
99+ accreditations : [ accreditationIds ] ,
100+ infrastructures : [ infrastructureIds ] ,
101+ organization : [ organizationIds ] ,
81102 } ) ;
82103 expect ( response . body . res ) . not . toBeNull ( ) ;
83104 } ) ;
@@ -87,9 +108,9 @@ describe("Department CRUD", () => {
87108 name : "Electronics" ,
88109 acronym : "COMPS" ,
89110 yearOfStarting : "2020-09-01T00:00:00.000Z" ,
90- accreditations : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03a" ) ] ,
91- infrastructures : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03b" ) ] ,
92- organization : [ mongoose . Types . ObjectId ( "5f8778b54b553439ac49a03b" ) ] ,
111+ accreditations : [ accreditationIds ] ,
112+ infrastructures : [ infrastructureIds ] ,
113+ organization : [ organizationIds ] ,
93114 } ) ;
94115 expect ( response . status ) . toBe ( 200 ) ;
95116 expect ( response . body . res ) . toMatch ( / d e p a r t m e n t u p d a t e d / ) ;
0 commit comments