From cf4641c8fbbe985af405a871491b0b62585b74ec Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Tue, 19 Aug 2025 19:35:55 -0400 Subject: [PATCH] Added more unit tests --- test/routes/benchmark.test.js | 37 ++++++++++++++++++++++++++++++----- test/routes/hardware.test.js | 37 ++++++++++++++++++++++++++++++----- test/routes/test.test.js | 37 ++++++++++++++++++++++++++++++----- test/routes/toplevel.test.js | 8 ++++++-- 4 files changed, 102 insertions(+), 17 deletions(-) diff --git a/test/routes/benchmark.test.js b/test/routes/benchmark.test.js index a0e33e7..79ae5f9 100644 --- a/test/routes/benchmark.test.js +++ b/test/routes/benchmark.test.js @@ -8,11 +8,15 @@ describe('GET /benchmark', () => { this.res = res; }); - it('should return a redirect', async () => { + it('Benchmark base route should return a redirect', async () => { expect(this.res.status).to.equal(302); }); - it('should redirect to /benchmark/list', async () => { + it('Benchmark base route should return an HTML response', async () => { + expect(this.res.headers['content-type']).contains('text/plain'); + }); + + it('Benchmark base route should redirect to /benchmark/list', async () => { expect(this.res.headers['location']).contains('/benchmark/list'); }); }); @@ -23,11 +27,34 @@ describe('GET /benchmark/list', () => { this.res = res; }); - it('should return a 200 status', async () => { + it('Benchmark list route should return a 200 status', async () => { expect(this.res.status).to.equal(200); }); - it('should return an HTML response', async () => { - expect(this.res.headers['content-type']).match(/text\/html/); + it('Benchmark list route should return an HTML response', async () => { + expect(this.res.headers['content-type']).contains('text/html'); + }); + + it('Benchmark list route should contain "List of Benchmarks" in body', async() => { + expect(this.res.text).contains('List of Benchmarks'); + }); +}); + +describe('GET /benchmark/add', () => { + beforeEach(async () => { + const res = await request(app).get('/benchmark/add'); + this.res = res; + }); + + it('Benchmark add route should return a 200 status', async () => { + expect(this.res.status).to.equal(200); + }); + + it('Benchmark add route should return an HTML response', async () => { + expect(this.res.headers['content-type']).contains('text/html'); + }); + + it('Benchmark add route should contain "Add a Benchmark" in body', async() => { + expect(this.res.text).contains('Add a Benchmark'); }); }); diff --git a/test/routes/hardware.test.js b/test/routes/hardware.test.js index 13d0fa7..35e0f02 100644 --- a/test/routes/hardware.test.js +++ b/test/routes/hardware.test.js @@ -8,11 +8,15 @@ describe('GET /hardware', () => { this.res = res; }); - it('should return a redirect', async () => { + it('Hardware base route should return a redirect', async () => { expect(this.res.status).to.equal(302); }); - it('should redirect to /hardware/list', async () => { + it('Hardware base route should return an HTML response', async () => { + expect(this.res.headers['content-type']).contains('text/plain'); + }); + + it('Hardware base route should redirect to /hardware/list', async () => { expect(this.res.headers['location']).contains('/hardware/list'); }); }); @@ -23,11 +27,34 @@ describe('GET /hardware/list', () => { this.res = res; }); - it('should return a 200 status', async () => { + it('Hardware list route should return a 200 status', async () => { expect(this.res.status).to.equal(200); }); - it('should return an HTML response', async () => { - expect(this.res.headers['content-type']).match(/text\/html/); + it('Hardware list route should return an HTML response', async () => { + expect(this.res.headers['content-type']).contains('text/html'); + }); + + it('Hardware list route should contain "List of Hardware" in body', async() => { + expect(this.res.text).contains('List of Hardware'); + }); +}); + +describe('GET /hardware/add', () => { + beforeEach(async () => { + const res = await request(app).get('/hardware/add'); + this.res = res; + }); + + it('Hardware add route should return a 200 status', async () => { + expect(this.res.status).to.equal(200); + }); + + it('Hardware add route should return an HTML response', async () => { + expect(this.res.headers['content-type']).contains('text/html'); + }); + + it('Hardware add route should contain "Add Hardware" in body', async() => { + expect(this.res.text).contains('Add Hardware'); }); }); diff --git a/test/routes/test.test.js b/test/routes/test.test.js index 6f9fc85..061c1bb 100644 --- a/test/routes/test.test.js +++ b/test/routes/test.test.js @@ -8,11 +8,15 @@ describe('GET /test', () => { this.res = res; }); - it('should return a redirect', async () => { + it('Test base route should return a redirect', async () => { expect(this.res.status).to.equal(302); }); - it('should redirect to /test/list', async () => { + it('Test base route should return an HTML response', async () => { + expect(this.res.headers['content-type']).contains('text/plain'); + }); + + it('Test base route should redirect to /test/list', async () => { expect(this.res.headers['location']).contains('/test/list'); }); }); @@ -23,11 +27,34 @@ describe('GET /test/list', () => { this.res = res; }); - it('should return a 200 status', async () => { + it('Test list route should return a 200 status', async () => { expect(this.res.status).to.equal(200); }); - it('should return an HTML response', async () => { - expect(this.res.headers['content-type']).match(/text\/html/); + it('Test list route should return an HTML response', async () => { + expect(this.res.headers['content-type']).contains('text/html'); + }); + + it('Test list route should contain "List of Tests" in body', async() => { + expect(this.res.text).contains('List of Tests'); + }); +}); + +describe('GET /test/add', () => { + beforeEach(async () => { + const res = await request(app).get('/test/add'); + this.res = res; + }); + + it('Test add route should return a 200 status', async () => { + expect(this.res.status).to.equal(200); + }); + + it('Test add route should return an HTML response', async () => { + expect(this.res.headers['content-type']).contains('text/html'); + }); + + it('Test add route should contain "Add a Test" in body', async() => { + expect(this.res.text).contains('Add a Test'); }); }); diff --git a/test/routes/toplevel.test.js b/test/routes/toplevel.test.js index 3d07f0d..3a65615 100644 --- a/test/routes/toplevel.test.js +++ b/test/routes/toplevel.test.js @@ -8,11 +8,15 @@ describe('GET /', () => { this.res = res; }); - it('should return a 200 status', async () => { + it('Dashboard should return a 200 status', async () => { expect(this.res.status).to.equal(200); }); - it('should return an HTML response', async () => { + it('Dashboard should return an HTML response', async () => { expect(this.res.headers['content-type']).match(/text\/html/); }); + + it('Dashboard should contain "Leviathan" in body', async() => { + expect(this.res.text).contains('Leviathan'); + }); });