aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app.ts4
-rw-r--r--src/files.ts8
-rw-r--r--src/logger.ts7
-rw-r--r--test/integration/auth.routes.test.ts5
-rw-r--r--test/integration/index.routes.test.ts5
-rw-r--r--test/integration/protocol.routes.test.ts6
-rw-r--r--test/test-db.ts9
7 files changed, 32 insertions, 12 deletions
diff --git a/src/app.ts b/src/app.ts
index 393a89e..bffaffc 100644
--- a/src/app.ts
+++ b/src/app.ts
@@ -41,8 +41,8 @@ class App {
* server.
*/
public constructor(enableLog: boolean) {
+ logger.setEnabled(enableLog);
logger.debug('Constructing router');
- this.logEnabled = enableLog;
this.express = ex();
this.express.use((req, res, next) => {
if (req.headers.authorisation) {
@@ -153,5 +153,5 @@ export default new App(true).express;
*/
// tslint:disable-next-line:variable-name
export const TestApp: () => ex.Express = (): ex.Express => {
- return new App(true).express;
+ return new App(false).express;
};
diff --git a/src/files.ts b/src/files.ts
index b2440a5..286e073 100644
--- a/src/files.ts
+++ b/src/files.ts
@@ -28,10 +28,10 @@ const imgQueueSize = profiler.counter({
agg_type: "sum"
})
-const BASE_BASE: string = `/cs/scratch/${require("os").userInfo().username}/`
-const CONTENT_BASE_DIRECTORY: string = BASE_BASE + 'files';
-const LOG_BASE_DIRECTORY: string = BASE_BASE + 'logs';
-const TEMP_BASE_DIRECTORY: string = BASE_BASE + 'files-temp';
+const BASE_BASE: string = `${__dirname}/../data`
+const CONTENT_BASE_DIRECTORY: string = BASE_BASE + '/files';
+const LOG_BASE_DIRECTORY: string = BASE_BASE + '/logs';
+const TEMP_BASE_DIRECTORY: string = BASE_BASE + '/files-temp';
export interface Metadata {
version: number;
diff --git a/src/logger.ts b/src/logger.ts
index bed8f72..a9fca4d 100644
--- a/src/logger.ts
+++ b/src/logger.ts
@@ -344,7 +344,11 @@ export const setDefaults: (defaults: LoggingMetadata) => Logger = (
emerg: makeLogFunction('emerg', defaults),
emergency: makeLogFunction('emergency', defaults),
shutdown: makeLogFunction('shutdown', defaults),
- isEnabled: (): boolean => !basicFileTransport.silent,
+ isEnabled: (): boolean => !basicLogger.silent,
+ setEnabled: (x: boolean): void => {
+ basicLogger.silent = !x;
+ return;
+ },
forward: forwardLog,
fetch: fetchLogs2,
for: setDefaults
@@ -389,6 +393,7 @@ export interface Logger {
emergency: LogFunction;
shutdown: LogFunction;
isEnabled: () => boolean;
+ setEnabled: (x: boolean) => void;
forward: (level: LogLevel, message: string, meta: LoggingMetadata) => void;
fetch: (level: LogLevel, params?: FetchParams) => Promise<LogItem[]>;
for: (defaults: LoggingMetadata) => Logger;
diff --git a/test/integration/auth.routes.test.ts b/test/integration/auth.routes.test.ts
index c090984..362a262 100644
--- a/test/integration/auth.routes.test.ts
+++ b/test/integration/auth.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, stopDB, resetDB
+} from '../test-db';
import { default as User } from '../../src/db/model/User';
// Chai-http must be imported this way:
@@ -69,6 +70,8 @@ const base: string = '/cs3099group-be-4';
describe('authentication', () => {
before(initDatabase);
+ after(stopDB);
+
context('invalid password authentication', () => {
before(populateDatabase);
it('should reject login to invalid endpoints', () => {
diff --git a/test/integration/index.routes.test.ts b/test/integration/index.routes.test.ts
index 0317d98..acd462a 100644
--- a/test/integration/index.routes.test.ts
+++ b/test/integration/index.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, stopDB, resetDB
+} from '../test-db';
import { default as User } from '../../src/db/model/User';
// Chai-http must be imported this way:
@@ -50,6 +51,8 @@ const getToken = async() => {
describe('routes : index', () => {
before(initDatabase);
+ after(stopDB);
+
describe('GET /', () => {
before(populateDatabase);
it('should return 401 without authentication', () => {
diff --git a/test/integration/protocol.routes.test.ts b/test/integration/protocol.routes.test.ts
index d289de3..6203e4a 100644
--- a/test/integration/protocol.routes.test.ts
+++ b/test/integration/protocol.routes.test.ts
@@ -7,7 +7,7 @@
import * as chai from 'chai';
const expect: Chai.ExpectStatic = chai.expect;
-import { Credentials, Database, addUser, initDB, resetDB,
+import { Credentials, Database, addUser, initDB, stopDB, resetDB,
Projec, addProjec, Filee, addFilee } from '../test-db';
import { default as User } from '../../src/db/model/User';
import * as fs from 'fs';
@@ -226,6 +226,8 @@ const completeProtocol: MochaForEachInput[] = [
describe('routes : protocol', () => {
before(initDatabase);
+ after(stopDB);
+
beforeEach(populateDatabase);
beforeEach(getToken);
@@ -304,6 +306,8 @@ describe('routes : protocol', () => {
describe('test edge cases', () => {
before(initDatabase);
+ after(stopDB);
+
beforeEach(populateDatabase);
beforeEach(getToken);
diff --git a/test/test-db.ts b/test/test-db.ts
index 9a32cb2..4bd6580 100644
--- a/test/test-db.ts
+++ b/test/test-db.ts
@@ -8,21 +8,26 @@ import * as fs from 'fs-extra';
import { FileTypeName } from '../src/files';
import { uuid } from '../src/uuid';
-
import { Sequelize } from 'sequelize-typescript';
import * as sqlite from 'sqlite3';
export type Database = Sequelize;
+let db: sqlite.Database;
+
export const initDB: () => Database = (): Database => {
const dataFile: string = ':memory:';
- const db: sqlite.Database = new sqlite.Database(dataFile);
+ db = new sqlite.Database(dataFile);
const seq: Database = new Sequelize(`sqlite:${dataFile}`);
seq.addModels([`${__dirname}/../src/db/model`]);
seq.options.logging = false;
return seq;
};
+export const stopDB: () => void = () => {
+ db.close((e) => {});
+}
+
export const resetDB: (database: Database) => Promise<void> = async(
database: Database
): Promise<void> => {