2021-11-25 15:25:29 -05:00
|
|
|
require("../mongoConfig")
|
|
|
|
|
|
|
|
|
|
const routes = require('../routes/msg')
|
|
|
|
|
|
2021-11-25 10:48:28 -05:00
|
|
|
const request = require('supertest');
|
2021-11-25 15:25:29 -05:00
|
|
|
const express = require('express');
|
|
|
|
|
const app = express();
|
|
|
|
|
|
|
|
|
|
app.use(express.urlencoded({ extended: false }))
|
|
|
|
|
app.use("/", routes)
|
2021-11-25 10:48:28 -05:00
|
|
|
|
2021-11-25 16:07:40 -05:00
|
|
|
/**
|
|
|
|
|
* Testing post message logic
|
|
|
|
|
*/
|
|
|
|
|
describe('POST /msg/:id', function () {
|
|
|
|
|
const data = {
|
|
|
|
|
message: "test",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it('respond with 201 created', function (done) {
|
|
|
|
|
request(app)
|
|
|
|
|
.post('/msg/1')
|
|
|
|
|
.type('form')
|
|
|
|
|
.send(data)
|
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
|
.expect(201, done);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('respond with 400 not updated', function (done) {
|
|
|
|
|
request(app)
|
|
|
|
|
.post('/msg/1')
|
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
|
.expect(400)
|
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
|
.end((err) => {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('respond with 400 not updated', function (done) {
|
|
|
|
|
request(app)
|
|
|
|
|
.post('/msg/idisnonexisting')
|
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
|
.expect(404)
|
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
|
.end((err) => {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Testing get message logic
|
|
|
|
|
*/
|
2021-11-25 10:48:28 -05:00
|
|
|
describe('GET /msg', function () {
|
|
|
|
|
it('respond with json containing a list of all users', function (done) {
|
2021-11-25 15:25:29 -05:00
|
|
|
request(app)
|
2021-11-25 10:48:28 -05:00
|
|
|
.get('/msg')
|
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
|
.expect(200, done);
|
|
|
|
|
});
|
2021-11-25 16:07:40 -05:00
|
|
|
});
|
2021-11-25 10:48:28 -05:00
|
|
|
|
|
|
|
|
describe('GET /msg/:id', function () {
|
|
|
|
|
it('respond with json containing a single message', function (done) {
|
2021-11-25 15:25:29 -05:00
|
|
|
request(app)
|
2021-11-25 10:48:28 -05:00
|
|
|
.get('/msg/1')
|
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
|
.expect(200, done);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('respond with json message not found', function (done) {
|
2021-11-25 15:25:29 -05:00
|
|
|
request(app)
|
2021-11-25 16:07:40 -05:00
|
|
|
.get('/msg/2')
|
2021-11-25 15:25:29 -05:00
|
|
|
.set('Accept', 'application/json')
|
|
|
|
|
.expect(400) //expecting HTTP status code
|
|
|
|
|
.expect('Content-Type', /json/) // expecting content value
|
2021-11-25 10:48:28 -05:00
|
|
|
.end((err) => {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2021-11-25 16:07:40 -05:00
|
|
|
|
|
|
|
|
it('respond with json message not found', function (done) {
|
|
|
|
|
request(app)
|
|
|
|
|
.get('/msg/idisnonexisting')
|
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
|
.expect(404) //expecting HTTP status code
|
|
|
|
|
.expect('Content-Type', /json/) // expecting content value
|
|
|
|
|
.end((err) => {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2021-11-25 10:48:28 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-25 16:07:40 -05:00
|
|
|
* Testing put message logic
|
2021-11-25 10:48:28 -05:00
|
|
|
*/
|
2021-11-25 16:07:40 -05:00
|
|
|
describe('PUT /msg/:id', function () {
|
|
|
|
|
it('respond with json containing a single message', function (done) {
|
|
|
|
|
request(app)
|
|
|
|
|
.put('/msg/1')
|
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
|
.expect(201, done);
|
|
|
|
|
});
|
2021-11-25 15:25:29 -05:00
|
|
|
|
2021-11-25 16:07:40 -05:00
|
|
|
it('respond with json message not found', function (done) {
|
2021-11-25 15:25:29 -05:00
|
|
|
request(app)
|
2021-11-25 16:07:40 -05:00
|
|
|
.put('/msg/2')
|
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
|
.expect(400) //expecting HTTP status code
|
|
|
|
|
.expect('Content-Type', /json/) // expecting content value
|
|
|
|
|
.end((err) => {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2021-11-25 10:48:28 -05:00
|
|
|
});
|
|
|
|
|
|
2021-11-25 16:07:40 -05:00
|
|
|
it('respond with json message not found', function (done) {
|
2021-11-25 15:25:29 -05:00
|
|
|
request(app)
|
2021-11-25 16:07:40 -05:00
|
|
|
.put('/msg/idisnonexisting')
|
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
|
.expect(404) //expecting HTTP status code
|
|
|
|
|
.expect('Content-Type', /json/) // expecting content value
|
|
|
|
|
.end((err) => {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Testing delete message logic
|
|
|
|
|
*/
|
|
|
|
|
describe('DELETE /msg/:id', function () {
|
|
|
|
|
it('respond with json containing a single message', function (done) {
|
|
|
|
|
request(app)
|
|
|
|
|
.delete('/msg/1')
|
2021-11-25 10:48:28 -05:00
|
|
|
.set('Accept', 'application/json')
|
2021-11-25 15:25:29 -05:00
|
|
|
.expect('Content-Type', /json/)
|
2021-11-25 16:07:40 -05:00
|
|
|
.expect(200, done);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('respond with json message not found', function (done) {
|
|
|
|
|
request(app)
|
|
|
|
|
.delete('/msg/1')
|
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
|
.expect(400) //expecting HTTP status code
|
|
|
|
|
.expect('Content-Type', /json/) // expecting content value
|
2021-11-25 10:48:28 -05:00
|
|
|
.end((err) => {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2021-11-25 16:07:40 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('DELETE /msg', function () {
|
|
|
|
|
it('respond with json containing a list of all users', function (done) {
|
|
|
|
|
request(app)
|
|
|
|
|
.delete('/msg')
|
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
|
.expect(200, done);
|
|
|
|
|
});
|
2021-11-25 10:48:28 -05:00
|
|
|
});
|