diff options
author | Nick Van Doorn <vandoorn.nick@gmail.com> | 2017-04-25 22:49:41 -0700 |
---|---|---|
committer | Nick Van Doorn <vandoorn.nick@gmail.com> | 2017-04-25 22:49:41 -0700 |
commit | 4175e511788b7260424ef3616100b6127c909f89 (patch) | |
tree | 5e7f046d941f3d3aa9d183416a93ba15c2102d63 | |
parent | 33f68404e71722894d3e9541b5a0d07e5d6aea95 (diff) |
Start test cleanup for new API
-rw-r--r-- | src/server/test/api.test.js | 78 |
1 files changed, 8 insertions, 70 deletions
diff --git a/src/server/test/api.test.js b/src/server/test/api.test.js index 29b522f..725a8c0 100644 --- a/src/server/test/api.test.js +++ b/src/server/test/api.test.js @@ -5,20 +5,19 @@ const assert = require('chai').assert const path = require('path') const axios = require('axios') +const subset = require('json-subset') + const get = (route, params) => axios.get(route, { params: params }) -const put = axios.put const post = axios.post const constants = require('../../constants') +const ROUTES = require('../routes').routes const createServer = require('../../../scripts/server') const LOGFILE_PATH = path.join(__dirname, './fixtures') -const LOGFILE_NAME = 'testlog.log' const TEST_PORT = 5000 const BASE_ROUTE = `http://localhost:${TEST_PORT}/api` -const CONFIG_ROUTE = `${BASE_ROUTE}/config` -const FILE_ROUTE = `${BASE_ROUTE}/file` -const DIRECTORY_ROUTE = `${BASE_ROUTE}/directory` +const CONFIG_ROUTE = BASE_ROUTE + ROUTES.CONFIG describe('REST API', function () { const server = createServer(TEST_PORT); // eslint-disable-line @@ -33,73 +32,12 @@ describe('REST API', function () { }] } it('should successfully set the config', function () { - return put(CONFIG_ROUTE, config).then(body => { - assert(body.success, 'failed to set config') - }) + console.log(expect(post(CONFIG_ROUTE, config))) }) - it('should successfully get the same config', function () { + it('should successfully get a superset of the same config', function () { return get(CONFIG_ROUTE).then(body => { - assert(body.success, 'failed to get config') - assert.deepEqual(body.data, config, 'configs are not equal') - }) - }) - }) - - describe('#directory()', function () { - it(`should contain ${LOGFILE_NAME}`, function () { - return get(DIRECTORY_ROUTE).then(body => { - assert.include(body.data, LOGFILE_NAME, `directory list did not include ${LOGFILE_NAME}`) - }) - }) - }) - - describe('#query()', function () { - const thisGet = () => get(FILE_ROUTE, { logfile: LOGFILE_NAME }) - const bodyFailMsg = 'query request failed' - it('should correctly parse the first line', function () { - const correct = { - text: `You must be pretty desperate if you're looking at the logs`, - level: constants.levels.info, - levelStr: 'info', - datetime: 1489387840000, - datetimeStr: '6:50:40' - } - return thisGet().then(body => { - assert(body.success, bodyFailMsg) - assert.deepEqual(body.data[0], correct, 'did not correctly parse logline') - }) - }) - - it('should return an empty list for a future date range', function () { - return get(FILE_ROUTE, { - logfile: LOGFILE_NAME, - startdt: Date.now() + 1 * 1000 * 60, - enddt: Date.now() + 2 * 1000 * 60 - }).then(body => { - assert(body.success, `${bodyFailMsg}: ${body.msg}`) - assert(!body.data, 'returned non-empty list for future date query') // TODO this should check length - }) - }) - - it('should default level on unknown level', function () { - return thisGet().then(function (body) { - assert(body.success, bodyFailMsg) - assert.strictEqual(body.data[4].level, constants.defaultLevel, 'level did not default') - }) - }) - - it('should default level string on unknown level', function () { - return thisGet().then(function (body) { - assert(body.success, bodyFailMsg) - assert.strictEqual(body.data[4].levelStr, constants.defaultLevelStr, - 'level string did not defualt') - }) - }) - - it('should return a pagesize of 2', function () { - return get(FILE_ROUTE, { logfile: LOGFILE_NAME, pagesize: 2 }).then(function (body) { - assert(body.success, bodyFailMsg) - assert.strictEqual(body.data.length, 2, 'pagesize is not 2') + assert(body.data.success, 'failed to get config') + assert(subset(config, body.data), 'configs are not equal') }) }) }) |