From 3639ce2c0c7fa74ec8be6fdec3db92adc62cac4a Mon Sep 17 00:00:00 2001 From: Roland Bernard <rolbernard@unibz.it> Date: Tue, 25 May 2021 23:18:27 +0200 Subject: [PATCH] Added tests for the work endpoint --- server/src/v1/work.test.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 server/src/v1/work.test.ts diff --git a/server/src/v1/work.test.ts b/server/src/v1/work.test.ts new file mode 100644 index 0000000..4021bcf --- /dev/null +++ b/server/src/v1/work.test.ts @@ -0,0 +1,33 @@ + +import supertest from 'supertest'; + +import { api } from '../api'; +import { generateAuthToken } from './auth'; + +const request = supertest(api); + +describe('GET /work', () => { + test('returns information for the unfinished work', async () => { + const resp = await request + .get('/v1/work') + .set('Authorization', `Bearer ${await generateAuthToken('00000000-0000-4000-8000-000000000000')}`); + expect(resp.status).toEqual(200); + expect(resp.body.status).toEqual('success'); + expect(resp.body.work).toEqual({ + id: '00000000-0000-4000-8000-000000000002', + task: '00000000-0000-4000-8000-000000000005', + user: '00000000-0000-4000-8000-000000000000', + started: Date.parse('2020-10-11T12:00:00'), + finished: null, + }); + }); + + test('returns 404 if no work is unfinished', async () => { + const resp = await request + .get('/v1/work') + .set('Authorization', `Bearer ${await generateAuthToken('00000000-0000-4000-8000-000000000001')}`); + expect(resp.status).toEqual(404); + expect(resp.body.status).toEqual('error'); + }); +}); + -- GitLab