feat: added root path first test

This commit is contained in:
Roberto Tonino 2021-04-09 19:07:44 +02:00
parent eb91ff06d6
commit 78d70b7369
3 changed files with 33 additions and 3 deletions

View file

@ -10,7 +10,7 @@
"prebuild": "yarn lint", "prebuild": "yarn lint",
"build": "tsc", "build": "tsc",
"test": "jest", "test": "jest",
"test-watch": "jest --watch" "test-watch": "jest --watchAll"
}, },
"dependencies": { "dependencies": {
"cookie-parser": "1.4.5", "cookie-parser": "1.4.5",

View file

@ -14,7 +14,7 @@ import { registerApis } from './routes/api/register'
const PORT = normalizePort(process.env.PORT || '6595') const PORT = normalizePort(process.env.PORT || '6595')
const debug = initDebug('deemix-gui:server') const debug = initDebug('deemix-gui:server')
const app: Application = express() export const app: Application = express()
const server = http.createServer(app) const server = http.createServer(app)
/* === Middlewares === */ /* === Middlewares === */
@ -31,7 +31,9 @@ registerApis(app)
app.set('port', PORT) app.set('port', PORT)
/* === Server port === */ /* === Server port === */
server.listen(PORT) if (process.env.NODE_ENV !== 'test') {
server.listen(PORT)
}
/* === Server callbacks === */ /* === Server callbacks === */
server.on('error', getErrorCb(PORT)) server.on('error', getErrorCb(PORT))

View file

@ -0,0 +1,28 @@
import request from 'supertest'
import { app } from '../app'
describe('root path requests', () => {
it('it responds 200 to the GET method', async () => {
const result = await request(app).get('/').send()
expect(result.status).toBe(200)
})
it('it responds 404 to the POST method', async () => {
const result = await request(app).post('/').send()
expect(result.status).toBe(404)
})
it('it responds 404 to the PATCH method', async () => {
const result = await request(app).patch('/').send()
expect(result.status).toBe(404)
})
it('it responds 404 to the DELETE method', async () => {
const result = await request(app).delete('/').send()
expect(result.status).toBe(404)
})
})