diff --git a/package-lock.json b/package-lock.json index 801ce06..0fa26a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,7 +31,7 @@ "nyc": "^15.1.0", "proxyquire": "^2.1.3", "sinon": "^17.0.1", - "supertest": "^6.3.3" + "supertest": "^7.0.0" }, "engines": { "node": "20.x.x" @@ -3106,15 +3106,14 @@ } }, "node_modules/formidable": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.2.tgz", - "integrity": "sha512-CM3GuJ57US06mlpQ47YcunuUZ9jpm8Vx+P2CGt2j7HpgkKZO/DJYQ0Bobim8G6PFQmK5lOqOOdUXboU+h73A4g==", + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-3.5.2.tgz", + "integrity": "sha512-Jqc1btCy3QzRbJaICGwKcBfGWuLADRerLzDqi2NwSt/UkXLsHJw2TVResiaoBufHVHy9aSgClOHCeJsSsFLTbg==", "dev": true, "dependencies": { "dezalgo": "^1.0.4", - "hexoid": "^1.0.0", - "once": "^1.4.0", - "qs": "^6.11.0" + "hexoid": "^2.0.0", + "once": "^1.4.0" }, "funding": { "url": "https://ko-fi.com/tunnckoCore/commissions" @@ -3460,9 +3459,9 @@ } }, "node_modules/hexoid": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz", - "integrity": "sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-2.0.0.tgz", + "integrity": "sha512-qlspKUK7IlSQv2o+5I7yhUd7TxlOG2Vr5LTa3ve2XSNVKAL/n/u/7KLvKmFNimomDIKvZFXWHv0T12mv7rT8Aw==", "dev": true, "engines": { "node": ">=8" @@ -6638,10 +6637,9 @@ } }, "node_modules/superagent": { - "version": "8.1.2", - "resolved": "https://registry.npmjs.org/superagent/-/superagent-8.1.2.tgz", - "integrity": "sha512-6WTxW1EB6yCxV5VFOIPQruWGHqc3yI7hEmZK6h+pyk69Lk/Ut7rLUY6W/ONF2MjBuGjvmMiIpsrVJ2vjrHlslA==", - "deprecated": "Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net", + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-9.0.2.tgz", + "integrity": "sha512-xuW7dzkUpcJq7QnhOsnNUgtYp3xRwpt2F7abdRYIpCsAt0hhUqia0EdxyXZQQpNmGtsCzYHryaKSV3q3GJnq7w==", "dev": true, "dependencies": { "component-emitter": "^1.3.0", @@ -6649,14 +6647,13 @@ "debug": "^4.3.4", "fast-safe-stringify": "^2.1.1", "form-data": "^4.0.0", - "formidable": "^2.1.2", + "formidable": "^3.5.1", "methods": "^1.1.2", "mime": "2.6.0", - "qs": "^6.11.0", - "semver": "^7.3.8" + "qs": "^6.11.0" }, "engines": { - "node": ">=6.4.0 <13 || >=14" + "node": ">=14.18.0" } }, "node_modules/superagent/node_modules/mime": { @@ -6672,16 +6669,16 @@ } }, "node_modules/supertest": { - "version": "6.3.4", - "resolved": "https://registry.npmjs.org/supertest/-/supertest-6.3.4.tgz", - "integrity": "sha512-erY3HFDG0dPnhw4U+udPfrzXa4xhSG+n4rxfRuZWCUvjFWwKl+OxWf/7zk50s84/fAAs7vf5QAb9uRa0cCykxw==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/supertest/-/supertest-7.0.0.tgz", + "integrity": "sha512-qlsr7fIC0lSddmA3tzojvzubYxvlGtzumcdHgPwbFWMISQwL22MhM2Y3LNt+6w9Yyx7559VW5ab70dgphm8qQA==", "dev": true, "dependencies": { "methods": "^1.1.2", - "superagent": "^8.1.2" + "superagent": "^9.0.1" }, "engines": { - "node": ">=6.4.0" + "node": ">=14.18.0" } }, "node_modules/supports-color": { diff --git a/package.json b/package.json index c45084f..1888ccb 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "nyc": "^15.1.0", "proxyquire": "^2.1.3", "sinon": "^17.0.1", - "supertest": "^6.3.3" + "supertest": "^7.0.0" }, "dependencies": { "express": "^4.18.2", diff --git a/test/app.test.js b/test/app.test.js index 9ba28c5..d8d82bb 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -31,7 +31,7 @@ routes.forEach((route) => { db.query = () => Promise.resolve(); }); - it("should pass params from the url to db.query and render the result", (done) => { + it("should pass params from the url to db.query and render the result", async () => { db.query = (params) => { expect(params.reportAgency).to.equal("fake-agency"); expect(params.reportName).to.equal("fake-report"); @@ -46,19 +46,16 @@ routes.forEach((route) => { .get(`/${route}/agencies/fake-agency/reports/fake-report/data`) .expect(200); - dataRequest - .then((actualResponse) => { - const expectedResponseBody = handleIfRouteNotice(route, [ - { id: 1, date: "2017-01-01" }, - { id: 2, date: "2017-01-02" }, - ]); - expect(actualResponse.body).to.deep.equal(expectedResponseBody); - done(); - }) - .catch(done); + await dataRequest.then((actualResponse) => { + const expectedResponseBody = handleIfRouteNotice(route, [ + { id: 1, date: "2017-01-01" }, + { id: 2, date: "2017-01-02" }, + ]); + expect(actualResponse.body).to.deep.equal(expectedResponseBody); + }); }); - it("should not pass the agency param if the request does not specify an agency", (done) => { + it("should not pass the agency param if the request does not specify an agency", async () => { db.query = (params) => { expect(params.reportAgency).to.be.undefined; expect(params.reportName).to.equal("fake-report"); @@ -73,19 +70,16 @@ routes.forEach((route) => { .get(`/${route}/reports/fake-report/data`) .expect(200); - dataRequest - .then((actualResponse) => { - const expectedResponseBody = handleIfRouteNotice(route, [ - { id: 1, date: "2017-01-01" }, - { id: 2, date: "2017-01-02" }, - ]); - expect(actualResponse.body).to.deep.equal(expectedResponseBody); - done(); - }) - .catch(done); + await dataRequest.then((actualResponse) => { + const expectedResponseBody = handleIfRouteNotice(route, [ + { id: 1, date: "2017-01-01" }, + { id: 2, date: "2017-01-02" }, + ]); + expect(actualResponse.body).to.deep.equal(expectedResponseBody); + }); }); - it("should merge the params in the url with query params", (done) => { + it("should merge the params in the url with query params", async () => { db.query = (params) => { expect(params.reportAgency).to.equal("fake-agency"); expect(params.reportName).to.equal("fake-report"); @@ -101,19 +95,16 @@ routes.forEach((route) => { .get(`/${route}/agencies/fake-agency/reports/fake-report/data?limit=50`) .expect(200); - dataRequest - .then((actualResponse) => { - const expectedResponseBody = handleIfRouteNotice(route, [ - { id: 1, date: "2017-01-01" }, - { id: 2, date: "2017-01-02" }, - ]); - expect(actualResponse.body).to.deep.equal(expectedResponseBody); - done(); - }) - .catch(done); + await dataRequest.then((actualResponse) => { + const expectedResponseBody = handleIfRouteNotice(route, [ + { id: 1, date: "2017-01-01" }, + { id: 2, date: "2017-01-02" }, + ]); + expect(actualResponse.body).to.deep.equal(expectedResponseBody); + }); }); - it("should respond with a 400 if db.query rejects", (done) => { + it("should respond with a 400 if db.query rejects", async () => { db.query = () => Promise.reject("This is a test of the emergency broadcast system."); @@ -121,19 +112,16 @@ routes.forEach((route) => { .get(`/${route}/agencies/fake-agency/reports/fake-report/data`) .expect(400); - dataRequest - .then((actualResponse) => { - const expectedResponseBody = { - message: "An error occurred. Please check the application logs.", - status: 400, - }; - expect(actualResponse.body).to.deep.equal(expectedResponseBody); - done(); - }) - .catch(done); + await dataRequest.then((actualResponse) => { + const expectedResponseBody = { + message: "An error occurred. Please check the application logs.", + status: 400, + }; + expect(actualResponse.body).to.deep.equal(expectedResponseBody); + }); }); - it("should respond with a 400 if the domain report is not one of the acceptable kinds of reports", (done) => { + it("should respond with a 400 if the domain report is not one of the acceptable kinds of reports", async () => { db.query = (params) => { expect(params.domain).to.equal("fakeiscool.gov"); expect(params.reportName).to.equal("browser"); @@ -155,20 +143,17 @@ routes.forEach((route) => { .get(`/${route}/domain/fakeiscool.gov/reports/browser/data`) .expect(400); - dataRequest - .then((actualResponse) => { - const expectedResponseBody = { - message: - "You are requesting a report that cannot be filtered on domain. Please try one of the following reports: site, domain, download, second-level-domain.", - status: 400, - }; - expect(actualResponse.body).to.deep.equal(expectedResponseBody); - done(); - }) - .catch(done); + await dataRequest.then((actualResponse) => { + const expectedResponseBody = { + message: + "You are requesting a report that cannot be filtered on domain. Please try one of the following reports: site, domain, download, second-level-domain.", + status: 400, + }; + expect(actualResponse.body).to.deep.equal(expectedResponseBody); + }); }); - it("should pass params from the url to db.query and render the result for a domain query for a non-download report", (done) => { + it("should pass params from the url to db.query and render the result for a domain query for a non-download report", async () => { db.query = (params) => { expect(params.domain).to.equal("fakeiscool.gov"); expect(params.reportName).to.equal("site"); @@ -187,20 +172,17 @@ routes.forEach((route) => { .get(`/${route}/domain/fakeiscool.gov/reports/site/data`) .expect(200); - dataRequest - .then((actualResponse) => { - const expectedResponseBody = handleIfRouteNotice(route, [ - { - id: 1, - date: "2017-01-01", - report_name: "site", - domain: "fakeiscool.gov", - }, - ]); - expect(actualResponse.body).to.deep.equal(expectedResponseBody); - done(); - }) - .catch(done); + await dataRequest.then((actualResponse) => { + const expectedResponseBody = handleIfRouteNotice(route, [ + { + id: 1, + date: "2017-01-01", + report_name: "site", + domain: "fakeiscool.gov", + }, + ]); + expect(actualResponse.body).to.deep.equal(expectedResponseBody); + }); }); }); }); @@ -210,7 +192,7 @@ describe(`app with unspupported version`, () => { db.query = () => Promise.resolve(); }); - it("should not accept unsupported versions", (done) => { + it("should not accept unsupported versions", async () => { const unsupportedVersion = "v2.x"; db.query = (params) => { @@ -232,15 +214,12 @@ describe(`app with unspupported version`, () => { ) .expect(404); - dataRequest - .then((actualResponse) => { - const expectedResponse = { - _body: expectedErrorMessage, - status: 404, - }; - expect(actualResponse).to.include(expectedResponse); - done(); - }) - .catch(done); + await dataRequest.then((actualResponse) => { + const expectedResponse = { + _body: expectedErrorMessage, + status: 404, + }; + expect(actualResponse).to.include(expectedResponse); + }); }); }); diff --git a/test/db.test.js b/test/db.test.js index 91b08b2..e475c6b 100644 --- a/test/db.test.js +++ b/test/db.test.js @@ -9,19 +9,16 @@ const db = proxyquire("../src/db", { describe("db", () => { const apiVersions = ["v1.1", "v2"]; - before((done) => { + before(async () => { // Setup the test database client - database.createClient().then(() => done()); + await database.createClient(); }); - after((done) => { + after(async () => { // Clean up the test database client and the application database client - database - .destroyClient() - .then(() => { - return db.dbClient.destroy(); - }) - .then(() => done()); + await database.destroyClient().then(() => { + return db.dbClient.destroy(); + }); }); apiVersions.forEach((apiVersion) => { @@ -30,13 +27,13 @@ describe("db", () => { apiVersion === "v1.1" ? "analytics_data" : "analytics_data_ga4"; const queryVersion = apiVersion === `v1.1` ? "1.1" : "2"; - beforeEach((done) => { - database.resetSchema(table).then(() => done()); + beforeEach(async () => { + await database.resetSchema(table); }); describe(".query(params)", () => { - it("should return all rows for the given agency and report", (done) => { - database + it("should return all rows for the given agency and report", async () => { + await database .client(table) .insert([ { report_name: "my-report", report_agency: "my-agency" }, @@ -55,13 +52,11 @@ describe("db", () => { expect(results).to.have.length(1); expect(results[0].report_name).to.equal("my-report"); expect(results[0].report_agency).to.equal("my-agency"); - done(); - }) - .catch(done); + }); }); - it("should return all rows without an agency if no agency name is given", (done) => { - database + it("should return all rows without an agency if no agency name is given", async () => { + await database .client(table) .insert([ { report_name: "my-report", report_agency: "not-my-agency" }, @@ -77,13 +72,11 @@ describe("db", () => { expect(results).to.have.length(1); expect(results[0].report_name).to.equal("my-report"); expect(results[0].report_agency).to.be.null; - done(); - }) - .catch(done); + }); }); - it("should sort the rows according to the date column", (done) => { - database + it("should sort the rows according to the date column", async () => { + await database .client(table) .insert([ { report_name: "report", date: "2017-01-02" }, @@ -100,18 +93,16 @@ describe("db", () => { const expectedDate = `2017-01-0${3 - index}`; expect(resultDate).to.equal(expectedDate); }); - done(); - }) - .catch(done); + }); }); - it("should limit the rows according to the limit param", (done) => { + it("should limit the rows according to the limit param", async () => { const rows = Array(5) .fill(0) .map(() => { return { report_name: "report", date: "2017-01-01" }; }); - database + await database .client(table) .insert(rows) .then(() => { @@ -123,18 +114,16 @@ describe("db", () => { }) .then((results) => { expect(results).to.have.length(4); - done(); - }) - .catch(done); + }); }); - it("should default to a limit of 1000", (done) => { + it("should default to a limit of 1000", async () => { const rows = Array(1001) .fill(0) .map(() => { return { report_name: "report", date: "2017-01-01" }; }); - database + await database .client(table) .insert(rows) .then(() => { @@ -142,18 +131,16 @@ describe("db", () => { }) .then((results) => { expect(results).to.have.length(1000); - done(); - }) - .catch(done); + }); }); - it("should have a maximum limit of 10,000", (done) => { + it("should have a maximum limit of 10,000", async () => { const rows = Array(11000) .fill(0) .map(() => { return { report_name: "report", date: "2017-01-01" }; }); - database + await database .client(table) .insert(rows) .then(() => { @@ -165,20 +152,16 @@ describe("db", () => { }) .then((results) => { expect(results).to.have.length(10000); - done(); - }) - .catch((err) => { - done(err); }); }); - it("should paginate on the page param", (done) => { + it("should paginate on the page param", async () => { const rows = Array(6) .fill(0) .map((val, index) => { return { report_name: "report", date: `2017-01-0${index + 1}` }; }); - database + await database .client(table) .insert(rows) .then(() => { @@ -205,9 +188,7 @@ describe("db", () => { expect(results).to.have.length(3); expect(results[0].date.toISOString()).to.match(/^2017-01-03/); expect(results[2].date.toISOString()).to.match(/^2017-01-01/); - done(); - }) - .catch(done); + }); }); }); @@ -237,8 +218,8 @@ describe("db", () => { }); describe(".queryDomain(params)", () => { - it("should only return 2 results that include site reports from the test.gov domain", (done) => { - database + it("should only return 2 results that include site reports from the test.gov domain", async () => { + await database .client(table) .insert([ { @@ -268,15 +249,11 @@ describe("db", () => { }) .then((results) => { expect(results).to.have.length(2); - done(); - }) - .catch((err) => { - done(err); }); }); - it("should only return 2 results that include site reports from the test.gov domain, when multiple reports", (done) => { - database + it("should only return 2 results that include site reports from the test.gov domain, when multiple reports", async () => { + await database .client(table) .insert([ { @@ -308,15 +285,11 @@ describe("db", () => { expect(results).to.have.length(2); expect(results[0].report_name).to.equal("site"); expect(results[0].data.domain).to.equal("test.gov"); - done(); - }) - .catch((err) => { - done(err); }); }); - it("should only return 2 results that include site reports from the test.gov domain, when multiple domains", (done) => { - database + it("should only return 2 results that include site reports from the test.gov domain, when multiple domains", async () => { + await database .client(table) .insert([ { @@ -348,14 +321,10 @@ describe("db", () => { expect(results).to.have.length(2); expect(results[0].report_name).to.equal("site"); expect(results[0].data.domain).to.equal("test.gov"); - done(); - }) - .catch((err) => { - done(err); }); }); - it("should only return 4 results that include download reports from the test.gov domain, when multiple domains", (done) => { + it("should only return 4 results that include download reports from the test.gov domain, when multiple domains", async () => { const testData = [ { report_name: "download", @@ -383,7 +352,7 @@ describe("db", () => { data: { page: "usda.gov" }, }, ]; - database + await database .client(table) .insert(testData) .then(() => { @@ -405,15 +374,11 @@ describe("db", () => { testData[index].data.page, ); }); - done(); - }) - .catch((err) => { - done(err); }); }); - it("should only return 2 results that include site reports from the test.gov domain, when before date parameters are in", (done) => { - database + it("should only return 2 results that include site reports from the test.gov domain, when before date parameters are in", async () => { + await database .client(table) .insert([ { @@ -452,15 +417,11 @@ describe("db", () => { expect(results[0].report_name).to.equal("site"); expect(results[0].data.domain).to.equal("test.gov"); expect(results[0].date.toISOString()).to.match(/^2017-01-02/); - done(); - }) - .catch((err) => { - done(err); }); }); - it("should only return 1 result that include site reports from the test.gov domain, when after date parameters are in", (done) => { - database + it("should only return 1 result that include site reports from the test.gov domain, when after date parameters are in", async () => { + await database .client(table) .insert([ { @@ -499,15 +460,11 @@ describe("db", () => { expect(results[0].report_name).to.equal("site"); expect(results[0].data.domain).to.equal("test.gov"); expect(results[0].date.toISOString()).to.match(/^2018-01-03/); - done(); - }) - .catch((err) => { - done(err); }); }); - it("should only return 2 result that include site reports from the test.gov domain, when after/before date parameters set", (done) => { - database + it("should only return 2 result that include site reports from the test.gov domain, when after/before date parameters set", async () => { + await database .client(table) .insert([ { @@ -557,15 +514,11 @@ describe("db", () => { expect(results[0].report_name).to.equal("site"); expect(results[0].data.domain).to.equal("test.gov"); expect(results[0].date.toISOString()).to.match(/^2017-11-04/); - done(); - }) - .catch((err) => { - done(err); }); }); - it("should only return 2 result that include site reports from the test.gov domain, when after/before date parameters set", (done) => { - database + it("should only return 2 result that include site reports from the test.gov domain, when after/before date parameters set", async () => { + await database .client(table) .insert([ { @@ -615,10 +568,6 @@ describe("db", () => { expect(results[0].report_name).to.equal("site"); expect(results[0].data.domain).to.equal("test.gov"); expect(results[0].date.toISOString()).to.match(/^2018-01-03/); - done(); - }) - .catch((err) => { - done(err); }); }); });