diff --git a/server/package.json b/server/package.json index 794d644..69730cf 100644 --- a/server/package.json +++ b/server/package.json @@ -10,7 +10,7 @@ "prebuild": "yarn lint", "build": "tsc", "test": "jest", - "test-watch": "jest --watch" + "test-watch": "jest --watchAll" }, "dependencies": { "cookie-parser": "1.4.5", diff --git a/server/src/app.ts b/server/src/app.ts index 1641e2f..1a26996 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -14,7 +14,7 @@ import { registerApis } from './routes/api/register' const PORT = normalizePort(process.env.PORT || '6595') const debug = initDebug('deemix-gui:server') -const app: Application = express() +export const app: Application = express() const server = http.createServer(app) /* === Middlewares === */ @@ -31,7 +31,9 @@ registerApis(app) app.set('port', PORT) /* === Server port === */ -server.listen(PORT) +if (process.env.NODE_ENV !== 'test') { + server.listen(PORT) +} /* === Server callbacks === */ server.on('error', getErrorCb(PORT)) diff --git a/server/src/routes/index.spec.ts b/server/src/routes/index.spec.ts new file mode 100644 index 0000000..0e200dc --- /dev/null +++ b/server/src/routes/index.spec.ts @@ -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) + }) +})