From 7316b8522701b8ce83ec1c3da68123d5b369ecd8 Mon Sep 17 00:00:00 2001 From: Roland Bernard <rolbernard@unibz.it> Date: Sun, 23 May 2021 13:37:25 +0200 Subject: [PATCH] Now able to successfully run one test. Teardown is still missing --- server/src/database.ts | 4 ++-- server/src/v1/user.test.ts | 5 +++++ server/src/v1/user.ts | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/src/database.ts b/server/src/database.ts index b83616d..be83ed0 100644 --- a/server/src/database.ts +++ b/server/src/database.ts @@ -4,8 +4,8 @@ import knex from 'knex'; import { environment } from './config'; import config from './knexconfig'; -const database = knex(config[environment]); -database.migrate.latest(); +export const database = knex(config[environment]); +export const migrated = database.migrate.latest(); export default database; diff --git a/server/src/v1/user.test.ts b/server/src/v1/user.test.ts index 2983bbd..c9c5905 100644 --- a/server/src/v1/user.test.ts +++ b/server/src/v1/user.test.ts @@ -1,9 +1,14 @@ import { api } from '../api'; +import { migrated } from '../database'; import supertest from 'supertest'; const request = supertest(api); +beforeAll(async () => { + await migrated; +}); + test('non existant username returns 404 for /v1/user/name/', async () => { const response = await request.get('/v1/user/name/__NO_REAL_NAME__'); expect(response.status).toEqual(404); diff --git a/server/src/v1/user.ts b/server/src/v1/user.ts index 8e596c2..8599d13 100644 --- a/server/src/v1/user.ts +++ b/server/src/v1/user.ts @@ -32,6 +32,7 @@ user.get('/name/:username', async (req, res) => { }); } } catch (e) { + console.log(e); res.status(400).json({ status: 'error', message: 'failed get user', -- GitLab