Last active
May 29, 2019 05:30
-
-
Save seanpmaxwell/f4cfb6d22d4f81e10b9ff212da8763d7 to your computer and use it in GitHub Desktop.
TypeScriptFullStackShell/src/controllers/demo/DemoController.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as supertest from 'supertest'; | |
import {} from 'jasmine'; | |
import { OK, BAD_REQUEST } from 'http-status-codes'; | |
import { SuperTest, Test } from 'supertest'; | |
import { Logger } from '@overnightjs/logger'; | |
import TestServer from '../shared/TestServer.test'; | |
import DemoController from './DemoController'; | |
describe('DemoController', () => { | |
const demoController = new DemoController(); | |
let agent: SuperTest<Test>; | |
beforeAll(done => { | |
const server = new TestServer(); | |
server.setController(demoController); | |
agent = supertest.agent(server.getExpressInstance()); | |
done(); | |
}); | |
describe('API: "/api/say-hello/:name"', () => { | |
const { SUCCESS_MSG } = DemoController; | |
const name = 'seanmaxwell'; | |
const message = SUCCESS_MSG + name; | |
it(`should return a JSON object with the message "${message}" and a status code | |
of "${OK}" if message was successful`, done => { | |
agent.get('/api/say-hello/' + name) | |
.end((err, res) => { | |
if (err) { | |
Logger.Err(err, true); | |
} | |
expect(res.status).toBe(OK); | |
expect(res.body.message).toBe(message); | |
done(); | |
}); | |
}); | |
it(`should return a JSON object with the "error" param and a status code of "${BAD_REQUEST}" | |
if message was unsuccessful`, done => { | |
agent.get('/api/say-hello/make_it_fail') | |
.end((err, res) => { | |
if (err) { | |
Logger.Err(err, true); | |
} | |
expect(res.status).toBe(BAD_REQUEST); | |
expect(res.body.error).toBeTruthy(); | |
done(); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment