aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHafeez2018-04-13 15:53:10 +0100
committerHafeez2018-04-13 15:53:10 +0100
commit8f013438e4e4c96594b7ed567e7a58dfc1b7ce5a (patch)
treeb370f997c98338925f071a0c802649f08b5ff84c
parentdatebase retrieves all properties (diff)
downloadmedicine-8f013438e4e4c96594b7ed567e7a58dfc1b7ce5a.tar.gz
medicine-8f013438e4e4c96594b7ed567e7a58dfc1b7ce5a.zip

fixed mock file tests

-rw-r--r--src/FileRouter.ts10
-rw-r--r--test/integration/protocol.routes.test.ts10
-rw-r--r--test/test-db.ts26
3 files changed, 36 insertions, 10 deletions
diff --git a/src/FileRouter.ts b/src/FileRouter.ts
index 619be9e..b76dea7 100644
--- a/src/FileRouter.ts
+++ b/src/FileRouter.ts
@@ -415,13 +415,10 @@ const getProjects: Middleware =
const getProjectName: Middleware =
async(req: Request, res: Response, next: NextFunction): Promise<void> => {
const project: Project | null = res.locals.project;
- if (project == null) {
- console.log("was null")
+ if (project == null) {
return next(new RequestError(404, 'project_not_found'));
- } else {
- console.log(project.contributors);
- res.locals.data = project.fullInfo;
- console.log("wasnt " + res.locals.data)
+ } else {
+ res.locals.data = project.fullInfo;
next();
}
};
@@ -639,6 +636,7 @@ export class FileRouter {
fileId: string
): Promise<void> => {
const file: File | null = await File.findOne({
+ include: [{all: true}],
where: {
uuid: fileId
}
diff --git a/test/integration/protocol.routes.test.ts b/test/integration/protocol.routes.test.ts
index 6a08278..7554f0e 100644
--- a/test/integration/protocol.routes.test.ts
+++ b/test/integration/protocol.routes.test.ts
@@ -8,7 +8,7 @@
import * as chai from 'chai';
const expect: Chai.ExpectStatic = chai.expect;
import { Credentials, Database, addUser, initDB, resetDB,
- Projec, addProjec } from '../test-db';
+ Projec, addProjec, Filee, addFilee } from '../test-db';
import { default as User } from '../../src/db/model/User';
// Chai-http must be imported this way:
@@ -30,6 +30,7 @@ let database: Database;
let mockUser: Credentials;
let token: string;
let mockProj: Projec;
+let mockFile: Filee;
const initDatabase = async() => {
database = initDB();
@@ -40,6 +41,7 @@ const populateDatabase = async() => {
await resetDB(database);
mockUser = await addUser(database, true);
mockProj = await addProjec(database, mockUser);
+ mockFile = await addFilee(database, mockUser);
};
const getToken = async() => {
@@ -228,9 +230,9 @@ describe('routes : protocol', () => {
['get', '/projects/mocky/properties', {
data: optional(types.anything)
}, 200],
- ['get', '/projects/mocky/files/:path', null, 200],
- ['post', '/projects/mocky/files/:id', null, 200],
- ['get', '/projects/mocky/files_by_id/:id', null, 200]
+ ['get', '/projects/mocky/files/example/path', null, 200],
+ ['post', '/projects/mocky/files/mockyfile2', null, 200],
+ ['get', '/projects/mocky/files_by_id/file1', null, 200]
];
/* tslint:enable:align */
diff --git a/test/test-db.ts b/test/test-db.ts
index fa62ad7..32f2f0b 100644
--- a/test/test-db.ts
+++ b/test/test-db.ts
@@ -1,6 +1,8 @@
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';
+import { default as File } from '../src/db/model/File';
+import { FileTypeName } from '../src/files';
import { Sequelize } from 'sequelize-typescript';
import * as sqlite from 'sqlite3';
@@ -37,6 +39,14 @@ export interface Projec {
lastActivity: Date;
}
+export interface Filee {
+ name: string,
+ path: string,
+ uuid: string,
+ creator: Credentials,
+ type: FileTypeName
+}
+
export const addUser: (database?: Database, admin?: boolean) =>
Promise<Credentials> = async(
database?: Database, admin?: boolean
@@ -78,3 +88,19 @@ export const addProjec: (database: Database, user: Credentials) =>
await new Project(mockProject).save();
return mockProject;
};
+
+export const addFilee: (database: Database, user: Credentials) =>
+ Promise<Filee> = async(
+ database: Database, user: Credentials
+): Promise<Filee> => {
+ const mockFile: Filee = {
+ name: 'mockyFile',
+ path: 'example/path',
+ uuid: 'file1',
+ creator: user,
+ type: "generic"
+ };
+
+ await new File(mockFile).save();
+ return mockFile;
+}; \ No newline at end of file