Implemented very basic (and poorly written) unit tests that test using the live database

This commit is contained in:
Gregory Campbell
2021-11-25 10:48:28 -05:00
parent 98308642aa
commit 4af4f90a72
4 changed files with 7767 additions and 4 deletions
+74
View File
@@ -0,0 +1,74 @@
const request = require('supertest');
const server = require('../server');
describe('GET /msg', function () {
it('respond with json containing a list of all users', function (done) {
request(server)
.get('/msg')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, done);
});
});;
describe('GET /msg/:id', function () {
it('respond with json containing a single message', function (done) {
request(server)
.get('/msg/1')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, done);
});
});
/**
* Testing get a message endpoint by giving a non-existing message
*/
describe('GET /msg/:id', function () {
it('respond with json message not found', function (done) {
request(server)
.get('/users/idisnonexisting')
//.set('Accept', 'application/json')
.expect(404) //expecting HTTP status code
//.expect('"Message not found"') // expecting content value
.end((err) => {
if (err) return done(err);
done();
});
});
});
/**
* Testing post message endpoint
*/
describe('POST /msg', function () {
it('respond with 201 created', function (done) {
request(server)
.post('/msg/1/test')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
.end((err) => {
if (err) return done(err);
done();
});
});
});
/**
* Testing post message endpoint
*/
describe('POST /msg', function () {
it('respond with 400 not created', function (done) {
request(server)
.post('/msg/test')
.set('Accept', 'application/json')
//.expect('Content-Type', /json/)
.expect(404)
//.expect('"Message not created"')
.end((err) => {
if (err) return done(err);
done();
});
});
});