From ff1034dc6f427238b19f895b052e33fc181f0829 Mon Sep 17 00:00:00 2001 From: jw255 Date: Tue, 10 Apr 2018 21:37:42 +0100 Subject: progress on testing --- test/integration/protocol.routes.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/integration/protocol.routes.test.ts b/test/integration/protocol.routes.test.ts index 18ee1e3..9467f13 100644 --- a/test/integration/protocol.routes.test.ts +++ b/test/integration/protocol.routes.test.ts @@ -111,7 +111,7 @@ describe('routes : protocol', () => { required: array(types.string) }), 200], ['get', '/log', types.array({ - component: types.string, + //component: types.string, level: alternative([ 'info', 'security', -- cgit v1.2.1 From f7220be4e1b80cdba0fbaf41f7382cbf18561e2b Mon Sep 17 00:00:00 2001 From: jw255 Date: Tue, 10 Apr 2018 23:30:51 +0100 Subject: sth works maybe --- test/integration/protocol.routes.test.ts | 36 +++++++++++++++++++------------- test/test-db.ts | 23 ++++++++++++++++++++ 2 files changed, 45 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/integration/protocol.routes.test.ts b/test/integration/protocol.routes.test.ts index 9467f13..e23fd60 100644 --- a/test/integration/protocol.routes.test.ts +++ b/test/integration/protocol.routes.test.ts @@ -7,7 +7,8 @@ import * as chai from 'chai'; const expect: Chai.ExpectStatic = chai.expect; -import { Credentials, Database, addUser, initDB, resetDB } from '../test-db'; +import { Credentials, Database, addUser, initDB, resetDB, + Projec, addProjec } from '../test-db'; import { default as User } from '../../src/db/model/User'; // Chai-http must be imported this way: @@ -28,6 +29,7 @@ const app = App.TestApp(); let database: Database; let mockUser: Credentials; let token: string; +let mockProj: Projec; const initDatabase = async() => { database = initDB(); @@ -37,6 +39,7 @@ const initDatabase = async() => { const populateDatabase = async() => { await resetDB(database); mockUser = await addUser(database, true); + mockProj = await addProjec(database, mockUser); }; const getToken = async() => { @@ -111,7 +114,7 @@ describe('routes : protocol', () => { required: array(types.string) }), 200], ['get', '/log', types.array({ - //component: types.string, + component: types.string, level: alternative([ 'info', 'security', @@ -122,8 +125,12 @@ describe('routes : protocol', () => { value: types.anything, username: types.string, timestamp: types.string - }), 500], - ['post', '/log', null, 500], + }), 200], + ['post', '/log', [{ + component: 'tesssst', + level: 'info', + value: 'sdasdasdasdasdasd' + }], 200], ['get', '/properties', types.array({ id: types.string, display: optional(match({ @@ -163,7 +170,7 @@ describe('routes : protocol', () => { private_admin_metadata: types.anything }), 401], // TODO types.metadata - ['get', '/users/:username', { + ['get', '/users/mock_user', { username: types.string, privileges: array(types.string), projects: array({ @@ -175,8 +182,8 @@ describe('routes : protocol', () => { public_admin_metadata: types.anything, private_admin_metadata: types.anything }, 401], - ['post', '/users/:username', null, 401], - ['get', '/users/:username/properties', { + ['post', '/users/mock_user', null, 401], + ['get', '/users/mock_user/properties', { data: optional(types.anything) }, 401], ['get', '/current_user', { @@ -207,7 +214,7 @@ describe('routes : protocol', () => { private_metadata: optional(types.anything), admin_metadata: optional(types.anything) }), 200], - ['get', '/projects/:project_name', { + ['get', '/projects/mocky', { project_name: types.string, users: array({ username: types.string, @@ -217,13 +224,13 @@ describe('routes : protocol', () => { private_metadata: types.anything, admin_metadata: optional(types.anything) }, 200], - ['post', '/projects/:project_name', null, 200], - ['get', '/projects/:project_name/properties', { + ['post', '/projects/mocky', null, 200], + ['get', '/projects/mocky/properties', { data: optional(types.anything) }, 200], - ['get', '/projects/:project_name/files/:path', null, 200], - ['post', '/projects/:project_name/files/:id', null, 200], - ['get', '/projects/:project_name/files_by_id/:id', null, 200] + ['get', '/projects/mocky/files/:path', null, 200], + ['post', '/projects/mocky/files/:id', null, 200], + ['get', '/projects/mocky/files_by_id/:id', null, 200] ]; /* tslint:enable:align */ @@ -238,7 +245,8 @@ describe('routes : protocol', () => { (method: string, path: string, temp: Template, resCode: number) => { const request: ChaiHttp.Request = method === 'get' ? chai.request(app).get(base + path) - : chai.request(app).post(base + path); + : chai.request(app).post(base + path) + .set('content-type', 'application/json').send(temp); request.set('Authorization', `Bearer ${token}`); return request.then((res: ChaiHttp.Response) => { expect(res.type).to.equal('application/json'); diff --git a/test/test-db.ts b/test/test-db.ts index f20608a..fa62ad7 100644 --- a/test/test-db.ts +++ b/test/test-db.ts @@ -1,3 +1,4 @@ +import { default as Project } from '../src/db/model/Project'; import { default as User } from '../src/db/model/User'; import { default as UserGroup } from '../src/db/model/UserGroup'; @@ -29,6 +30,13 @@ export interface Credentials { usergroups: UserGroup[]; } +export interface Projec { + name: string; + contributors: Credentials[]; + creationDate: Date; + lastActivity: Date; +} + export const addUser: (database?: Database, admin?: boolean) => Promise = async( database?: Database, admin?: boolean @@ -55,3 +63,18 @@ export const addUser: (database?: Database, admin?: boolean) => await new User(mockUser).save(); return mockUser; }; + +export const addProjec: (database: Database, user: Credentials) => + Promise = async( + database: Database, user: Credentials +): Promise => { + const mockProject: Projec = { + name: 'mocky', + contributors: [user], + creationDate: new Date(), + lastActivity: new Date() + }; + + await new Project(mockProject).save(); + return mockProject; +}; -- cgit v1.2.1