From 57e9e09c181331281bafe03466c7aaa01b1792f7 Mon Sep 17 00:00:00 2001 From: anushac14 <113647676+anushac14@users.noreply.github.com> Date: Mon, 12 Aug 2024 16:51:54 -0400 Subject: [PATCH] used supertest --- .github/workflows/ci.yml | 2 +- app.js | 19 +- controllers/employeeController.js | 2 +- models/{employee.js => employeeModel.js} | 0 package-lock.json | 224 +++++++++++++++++++---- package.json | 1 + routes/employee.js | 11 -- routes/employeeRoutes.js | 11 ++ test/employeeRoute.test.js | 55 +++--- 9 files changed, 235 insertions(+), 90 deletions(-) rename models/{employee.js => employeeModel.js} (100%) delete mode 100644 routes/employee.js create mode 100644 routes/employeeRoutes.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 496235a..b962f75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,7 +35,7 @@ jobs: run: npm i - name: Install dev dependencies - run: npm install --save-dev jest chai supertest mongoose sinon dotenv + run: npm install --save-dev jest chai supertest mongoose sinon dotenv chai-http - name: Run tests run: npm test diff --git a/app.js b/app.js index 6f031a7..1df658e 100644 --- a/app.js +++ b/app.js @@ -1,3 +1,4 @@ +// app.js const express = require('express'); const mongoose = require('mongoose'); require('dotenv').config(); @@ -19,20 +20,6 @@ app.use('/api/stakeholders', stakeholderRoutes); app.use('/api/documents', documentRoutes); app.use('/api/fundraisingRounds', fundraisingRoundRoutes); app.use('/api/equityPlans', equityPlanRoutes); -app.use('/api/documentEmbeddings', documentEmbeddingRoutes); +app.use('/api/documentEmbeddings', documentEmbeddingRoutes); -const connectDB = async () => { - try { - const uri = process.env.MONGODB_URI; - if (!uri) { - throw new Error("MONGODB_URI is not defined in the environment variables."); - } - await mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true }); - console.log('MongoDB connected'); - } catch (err) { - console.error(err.message); - process.exit(1); - } -}; - -module.exports = { app, connectDB }; +module.exports = app; // Only export the Express app diff --git a/controllers/employeeController.js b/controllers/employeeController.js index 57a4b6d..ec40246 100644 --- a/controllers/employeeController.js +++ b/controllers/employeeController.js @@ -1,4 +1,4 @@ -const Employee = require("../models/employee"); +const Employee = require("../models/employeeModel"); // Create a new employee exports.createEmployee = async (req, res) => { diff --git a/models/employee.js b/models/employeeModel.js similarity index 100% rename from models/employee.js rename to models/employeeModel.js diff --git a/package-lock.json b/package-lock.json index 79e9432..650f5c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "dependencies": { "argon2": "^0.40.3", + "chai-http": "^5.0.0", "dotenv": "^16.4.5", "express": "^4.17.1", "express-async-handler": "^1.2.0", @@ -1253,8 +1254,7 @@ "node_modules/asap": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", - "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==", - "dev": true + "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==" }, "node_modules/assertion-error": { "version": "1.1.0", @@ -1278,8 +1278,7 @@ "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/b4a": { "version": "1.6.6", @@ -1639,6 +1638,57 @@ "node": ">=4" } }, + "node_modules/chai-http": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/chai-http/-/chai-http-5.0.0.tgz", + "integrity": "sha512-nWtyQ0/+VSayMEESPbBE2v5HYd24Jh67Alh9/dxecfZ4viFAsGN3leFwy3EsNu1DbEi/HsTVW+9pT8p79a2J+g==", + "license": "MIT", + "dependencies": { + "charset": "^1.0.1", + "cookiejar": "^2.1.4", + "is-ip": "^5.0.1", + "methods": "^1.1.2", + "qs": "^6.12.1", + "superagent": "^9" + }, + "engines": { + "node": ">=18.20.0" + } + }, + "node_modules/chai-http/node_modules/formidable": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-3.5.1.tgz", + "integrity": "sha512-WJWKelbRHN41m5dumb0/k8TeAx7Id/y3a+Z7QfhxP/htI9Js5zYaEDtG8uMgG0vM0lOlqnmjE99/kfpOYi/0Og==", + "license": "MIT", + "dependencies": { + "dezalgo": "^1.0.4", + "hexoid": "^1.0.0", + "once": "^1.4.0" + }, + "funding": { + "url": "https://ko-fi.com/tunnckoCore/commissions" + } + }, + "node_modules/chai-http/node_modules/superagent": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-9.0.2.tgz", + "integrity": "sha512-xuW7dzkUpcJq7QnhOsnNUgtYp3xRwpt2F7abdRYIpCsAt0hhUqia0EdxyXZQQpNmGtsCzYHryaKSV3q3GJnq7w==", + "license": "MIT", + "dependencies": { + "component-emitter": "^1.3.0", + "cookiejar": "^2.1.4", + "debug": "^4.3.4", + "fast-safe-stringify": "^2.1.1", + "form-data": "^4.0.0", + "formidable": "^3.5.1", + "methods": "^1.1.2", + "mime": "2.6.0", + "qs": "^6.11.0" + }, + "engines": { + "node": ">=14.18.0" + } + }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -1664,6 +1714,15 @@ "node": ">=10" } }, + "node_modules/charset": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/charset/-/charset-1.0.1.tgz", + "integrity": "sha512-6dVyOOYjpfFcL1Y4qChrAoQLRHvj2ziyhcm0QJlhOcAhykL/k1kTUPbeo+87MNRTRdk2OIIsIXbuF3x2wi5EXg==", + "license": "MIT", + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/check-error": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.3.tgz", @@ -1712,6 +1771,21 @@ "node": ">=12" } }, + "node_modules/clone-regexp": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/clone-regexp/-/clone-regexp-3.0.0.tgz", + "integrity": "sha512-ujdnoq2Kxb8s3ItNBtnYeXdm07FcU0u8ARAT1lQ2YdMwQC+cdiXX8KoqMVuglztILivceTtp4ivqGSmEmhBUJw==", + "license": "MIT", + "dependencies": { + "is-regexp": "^3.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -1764,7 +1838,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -1791,7 +1864,6 @@ "version": "1.3.1", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.1.tgz", "integrity": "sha512-T0+barUSQRTUQASh8bx02dl+DhF54GtIDY13Y3m9oWTklKbb3Wv974meRpeZ3lp1JpLVECWWNHC4vaG2XHXouQ==", - "dev": true, "funding": { "url": "https://github.com/sponsors/sindresorhus" } @@ -1821,6 +1893,18 @@ "node": ">= 0.6" } }, + "node_modules/convert-hrtime": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/convert-hrtime/-/convert-hrtime-5.0.0.tgz", + "integrity": "sha512-lOETlkIeYSJWcbbcvjRKGxVMXJR+8+OQb/mTPbA4ObPMytYIsUbuOE0Jzy60hjARYszq1id0j8KgVhC+WGZVTg==", + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/convert-source-map": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", @@ -1843,8 +1927,7 @@ "node_modules/cookiejar": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz", - "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==", - "dev": true + "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==" }, "node_modules/core-util-is": { "version": "1.0.3", @@ -1890,7 +1973,6 @@ "version": "4.3.5", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.5.tgz", "integrity": "sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==", - "dev": true, "dependencies": { "ms": "2.1.2" }, @@ -1959,7 +2041,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true, "engines": { "node": ">=0.4.0" } @@ -2002,7 +2083,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz", "integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==", - "dev": true, "dependencies": { "asap": "^2.0.0", "wrappy": "1" @@ -2287,8 +2367,7 @@ "node_modules/fast-safe-stringify": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", - "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==", - "dev": true + "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==" }, "node_modules/fb-watchman": { "version": "2.0.2", @@ -2406,6 +2485,20 @@ } } }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/formidable": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.2.tgz", @@ -2465,6 +2558,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/function-timeout": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/function-timeout/-/function-timeout-0.1.1.tgz", + "integrity": "sha512-0NVVC0TaP7dSTvn1yMiy6d6Q8gifzbvQafO46RtLG/kHJUBNd+pVRGOBoK44wNBvtSPUJRfdVvkFdD3p0xvyZg==", + "license": "MIT", + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -2652,7 +2757,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz", "integrity": "sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==", - "dev": true, "engines": { "node": ">=8" } @@ -2785,6 +2889,18 @@ "integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==", "dev": true }, + "node_modules/ip-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-5.0.0.tgz", + "integrity": "sha512-fOCG6lhoKKakwv+C6KdsOnGvgXnmgfmp0myi3bcNwj3qfwPAxRKWEuFhvEFF7ceYIz6+1jRZ+yguLFAmUNPEfw==", + "license": "MIT", + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/ipaddr.js": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", @@ -2832,6 +2948,22 @@ "node": ">=6" } }, + "node_modules/is-ip": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/is-ip/-/is-ip-5.0.1.tgz", + "integrity": "sha512-FCsGHdlrOnZQcp0+XT5a+pYowf33itBalCl+7ovNXC/7o5BhIpG14M3OrpPPdBSIQJCm+0M5+9mO7S9VVTTCFw==", + "license": "MIT", + "dependencies": { + "ip-regex": "^5.0.0", + "super-regex": "^0.2.0" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", @@ -2841,6 +2973,18 @@ "node": ">=0.12.0" } }, + "node_modules/is-regexp": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/is-regexp/-/is-regexp-3.1.0.tgz", + "integrity": "sha512-rbku49cWloU5bSMI+zaRaXdQHXnthP6DZ/vLnfdSKyL4zUzuWnomtOEiZZOd+ioQ+avFo/qau3KPTc7Fjy1uPA==", + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-stream": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", @@ -3767,7 +3911,6 @@ "version": "2.6.0", "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==", - "dev": true, "bin": { "mime": "cli.js" }, @@ -4316,7 +4459,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "dev": true, "dependencies": { "wrappy": "1" } @@ -4600,7 +4742,6 @@ "version": "6.12.3", "resolved": "https://registry.npmjs.org/qs/-/qs-6.12.3.tgz", "integrity": "sha512-AWJm14H1vVaO/iNZ4/hO+HyaTehuy9nRqVdkTqlJt0HWvBiBIEXFmb4C0DGeYo3Xes9rrEW+TxHsaigCbN5ICQ==", - "dev": true, "dependencies": { "side-channel": "^1.0.6" }, @@ -5151,6 +5292,23 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/super-regex": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/super-regex/-/super-regex-0.2.0.tgz", + "integrity": "sha512-WZzIx3rC1CvbMDloLsVw0lkZVKJWbrkJ0k1ghKFmcnPrW1+jWbgTkTEWVtD9lMdmI4jZEz40+naBxl1dCUhXXw==", + "license": "MIT", + "dependencies": { + "clone-regexp": "^3.0.0", + "function-timeout": "^0.1.0", + "time-span": "^5.1.0" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/superagent": { "version": "8.1.2", "resolved": "https://registry.npmjs.org/superagent/-/superagent-8.1.2.tgz", @@ -5173,20 +5331,6 @@ "node": ">=6.4.0 <13 || >=14" } }, - "node_modules/superagent/node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/superagent/node_modules/semver": { "version": "7.6.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", @@ -5270,6 +5414,21 @@ "b4a": "^1.6.4" } }, + "node_modules/time-span": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/time-span/-/time-span-5.1.0.tgz", + "integrity": "sha512-75voc/9G4rDIJleOo4jPvN4/YC4GRZrY8yy1uU4lwrB3XEQbWve8zXoO5No4eFrGcTAMYyoY67p8jRQdtA1HbA==", + "license": "MIT", + "dependencies": { + "convert-hrtime": "^5.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/tmpl": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", @@ -5514,8 +5673,7 @@ "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "dev": true + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, "node_modules/write-file-atomic": { "version": "4.0.2", diff --git a/package.json b/package.json index 9e5859b..80fb59c 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ }, "dependencies": { "argon2": "^0.40.3", + "chai-http": "^5.0.0", "dotenv": "^16.4.5", "express": "^4.17.1", "express-async-handler": "^1.2.0", diff --git a/routes/employee.js b/routes/employee.js deleted file mode 100644 index 71c2eb4..0000000 --- a/routes/employee.js +++ /dev/null @@ -1,11 +0,0 @@ -const express = require("express"); -const router = express.Router(); -const employeeController = require("../controllers/employeeController"); - -router.post("/employees", employeeController.createEmployee); -router.get("/employees", employeeController.getEmployees); -router.get("/employees/:id", employeeController.getEmployeeById); -router.put("/employees/:id", employeeController.updateEmployee); -router.delete("/employees/:id", employeeController.deleteEmployee); - -module.exports = router; diff --git a/routes/employeeRoutes.js b/routes/employeeRoutes.js new file mode 100644 index 0000000..bbcaed5 --- /dev/null +++ b/routes/employeeRoutes.js @@ -0,0 +1,11 @@ +const express = require("express"); +const router = express.Router(); +const employeeController = require("../controllers/employeeController"); + +router.post("/", employeeController.createEmployee); +router.get("/", employeeController.getEmployees); +router.get("/:id", employeeController.getEmployeeById); +router.put("/:id", employeeController.updateEmployee); +router.delete("/:id", employeeController.deleteEmployee); + +module.exports = router; diff --git a/test/employeeRoute.test.js b/test/employeeRoute.test.js index 92c7cb2..8c91e1d 100644 --- a/test/employeeRoute.test.js +++ b/test/employeeRoute.test.js @@ -1,31 +1,35 @@ -const chai = require("chai"); -const server = require("../app"); -const Employee = require("../models/employee"); -const should = chai.should(); +const request = require("supertest"); +const mongoose = require("mongoose"); +const app = require("../app"); // Ensure this points to your Express app +const Employee = require("../models/employeeModel"); + +beforeAll(async () => { + await mongoose.connect("mongodb://localhost:27017/testDB", { + useNewUrlParser: true, + useUnifiedTopology: true, + }); +}); + +afterAll(async () => { + await mongoose.connection.close(); +}); describe("Employee Routes", () => { - beforeEach((done) => { - Employee.deleteMany({}, (err) => { - done(); - }); + beforeEach(async () => { + await Employee.deleteMany({}); }); describe("GET /employees", () => { - it("it should GET all the employees", (done) => { - chai - .request(server) - .get("/employees") - .end((err, res) => { - res.should.have.status(200); - res.body.should.be.a("array"); - res.body.length.should.be.eql(0); - done(); - }); + it("it should GET all the employees", async () => { + const response = await request(app).get("/employees"); + expect(response.statusCode).toBe(200); + expect(response.body).toBeInstanceOf(Array); + expect(response.body.length).toBe(0); }); }); describe("POST /employees", () => { - it("it should POST a new employee", (done) => { + it("it should POST a new employee", async () => { const employee = { EmployeeID: "E12345", Name: "John Doe", @@ -47,16 +51,11 @@ describe("Employee Routes", () => { TaxLiability: 300, }, }; - chai - .request(server) + const response = await request(app) .post("/employees") - .send(employee) - .end((err, res) => { - res.should.have.status(201); - res.body.should.be.a("object"); - res.body.should.have.property("Name").eql("John Doe"); - done(); - }); + .send(employee); + expect(response.statusCode).toBe(201); + expect(response.body).toHaveProperty("Name", "John Doe"); }); }); });