aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Harley2018-03-27 03:50:17 +0100
committerTom Harley2018-03-27 03:50:17 +0100
commitea1ee67bdd02b2ea727c09cfef1784a61aa934f4 (patch)
tree6bf1e8a086bd5250416307501147ee4fe942b87b
parentsmall fix (diff)
downloadmedicine-ea1ee67bdd02b2ea727c09cfef1784a61aa934f4.tar.gz
medicine-ea1ee67bdd02b2ea727c09cfef1784a61aa934f4.zip

Centralise test configuration and introduce SQLite

Tests now take their configuration from a new file test-db.ts. Additionally, this configuration sets up and uses an in-memory SQLite3 database for testing, to avoid writing to disk and to prevent edits to a current database.

-rw-r--r--package.json2
-rw-r--r--src/FileRouter.ts1
-rw-r--r--src/app.ts9
-rw-r--r--src/auth.ts16
-rw-r--r--test/integration/auth.routes.test.ts169
-rw-r--r--test/integration/index.routes.test.ts79
-rw-r--r--test/integration/protocol.routes.test.ts167
-rw-r--r--test/test-db.ts41
-rw-r--r--yarn.lock108
9 files changed, 371 insertions, 221 deletions
diff --git a/package.json b/package.json
index fadb260..9f08c51 100644
--- a/package.json
+++ b/package.json
@@ -54,6 +54,7 @@
"@types/passport": "^0.4.2",
"@types/passport-local": "^1.0.32",
"@types/sequelize": "^4.27.5",
+ "@types/sqlite3": "^3.1.1",
"@types/supertest": "^2.0.4",
"@types/uuid": "^3.4.3",
"@types/winston": "^2.3.8",
@@ -72,6 +73,7 @@
"reflect-metadata": "^0.1.12",
"sequelize": "^4.32.7",
"sequelize-typescript": "^0.6.2",
+ "sqlite3": "^4.0.0",
"supertest": "^3.0.0",
"ts-node": "^3.3.0",
"typescript": "^2.7.1",
diff --git a/src/FileRouter.ts b/src/FileRouter.ts
index 1cef85d..4dc3105 100644
--- a/src/FileRouter.ts
+++ b/src/FileRouter.ts
@@ -447,7 +447,6 @@ const postProjectName: Middleware =
});
promise = file.save();
project = new Project({
- uuid: uuid.generate(),
name: req.params.project_name,
rootFolder: file
});
diff --git a/src/app.ts b/src/app.ts
index bedffa4..897896a 100644
--- a/src/app.ts
+++ b/src/app.ts
@@ -94,8 +94,7 @@ class App {
}
});
if (user === null) {
- next(new RequestError(404, 'user_not_found'));
- return;
+ return next(new RequestError(404, 'user_not_found'));
} else {
res.locals.user = user;
}
@@ -142,8 +141,7 @@ class App {
}
});
if (fileOrNull === null) {
- next();
- return;
+ return next();
} else {
file = fileOrNull;
}
@@ -159,8 +157,7 @@ class App {
}
});
if (parentFolder === null) {
- next();
- return;
+ return next();
}
res.locals.parentFolder = parentFolder;
const tFile: File | undefined = parentFolder.containedFiles.find(
diff --git a/src/auth.ts b/src/auth.ts
index 6339260..b055d9f 100644
--- a/src/auth.ts
+++ b/src/auth.ts
@@ -26,7 +26,7 @@ export class AuthRouter {
username: req.body.username
},
include: [ UserGroup, Project]
- });
+ });
if (user === null) {
// Whoa, what an error!
@@ -68,18 +68,18 @@ export class AuthRouter {
// Checks for errors within request before authentication
public checkErr(req: Request, res: Response, next: NextFunction): void {
if (!req.body.grant_type || !req.body.username || !req.body.password) {
- next(new RequestError(400, 'invalid_request', 'Missing parameters'));
+ return next(new RequestError(400, 'invalid_request', 'Missing parameters'));
}
if (req.body.grant_type !== 'refresh_token'
&& req.body.grant_type !== 'password') {
- next(new RequestError(400, 'unsupported_grant_type', 'invalid grant type'));
+ return next(new RequestError(400, 'unsupported_grant_type', `invalid grant type`));
}
next();
}
-
+
// Configure local strategy to use with passport-js.
private configStrategy(): void {
// tslint:disable-next-line:typedef
@@ -93,7 +93,7 @@ export class AuthRouter {
if (!user || user.password !== password) {
return done(null, false);
- }
+ }
return done(null, user);
}));
}
@@ -122,10 +122,10 @@ export const unauthorisedErr: Errorware =
};
// Middleware to check privileges - admin
-export const isAdmin: any =
-(req: Request, res: Response, next: NextFunction): void => {
+export const isAdmin: any =
+(req: Request, res: Response, next: NextFunction): void => {
var isAdmin: boolean = req.user.object.userGroups.some((x: UserGroup): boolean => x.name === 'admin');
-
+
if (!isAdmin) {
next(new RequestError(
401, 'not_authorised',
diff --git a/test/integration/auth.routes.test.ts b/test/integration/auth.routes.test.ts
index c8a509d..e3f8113 100644
--- a/test/integration/auth.routes.test.ts
+++ b/test/integration/auth.routes.test.ts
@@ -2,10 +2,12 @@
/* Chai assertions look silly when formatted multiline. */
/* tslint:disable:no-unused-expression */
/* Chai assertions do not require assignation. */
+/* tslint:disable:typedef */
+/* Mocha tests do not require strong typing. */
import * as chai from 'chai';
const expect: Chai.ExpectStatic = chai.expect;
-import { default as seq } from '../../src/db/orm';
+import { Credentials, Database, addUser, initDB, resetDB } from '../test-db';
import { default as User } from '../../src/db/model/User';
// Chai-http must be imported this way:
@@ -19,143 +21,158 @@ import 'mocha';
import * as App from '../../src/app';
const app = App.TestApp();
-const badRequestErr =
- { status: 'error',
- error: 'invalid_request',
- error_description: 'Missing parameters' };
-const unsupportedGrantTypeErr =
- { status: 'error',
- error: 'unsupported_grant_type',
- error_description: 'invalid grant type' }
-const authorisationErr =
- { status: 'error',
- error: 'not_authorised',
- error_description: 'user does not have correct authorisation for task' }
-
+let database: Database;
+let mockUser: Credentials;
+let token: string;
-const bobbyCredentials = {
- username: 'bobby',
- password: 'tables',
- grant_type: 'password'
+const initDatabase = async() => {
+ database = initDB();
+ await database.authenticate();
};
-let bobbyToken: string;
+const populateDatabase = async() => {
+ await resetDB(database);
+ mockUser = await addUser(database);
+};
-async function resetDatabase(done: any){
- await seq.sync({
- force: true
+const getToken = async() => {
+ return chai.request(app)
+ .post('/cs3099group-be-4/login')
+ .send({
+ username: mockUser.username,
+ password: mockUser.password,
+ grant_type: 'password'
+ })
+ .then((res) => {
+ token = res.body.access_token;
});
- const u: string = bobbyCredentials.username
- const p: string = bobbyCredentials.password
+};
- const newUser: User = new User({
- username: u,
- password: p,
- userGroups: []
- });
- await newUser.save();
- done();
-}
+const badRequestErr = {
+ status: 'error',
+ error: 'invalid_request',
+ error_description: 'Missing parameters'
+};
-async function setupDatabase(done: any) {
- await seq.authenticate();
- await seq.sync({
- force: true
- });
- done();
-}
+const unsupportedGrantTypeErr = {
+ status: 'error',
+ error: 'unsupported_grant_type',
+ error_description: 'invalid grant type'
+};
-// Add user
-before((done: any) => {
- setupDatabase(done);
-});
+const authorisationErr = {
+ status: 'error',
+ error: 'not_authorised',
+ error_description: 'user does not have correct authorisation for task'
+};
describe('authentication', () => {
+ before(initDatabase);
context('invalid password authentication', () => {
+ before(populateDatabase);
it('should reject login to invalid endpoints', () => {
- chai.request(app)
+ return chai.request(app)
.post('/')
- .send({...bobbyCredentials})
+ .send({
+ username: mockUser.username,
+ password: mockUser.password,
+ grant_type: 'password'
+ })
.then((res) => {
expect(res).to.have.status(400);
});
});
it('should reject invalid usernames', () => {
- chai.request(app)
+ return chai.request(app)
.post('/cs3099group-be-4/login')
- .send({...bobbyCredentials, username: 'invalid'})
+ .send({
+ username: 'invalid',
+ password: mockUser.password,
+ grant_type: 'password'
+ })
.then((res) => {
expect(res).to.have.status(401);
});
});
it('should reject invalid passwords', () => {
- chai.request(app)
+ return chai.request(app)
.post('/cs3099group-be-4/login')
- .send({...bobbyCredentials, password: 'asasasas'})
+ .send({
+ username: mockUser.username,
+ password: 'asasasas',
+ grant_type: 'password'
+ })
.then((res) => {
expect(res).to.have.status(401);
});
});
it('should reject invalid grant_type', () => {
- chai.request(app)
+ return chai.request(app)
.post('/cs3099group-be-4/login')
- .send({...bobbyCredentials, grant_type: 'invalid'})
+ .send({
+ username: mockUser.username,
+ password: mockUser.password,
+ grant_type: 'invalid'
+ })
.catch((reason) => {
expect(reason.response.body).to.eql(unsupportedGrantTypeErr);
});
});
it('should reject empty usernames', () => {
- chai.request(app)
+ return chai.request(app)
.post('/cs3099group-be-4/login')
- .send({...bobbyCredentials, username: ''})
+ .send({
+ username: '',
+ password: mockUser.password,
+ grant_type: 'password'
+ })
.catch((reason) => {
expect(reason.response.body).to.eql(badRequestErr);
});
});
it('should reject empty passwords', () => {
- chai.request(app)
+ return chai.request(app)
.post('/cs3099group-be-4/login')
- .send({...bobbyCredentials, password: ''})
+ .send({
+ username: mockUser.username,
+ password: '',
+ grant_type: 'password'
+ })
.catch((reason) => {
expect(reason.response.body).to.eql(badRequestErr);
});
});
it('should reject empty grant_type', () => {
- chai.request(app)
+ return chai.request(app)
.post('/cs3099group-be-4/login')
- .send({...bobbyCredentials, grant_type: ''})
+ .send({
+ username: mockUser.username,
+ password: mockUser.password,
+ grant_type: ''
+ })
.catch((reason) => {
expect(reason.response.body).to.eql(badRequestErr);
});
});
});
context('valid password authentication', () => {
- before((done: any) => {
- resetDatabase(done);
- });
+ before(populateDatabase);
it('should accept correct credentials', () => {
- chai.request(app)
+ return chai.request(app)
.post('/cs3099group-be-4/login')
- .send(bobbyCredentials)
+ .send({
+ username: mockUser.username,
+ password: mockUser.password,
+ grant_type: 'password'
+ })
.then((res) => {
expect(res).to.have.status(200);
});
});
});
context('token authentication', () => {
- let bobbyToken: string;
- before((done: any) => {
- resetDatabase(() => {
- chai.request(app)
- .post('/cs3099group-be-4/login')
- .send(bobbyCredentials)
- .end((err, res) => {
- if (err) { throw err; }
- bobbyToken = res.body.access_token;
- done();
- });
- });
- });
+ beforeEach(populateDatabase);
+ beforeEach(getToken);
it('should reject invalid tokens', () => {
return chai.request(app).get('/')
.set('Authorization', 'Bearer ' + 'invalid')
@@ -167,7 +184,7 @@ describe('authentication', () => {
});
it('should accept valid tokens', () => {
return chai.request(app).get('/')
- .set('Authorization', 'Bearer ' + bobbyToken)
+ .set('Authorization', `Bearer ${token}`)
.then((res) => {
expect(res).to.have.status(200);
});
diff --git a/test/integration/index.routes.test.ts b/test/integration/index.routes.test.ts
index 70671d8..aa30586 100644
--- a/test/integration/index.routes.test.ts
+++ b/test/integration/index.routes.test.ts
@@ -2,12 +2,12 @@
/* Chai assertions look silly when formatted multiline. */
/* tslint:disable:no-unused-expression */
/* Chai assertions do not require assignation. */
+/* tslint:disable:typedef */
+/* Mocha tests do not require strong typing. */
import * as chai from 'chai';
const expect: Chai.ExpectStatic = chai.expect;
-const should = chai.should();
-import * as ex from 'express';
-import { default as seq } from '../../src/db/orm';
+import { Credentials, Database, addUser, initDB, resetDB } from '../test-db';
import { default as User } from '../../src/db/model/User';
// Chai-http must be imported this way:
@@ -19,66 +19,58 @@ chai.use(require('chai-http'));
import 'mocha';
import * as App from '../../src/app';
-const app: ex.Express = App.TestApp();
-
-const userCredentials: Object = {
- username: 'bobby',
- password: 'pass',
- grant_type: 'password'
-};
+const app = App.TestApp();
+let database: Database;
+let mockUser: Credentials;
let token: string;
-async function startDatabase(done: any) {
- await seq.authenticate();
- await seq.sync({
- force: true
- });
+const initDatabase = async() => {
+ database = initDB();
+ await database.authenticate();
+};
- const newUser: User = new User({
- username: 'bobby',
- password: 'pass',
- userGroups: []
- });
- await newUser.save();
- done();
-}
+const populateDatabase = async() => {
+ await resetDB(database);
+ mockUser = await addUser(database);
+};
-// Add user
-before(function(done: any) {
- startDatabase(done);
-});
+const getToken = async() => {
+ return chai.request(app)
+ .post('/cs3099group-be-4/login')
+ .send({
+ username: mockUser.username,
+ password: mockUser.password,
+ grant_type: 'password'
+ })
+ .then((res) => {
+ token = res.body.access_token;
+ });
+};
describe('routes : index', () => {
+ before(initDatabase);
describe('GET /', () => {
+ before(populateDatabase);
it('should return 401 without authentication', () => {
chai.request(app).get('/')
- .catch(function(err: any) {
+ .catch((err) => {
return expect(err).to.have.status(401);
});
});
context('with authentication', () => {
- before(function(done) {
- chai.request(app)
- .post('/cs3099group-be-4/login')
- .send(userCredentials)
- .end(function(err, res) {
- if (err) { throw err; }
- token = res.body.access_token;
- done();
- });
- });
+ beforeEach(getToken);
it('should return 200', () => {
return chai.request(app).get('/')
- .set('Authorization', 'Bearer ' + token)
+ .set('Authorization', `Bearer ${token}`)
.then((res: ChaiHttp.Response) => {
- res.status.should.eql(200);
+ expect(res).to.have.status(200);
});
});
it('should return json', () => {
return chai.request(app).get('/')
- .set('Authorization', 'Bearer ' + token)
+ .set('Authorization', `Bearer ${token}`)
.then((res: ChaiHttp.Response) => {
expect(res.type).to.eql('application/json');
});
@@ -86,7 +78,7 @@ describe('routes : index', () => {
it('should return a message prop', () => {
return chai.request(app).get('/')
- .set('Authorization', 'Bearer ' + token)
+ .set('Authorization', `Bearer ${token}`)
.then((res: ChaiHttp.Response) => {
expect(res.body.message).to.eql('Welcome to the CS3099 BE4 server!');
});
@@ -94,7 +86,7 @@ describe('routes : index', () => {
it('should return an important prop', () => {
return chai.request(app).get('/')
- .set('Authorization', 'Bearer ' + token)
+ .set('Authorization', `Bearer ${token}`)
.then((res: ChaiHttp.Response) => {
expect(res.body.important)
.to.eql('Endpoints start from /cs3099group-be-4/');
@@ -103,5 +95,4 @@ describe('routes : index', () => {
});
});
-
});
diff --git a/test/integration/protocol.routes.test.ts b/test/integration/protocol.routes.test.ts
index 863bec9..a08f977 100644
--- a/test/integration/protocol.routes.test.ts
+++ b/test/integration/protocol.routes.test.ts
@@ -1,19 +1,60 @@
+/* tslint:disable:newline-per-chained-call */
+/* Chai assertions look silly when formatted multiline. */
+/* tslint:disable:no-unused-expression */
+/* Chai assertions do not require assignation. */
+/* tslint:disable:typedef */
+/* Mocha tests do not require strong typing. */
+
import * as chai from 'chai';
-import * as mocha from 'mocha';
const expect: Chai.ExpectStatic = chai.expect;
+import { Credentials, Database, addUser, initDB, resetDB } from '../test-db';
+import { default as User } from '../../src/db/model/User';
+// Chai-http must be imported this way:
+// tslint:disable-next-line:no-var-requires no-require-imports
chai.use(require('chai-http'));
+
+// Mocha must be imported as a side-effect library:
+// tslint:disable-next-line:no-import-side-effect
import 'mocha';
+
+// Mocha-each must be imported using a require:
+// tslint:disable-next-line:no-require-imports
import forEach = require('mocha-each');
import * as App from '../../src/app';
-import * as ex from 'express';
+const app = App.TestApp();
+
+let database: Database;
+let mockUser: Credentials;
+let token: string;
+
+const initDatabase = async() => {
+ database = initDB();
+ await database.authenticate();
+};
+
+const populateDatabase = async() => {
+ await resetDB(database);
+ mockUser = await addUser(database);
+};
+
+const getToken = async() => {
+ return chai.request(app)
+ .post('/cs3099group-be-4/login')
+ .send({
+ username: mockUser.username,
+ password: mockUser.password,
+ grant_type: 'password'
+ })
+ .then((res) => {
+ token = res.body.access_token;
+ });
+};
+
import { Template, alternative, array, exact, match, optional
} from '../../src/matcher/options';
-import { default as seq } from '../../src/db/orm';
import { default as types } from '../../src/matcher/types';
-import { default as User } from '../../src/db/model/User';
-const app = App.TestApp();
// The general response template according to protocol
const responseTemplate: Template = {
@@ -36,78 +77,32 @@ const errorResponseTemplate: Template = {
type MochaForEachInput = [ string, string, Template, number ];
-const bobbyCredentials = {
- username: 'bobby',
- password: 'tables',
- grant_type: 'password'
-};
-
-let bobbyToken: string;
-
-async function resetDatabase(done: any){
- await seq.sync({
- force: true
- });
- const u: string = bobbyCredentials.username
- const p: string = bobbyCredentials.password
-
- const newUser: User = new User({
- username: u,
- password: p,
- userGroups: []
- });
- await newUser.save();
- done();
-}
-
-async function setupDatabase(done: any) {
- await seq.authenticate();
- await seq.sync({
- force: true
- });
- done();
-}
-
-// Add user
-before((done: any) => {
- setupDatabase(() => {
- resetDatabase(() => {
- chai.request(app)
- .post('/cs3099group-be-4/login')
- .send(bobbyCredentials)
- .end((err, res) => {
- if (err) { throw err; }
- bobbyToken = res.body.access_token;
- done();
- });
- });
- });
-
-});
-
describe('routes : errors', () => {
- describe('GET invalid routes', function() {
+ before(initDatabase);
+ describe('GET invalid routes', () => {
it('should have response code 404', () => {
return chai.request(app).get('/invalid/route')
- .set('Authorization', 'Bearer ' + bobbyToken)
- .catch(function(err: any) {
+ .set('Authorization', `Bearer ${token}`)
+ .catch((err) => {
expect(err.status).to.equal(404);
});
});
- it('should conform to the error protocol', function() {
+ it('should conform to the error protocol', () => {
return chai.request(app).get('/invalid/route')
- .set('Authorization', 'Bearer ' + bobbyToken)
- .catch(function(err: any) {
- match(errorResponseTemplate)(err.response.body).should.be.true;
+ .set('Authorization', `Bearer ${token}`)
+ .catch((err) => {
+ expect(match(errorResponseTemplate)(err.response.body)).to.be.true;
});
});
});
-
});
describe('routes : protocol', () => {
const base: string = '/cs3099group-be-4';
- // format:
+
+ /* tslint:disable:align */
+
+ // Format:
// <method> <route> <json-response-template> <response-code>
const completeProtocol: MochaForEachInput[] = [
['get', '/_supported_protocols_', exact({
@@ -166,7 +161,7 @@ describe('routes : protocol', () => {
public_admin_metadata: types.anything,
private_admin_metadata: types.anything
}), 401],
- // todo types.metadata
+ // TODO types.metadata
['get', '/users/:username', {
username: types.string,
privileges: array(types.string),
@@ -230,55 +225,63 @@ describe('routes : protocol', () => {
['get', '/projects/:project_name/files_by_id/:id', null, 200]
];
+ /* tslint:enable:align */
+
+ before(initDatabase);
+ beforeEach(populateDatabase);
+ beforeEach(getToken);
+
describe('Access all valid routes', () => {
forEach(completeProtocol).it(
'%s %s should be json',
- (method: string, path: string, temp: Template, res_code: number) => {
+ (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);
- request.set('Authorization', 'Bearer ' + bobbyToken);
+ request.set('Authorization', `Bearer ${token}`);
return request.then((res: ChaiHttp.Response) => {
expect(res.type).to.equal('application/json');
- }).catch(function(err: any) {
- match(errorResponseTemplate)(err.response.body).should.be.true;
+ }).catch((err) => {
+ expect(match(errorResponseTemplate)(err.response.body)).to.be.true;
});
});
forEach(completeProtocol).it(
'%s %s should have a status %4$d',
- (method: string, path: string, temp: Template, res_code: number) => {
+ (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);
- request.set('Authorization', 'Bearer ' + bobbyToken);
+ request.set('Authorization', `Bearer ${token}`);
return request.then((res: ChaiHttp.Response) => {
- expect(res).to.have.status(res_code);
- }).catch(function(err: any) {
- match(errorResponseTemplate)(err.response.body).should.be.true;
+ expect(res).to.have.status(resCode);
+ }).catch((err) => {
+ expect(match(errorResponseTemplate)(err.response.body)).to.be.true;
});
});
forEach(completeProtocol).it(
'%s %s should conform to the general response protocol',
- (method: string, path: string, temp: Template, res_code: number) => {
+ (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);
- request.set('Authorization', 'Bearer ' + bobbyToken);
+ request.set('Authorization', `Bearer ${token}`);
return request.then((res: ChaiHttp.Response) => {
match(responseTemplate, JSON.parse(res.body)).shoul.be.true;
- }).catch(function(err: any) {
- match(errorResponseTemplate)(err.response.body).should.be.true;
+ }).catch((err) => {
+ expect(match(errorResponseTemplate)(err.response.body)).to.be.true;
});
});
forEach(completeProtocol).it(
'the response for %s %s should conform to its specific response protocol',
- (method: string, path: string, temp: Template, res_code: number) => {
+ (method: string, path: string, temp: Template, resCode: number) => {
if (method === 'get' && temp != null) {
- return chai.request(app).get(base + path).set('Authorization', 'Bearer ' + bobbyToken)
+ return chai.request(app)
+ .get(base + path)
+ .set('Authorization', `Bearer ${token}`)
.then((res: ChaiHttp.Response) => {
- match(temp)(JSON.parse(res.body)).should.be.true;
- }).catch(function(err: any) {
- match(errorResponseTemplate)(err.response.body).should.be.true;
+ expect(match(temp)(JSON.parse(res.body))).to.be.true;
+ }).catch((err) => {
+ expect(match(errorResponseTemplate)(err.response.body)).to.be.true;
});
} else {
return true;
diff --git a/test/test-db.ts b/test/test-db.ts
new file mode 100644
index 0000000..fe8ae4d
--- /dev/null
+++ b/test/test-db.ts
@@ -0,0 +1,41 @@
+import { default as User } from '../src/db/model/User';
+import { default as UserGroup } from '../src/db/model/UserGroup';
+
+import { Sequelize } from 'sequelize-typescript';
+import * as sqlite from 'sqlite3';
+
+export type Database = Sequelize;
+
+export const initDB: () => Database = (): Database => {
+ const dataFile: string = ':memory:';
+ const db: sqlite.Database = 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 resetDB: (database: Database) => Promise<void> = async(
+ database: Database
+): Promise<void> => {
+ await database.sync({
+ force: true
+ });
+};
+
+export interface Credentials {
+ username: string;
+ password: string;
+ usergroups: UserGroup[];
+}
+
+export const addUser: (database?: Database) => Promise<Credentials> = async(
+): Promise<Credentials> => {
+ const mockUser: Credentials = {
+ username: 'mock_user',
+ password: 'mock_password',
+ usergroups: []
+ };
+ await new User(mockUser).save();
+ return mockUser;
+};
diff --git a/yarn.lock b/yarn.lock
index 551800a..ef72a51 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -221,6 +221,12 @@
"@types/glob" "*"
"@types/node" "*"
+"@types/sqlite3@^3.1.1":
+ version "3.1.1"
+ resolved "https://registry.yarnpkg.com/@types/sqlite3/-/sqlite3-3.1.1.tgz#f9b707c574e8d2f73d6c41aaa86e28b6ef85a324"
+ dependencies:
+ "@types/node" "*"
+
"@types/superagent@*":
version "3.5.7"
resolved "https://registry.yarnpkg.com/@types/superagent/-/superagent-3.5.7.tgz#c170633e7dff01425b4712bb3afac3a12be49b7b"
@@ -638,6 +644,10 @@ chokidar@^2.0.0:
optionalDependencies:
fsevents "^1.0.0"
+chownr@^1.0.1:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.0.1.tgz#e2a75042a9551908bebd25b8523d5f9769d79181"
+
class-utils@^0.3.5:
version "0.3.6"
resolved "https://registry.yarnpkg.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463"
@@ -833,7 +843,7 @@ debug@2.6.8:
dependencies:
ms "2.0.0"
-debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.9:
+debug@2.6.9, debug@^2.1.2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
dependencies:
@@ -1189,6 +1199,12 @@ fs-extra@^5.0.0:
jsonfile "^4.0.0"
universalify "^0.1.0"
+fs-minipass@^1.2.5:
+ version "1.2.5"
+ resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.5.tgz#06c277218454ec288df77ada54a03b8702aacb9d"
+ dependencies:
+ minipass "^2.2.1"
+
fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -1421,7 +1437,7 @@ http-signature@~1.1.0:
jsprim "^1.2.2"
sshpk "^1.7.0"
-iconv-lite@0.4.19:
+iconv-lite@0.4.19, iconv-lite@^0.4.4:
version "0.4.19"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
@@ -1429,6 +1445,12 @@ ignore-by-default@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/ignore-by-default/-/ignore-by-default-1.0.1.tgz#48ca6d72f6c6a3af00a9ad4ae6876be3889e2b09"
+ignore-walk@^3.0.1:
+ version "3.0.1"
+ resolved "https://registry.yarnpkg.com/ignore-walk/-/ignore-walk-3.0.1.tgz#a83e62e7d272ac0e3b551aaa82831a19b69f82f8"
+ dependencies:
+ minimatch "^3.0.4"
+
import-lazy@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/import-lazy/-/import-lazy-2.1.0.tgz#05698e3d45c88e8d7e9d92cb0584e77f096f3e43"
@@ -1995,6 +2017,19 @@ minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
+minipass@^2.2.1, minipass@^2.2.4:
+ version "2.2.4"
+ resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.2.4.tgz#03c824d84551ec38a8d1bb5bc350a5a30a354a40"
+ dependencies:
+ safe-buffer "^5.1.1"
+ yallist "^3.0.0"
+
+minizlib@^1.1.0:
+ version "1.1.0"
+ resolved "https://registry.yarnpkg.com/minizlib/-/minizlib-1.1.0.tgz#11e13658ce46bc3a70a267aac58359d1e0c29ceb"
+ dependencies:
+ minipass "^2.2.1"
+
mixin-deep@^1.2.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.1.tgz#a49e7268dce1a0d9698e45326c5626df3543d0fe"
@@ -2002,7 +2037,7 @@ mixin-deep@^1.2.0:
for-in "^1.0.2"
is-extendable "^1.0.1"
-mkdirp@0.5.1, "mkdirp@>=0.5 0", mkdirp@^0.5.1:
+mkdirp@0.5.1, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
dependencies:
@@ -2063,6 +2098,10 @@ nan@^2.3.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.8.0.tgz#ed715f3fe9de02b57a5e6252d90a96675e1f085a"
+nan@~2.9.2:
+ version "2.9.2"
+ resolved "https://registry.yarnpkg.com/nan/-/nan-2.9.2.tgz#f564d75f5f8f36a6d9456cca7a6c4fe488ab7866"
+
nanomatch@^1.2.5:
version "1.2.7"
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.7.tgz#53cd4aa109ff68b7f869591fdc9d10daeeea3e79"
@@ -2079,6 +2118,14 @@ nanomatch@^1.2.5:
snapdragon "^0.8.1"
to-regex "^3.0.1"
+needle@^2.2.0:
+ version "2.2.0"
+ resolved "https://registry.yarnpkg.com/needle/-/needle-2.2.0.tgz#f14efc69cee1024b72c8b21c7bdf94a731dc12fa"
+ dependencies:
+ debug "^2.1.2"
+ iconv-lite "^0.4.4"
+ sax "^1.2.4"
+
negotiator@0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9"
@@ -2099,6 +2146,21 @@ node-pre-gyp@^0.6.39:
tar "^2.2.1"
tar-pack "^3.4.0"
+node-pre-gyp@~0.9.0:
+ version "0.9.0"
+ resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.9.0.tgz#bdd4c3afac9b1b1ebff0a9ff3362859eb6781bb8"
+ dependencies:
+ detect-libc "^1.0.2"
+ mkdirp "^0.5.1"
+ needle "^2.2.0"
+ nopt "^4.0.1"
+ npm-packlist "^1.1.6"
+ npmlog "^4.0.2"
+ rc "^1.1.7"
+ rimraf "^2.6.1"
+ semver "^5.3.0"
+ tar "^4"
+
nodemon@^1.14.10:
version "1.14.12"
resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-1.14.12.tgz#fe059424b15ebdb107696287a558d9cf53a63999"
@@ -2132,6 +2194,17 @@ normalize-path@^2.1.1:
dependencies:
remove-trailing-separator "^1.0.1"
+npm-bundled@^1.0.1:
+ version "1.0.3"
+ resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.0.3.tgz#7e71703d973af3370a9591bafe3a63aca0be2308"
+
+npm-packlist@^1.1.6:
+ version "1.1.10"
+ resolved "https://registry.yarnpkg.com/npm-packlist/-/npm-packlist-1.1.10.tgz#1039db9e985727e464df066f4cf0ab6ef85c398a"
+ dependencies:
+ ignore-walk "^3.0.1"
+ npm-bundled "^1.0.1"
+
npm-run-path@^2.0.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f"
@@ -2591,10 +2664,14 @@ rimraf@2, rimraf@^2.5.1, rimraf@^2.6.1:
dependencies:
glob "^7.0.5"
-safe-buffer@5.1.1, safe-buffer@^5.0.1, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
+safe-buffer@5.1.1, safe-buffer@^5.0.1, safe-buffer@^5.1.1, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853"
+sax@^1.2.4:
+ version "1.2.4"
+ resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
+
semver-diff@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/semver-diff/-/semver-diff-2.1.0.tgz#4bbb8437c8d37e4b0cf1a68fd726ec6d645d6d36"
@@ -2824,6 +2901,13 @@ sprintf-js@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
+sqlite3@^4.0.0:
+ version "4.0.0"
+ resolved "https://registry.yarnpkg.com/sqlite3/-/sqlite3-4.0.0.tgz#cc0e093ab51873f50d9dfc4126fcbef15d486570"
+ dependencies:
+ nan "~2.9.2"
+ node-pre-gyp "~0.9.0"
+
ssf@~0.10.1:
version "0.10.1"
resolved "https://registry.yarnpkg.com/ssf/-/ssf-0.10.1.tgz#f23d82b63792ef56089089c1cd0c848e911cdba6"
@@ -2996,6 +3080,18 @@ tar@^2.2.1:
fstream "^1.0.2"
inherits "2"
+tar@^4:
+ version "4.4.1"
+ resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.1.tgz#b25d5a8470c976fd7a9a8a350f42c59e9fa81749"
+ dependencies:
+ chownr "^1.0.1"
+ fs-minipass "^1.2.5"
+ minipass "^2.2.4"
+ minizlib "^1.1.0"
+ mkdirp "^0.5.0"
+ safe-buffer "^5.1.1"
+ yallist "^3.0.2"
+
term-size@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/term-size/-/term-size-1.2.0.tgz#458b83887f288fc56d6fffbfad262e26638efa69"
@@ -3394,6 +3490,10 @@ yallist@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"
+yallist@^3.0.0, yallist@^3.0.2:
+ version "3.0.2"
+ resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.2.tgz#8452b4bb7e83c7c188d8041c1a837c773d6d8bb9"
+
yargs@~3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.10.0.tgz#f7ee7bd857dd7c1d2d38c0e74efbd681d1431fd1"