Skip to content

Commit

Permalink
Updated tests to utilise user config.
Browse files Browse the repository at this point in the history
  • Loading branch information
nero120 committed Jul 17, 2018
1 parent c7039eb commit 5fe00f5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
1 change: 1 addition & 0 deletions test/integration/bookmarks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('BookmarksRouter', () => {
beforeEach(async () => {
testConfig = Config.get(true);
testConfig.log.enabled = false;
testConfig.db.name = testConfig.tests.db;
testConfig.server.port = testConfig.tests.port;
sandbox = sinon.createSandbox();

Expand Down
12 changes: 4 additions & 8 deletions test/integration/docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@ describe('Docs', () => {
let testConfig: any;

beforeEach(async () => {
const { version } = require('../../package.json');
testConfig = {
...require('../../config/settings.default.json'),
version
};
testConfig.db.name = testConfig.tests.db;
testConfig = Config.get(true);
testConfig.log.enabled = false;
testConfig.db.name = testConfig.tests.db;
testConfig.server.port = testConfig.tests.port;
sandbox = sinon.createSandbox();
sandbox.stub(Config, 'get').returns(testConfig);

server = new Server();
server.logToConsoleEnabled(false);
Expand All @@ -37,10 +32,11 @@ describe('Docs', () => {
afterEach(async () => {
await server.stop();
sandbox.restore();
decache('../../config/settings.default.json');
});

it('GET /: Should return a 200 code', async () => {
sandbox.stub(Config, 'get').returns(testConfig);

await new Promise((resolve) => {
request(server.Application)
.get('/')
Expand Down
12 changes: 4 additions & 8 deletions test/integration/info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@ describe('InfoRouter', () => {
let testConfig: any;

beforeEach(async () => {
const { version } = require('../../package.json');
testConfig = {
...require('../../config/settings.default.json'),
version
};
testConfig.db.name = testConfig.tests.db;
testConfig = Config.get(true);
testConfig.log.enabled = false;
testConfig.db.name = testConfig.tests.db;
testConfig.server.port = testConfig.tests.port;
sandbox = sinon.createSandbox();
sandbox.stub(Config, 'get').returns(testConfig);

server = new Server();
server.logToConsoleEnabled(false);
Expand All @@ -37,10 +32,11 @@ describe('InfoRouter', () => {
afterEach(async () => {
await server.stop();
sandbox.restore();
decache('../../config/settings.default.json');
});

it('GET info: should return api status info', async () => {
sandbox.stub(Config, 'get').returns(testConfig);

await new Promise((resolve) => {
request(server.Application)
.get('/info')
Expand Down
16 changes: 8 additions & 8 deletions test/integration/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,11 @@ describe('Server', () => {
let testConfig: any;

beforeEach(async () => {
const { version } = require('../../package.json');
testConfig = {
...require('../../config/settings.default.json'),
version
};
testConfig.db.name = testConfig.tests.db;
testConfig = Config.get(true);
testConfig.log.enabled = false;
testConfig.db.name = testConfig.tests.db;
testConfig.server.port = testConfig.tests.port;
sandbox = sinon.createSandbox();
sandbox.stub(Config, 'get').returns(testConfig);

server = new Server();
server.logToConsoleEnabled(false);
Expand All @@ -49,10 +44,11 @@ describe('Server', () => {
afterEach(async () => {
await server.stop();
sandbox.restore();
decache('../../config/settings.default.json');
});

it('Should return a NotImplementedException error code for an invalid route', async () => {
sandbox.stub(Config, 'get').returns(testConfig);

await new Promise((resolve) => {
request(server.Application)
.get('/bookmarks')
Expand All @@ -69,6 +65,7 @@ describe('Server', () => {
it('Should return an OriginNotPermittedException error code when requested api version is not supported', async () => {
await server.stop();
testConfig.allowedOrigins = ['http://test.com'];
sandbox.stub(Config, 'get').returns(testConfig);
server = new Server();
server.logToConsoleEnabled(false);
await server.init();
Expand All @@ -90,6 +87,7 @@ describe('Server', () => {
it('Should return a RequestThrottledException error code when request throttling is triggered', async () => {
await server.stop();
testConfig.throttle.maxRequests = 1;
sandbox.stub(Config, 'get').returns(testConfig);
server = new Server();
server.logToConsoleEnabled(false);
await server.init();
Expand Down Expand Up @@ -118,6 +116,8 @@ describe('Server', () => {
});

it('Should return an UnsupportedVersionException error code when requested api version is not supported', async () => {
sandbox.stub(Config, 'get').returns(testConfig);

await new Promise((resolve) => {
request(server.Application)
.get('/info')
Expand Down

0 comments on commit 5fe00f5

Please # to comment.