diff options
| author | Tom Harley | 2020-01-24 06:44:55 +0000 |
|---|---|---|
| committer | Tom Harley | 2020-01-24 06:44:55 +0000 |
| commit | 354e6851e70d7c19106af0d4f14c2b2751e7167d (patch) | |
| tree | 3a00ce281cd6466566708dc1c8234d0b2979945d /test | |
| parent | Simplify Travis CI installing (diff) | |
| download | medicine-trh/travis-setup.tar.gz medicine-trh/travis-setup.zip | |
Changes from ages ago
HEADtrh/travis-setupDiffstat (limited to 'test')
| -rw-r--r-- | test/integration/auth.routes.test.ts | 5 | ||||
| -rw-r--r-- | test/integration/index.routes.test.ts | 5 | ||||
| -rw-r--r-- | test/integration/protocol.routes.test.ts | 6 | ||||
| -rw-r--r-- | test/test-db.ts | 9 |
4 files changed, 20 insertions, 5 deletions
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> => { |
