mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
* Move src/server to Jest * ESLint overrides for src/server tests * Rename files * Fix renamed files * Remove unnecessary changes * Remove exclude of src/server tests
This commit is contained in:
parent
af79bdb5fc
commit
a16fa8422e
58 changed files with 892 additions and 924 deletions
|
@ -3,6 +3,7 @@ export default {
|
|||
roots: [
|
||||
'<rootDir>/src/ui',
|
||||
'<rootDir>/src/core_plugins',
|
||||
'<rootDir>/src/server',
|
||||
'<rootDir>/packages',
|
||||
],
|
||||
collectCoverageFrom: [
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
import expect from 'expect.js';
|
||||
|
||||
import * as kbnTestServer from '../../test_utils/kbn_server';
|
||||
import * as kbnTestServer from '../test_utils/kbn_server';
|
||||
const basePath = '/kibana';
|
||||
|
||||
describe('Server basePath config', function () {
|
||||
this.slow(10000);
|
||||
this.timeout(60000);
|
||||
|
||||
let kbnServer;
|
||||
before(async function () {
|
||||
beforeAll(async function () {
|
||||
kbnServer = kbnTestServer.createServer({
|
||||
server: { basePath }
|
||||
});
|
||||
|
@ -16,7 +11,7 @@ describe('Server basePath config', function () {
|
|||
return kbnServer;
|
||||
});
|
||||
|
||||
after(async function () {
|
||||
afterAll(async function () {
|
||||
await kbnServer.close();
|
||||
});
|
||||
|
||||
|
@ -27,7 +22,7 @@ describe('Server basePath config', function () {
|
|||
};
|
||||
kbnTestServer.makeRequest(kbnServer, options, function (res) {
|
||||
try {
|
||||
expect(res.payload).to.match(/defaultRoute = '\/kibana\/app\/kibana'/);
|
||||
expect(res.payload).toMatch(/defaultRoute = '\/kibana\/app\/kibana'/);
|
||||
done();
|
||||
} catch (e) {
|
||||
done(e);
|
|
@ -1,10 +1,9 @@
|
|||
import completeMixin from '../complete';
|
||||
import expect from 'expect.js';
|
||||
import completeMixin from './complete';
|
||||
import sinon from 'sinon';
|
||||
|
||||
/* eslint-disable import/no-duplicates */
|
||||
import * as transformDeprecationsNS from '../transform_deprecations';
|
||||
import { transformDeprecations } from '../transform_deprecations';
|
||||
import * as transformDeprecationsNS from './transform_deprecations';
|
||||
import { transformDeprecations } from './transform_deprecations';
|
||||
/* eslint-enable import/no-duplicates */
|
||||
|
||||
describe('server/config completeMixin()', function () {
|
||||
|
@ -50,7 +49,7 @@ describe('server/config completeMixin()', function () {
|
|||
callCompleteMixin();
|
||||
sinon.assert.calledOnce(server.decorate);
|
||||
sinon.assert.calledWith(server.decorate, 'server', 'config', sinon.match.func);
|
||||
expect(server.decorate.firstCall.args[2]()).to.be(config);
|
||||
expect(server.decorate.firstCall.args[2]()).toBe(config);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -131,13 +130,13 @@ describe('server/config completeMixin()', function () {
|
|||
}
|
||||
});
|
||||
|
||||
expect(callCompleteMixin).to.throwError(error => {
|
||||
expect(error.message).to.contain('"unused" setting was not applied');
|
||||
});
|
||||
expect(callCompleteMixin).toThrowError('"unused" setting was not applied');
|
||||
});
|
||||
|
||||
describe('error thrown', () => {
|
||||
it('has correct code, processExitCode, and message', () => {
|
||||
expect.assertions(3);
|
||||
|
||||
const { callCompleteMixin } = setup({
|
||||
settings: {
|
||||
unused: true,
|
||||
|
@ -152,11 +151,13 @@ describe('server/config completeMixin()', function () {
|
|||
}
|
||||
});
|
||||
|
||||
expect(callCompleteMixin).to.throwError((error) => {
|
||||
expect(error).to.have.property('code', 'InvalidConfig');
|
||||
expect(error).to.have.property('processExitCode', 64);
|
||||
expect(error.message).to.contain('"unused", "foo", and "namespace.with.sub.keys"');
|
||||
});
|
||||
try {
|
||||
callCompleteMixin();
|
||||
} catch (error) {
|
||||
expect(error).toHaveProperty('code', 'InvalidConfig');
|
||||
expect(error).toHaveProperty('processExitCode', 64);
|
||||
expect(error.message).toMatch('"unused", "foo", and "namespace.with.sub.keys"');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -221,7 +222,7 @@ describe('server/config completeMixin()', function () {
|
|||
configValues: {}
|
||||
});
|
||||
|
||||
expect(callCompleteMixin).to.not.throwError();
|
||||
expect(callCompleteMixin).not.toThrowError();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,5 +1,4 @@
|
|||
import { Config } from '../config';
|
||||
import expect from 'expect.js';
|
||||
import { Config } from './config';
|
||||
import _ from 'lodash';
|
||||
import Joi from 'joi';
|
||||
|
||||
|
@ -48,7 +47,7 @@ describe('lib/config/config', function () {
|
|||
const run = function () {
|
||||
config.set('something.enable', true);
|
||||
};
|
||||
expect(run).to.throwException();
|
||||
expect(run).toThrow();
|
||||
});
|
||||
|
||||
it('should allow keys in the schema', function () {
|
||||
|
@ -56,7 +55,7 @@ describe('lib/config/config', function () {
|
|||
const run = function () {
|
||||
config.set('test.client.host', 'http://localhost');
|
||||
};
|
||||
expect(run).to.not.throwException();
|
||||
expect(run).not.toThrow();
|
||||
});
|
||||
|
||||
it('should not allow keys not in the schema', function () {
|
||||
|
@ -64,7 +63,7 @@ describe('lib/config/config', function () {
|
|||
const run = function () {
|
||||
config.set('paramNotDefinedInTheSchema', true);
|
||||
};
|
||||
expect(run).to.throwException();
|
||||
expect(run).toThrow();
|
||||
});
|
||||
|
||||
it('should not allow child keys not in the schema', function () {
|
||||
|
@ -72,13 +71,13 @@ describe('lib/config/config', function () {
|
|||
const run = function () {
|
||||
config.set('test.client.paramNotDefinedInTheSchema', true);
|
||||
};
|
||||
expect(run).to.throwException();
|
||||
expect(run).toThrow();
|
||||
});
|
||||
|
||||
it('should set defaults', function () {
|
||||
const config = new Config(schema);
|
||||
expect(config.get('test.enable')).to.be(true);
|
||||
expect(config.get('test.client.type')).to.be('datastore');
|
||||
expect(config.get('test.enable')).toBe(true);
|
||||
expect(config.get('test.client.type')).toBe('datastore');
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -95,7 +94,7 @@ describe('lib/config/config', function () {
|
|||
const newData = config.get();
|
||||
newData.test.enable = false;
|
||||
config.resetTo(newData);
|
||||
expect(config.get()).to.eql(newData);
|
||||
expect(config.get()).toEqual(newData);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -108,15 +107,15 @@ describe('lib/config/config', function () {
|
|||
});
|
||||
|
||||
it('should return true for fields that exist in the schema', function () {
|
||||
expect(config.has('test.undefValue')).to.be(true);
|
||||
expect(config.has('test.undefValue')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for partial objects that exist in the schema', function () {
|
||||
expect(config.has('test.client')).to.be(true);
|
||||
expect(config.has('test.client')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for fields that do not exist in the schema', function () {
|
||||
expect(config.has('test.client.pool')).to.be(false);
|
||||
expect(config.has('test.client.pool')).toBe(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -130,21 +129,21 @@ describe('lib/config/config', function () {
|
|||
|
||||
it('should use a key and value to set a config value', function () {
|
||||
config.set('test.enable', false);
|
||||
expect(config.get('test.enable')).to.be(false);
|
||||
expect(config.get('test.enable')).toBe(false);
|
||||
});
|
||||
|
||||
it('should use an object to set config values', function () {
|
||||
const hosts = ['host-01', 'host-02'];
|
||||
config.set({ test: { enable: false, hosts: hosts } });
|
||||
expect(config.get('test.enable')).to.be(false);
|
||||
expect(config.get('test.hosts')).to.eql(hosts);
|
||||
expect(config.get('test.enable')).toBe(false);
|
||||
expect(config.get('test.hosts')).toEqual(hosts);
|
||||
});
|
||||
|
||||
it('should use a flatten object to set config values', function () {
|
||||
const hosts = ['host-01', 'host-02'];
|
||||
config.set({ 'test.enable': false, 'test.hosts': hosts });
|
||||
expect(config.get('test.enable')).to.be(false);
|
||||
expect(config.get('test.hosts')).to.eql(hosts);
|
||||
expect(config.get('test.enable')).toBe(false);
|
||||
expect(config.get('test.hosts')).toEqual(hosts);
|
||||
});
|
||||
|
||||
it('should override values with just the values present', function () {
|
||||
|
@ -152,20 +151,25 @@ describe('lib/config/config', function () {
|
|||
config.set(data);
|
||||
newData.test.enable = false;
|
||||
config.set({ test: { enable: false } });
|
||||
expect(config.get()).to.eql(newData);
|
||||
expect(config.get()).toEqual(newData);
|
||||
});
|
||||
|
||||
it('should thow an exception when setting a value with the wrong type', function (done) {
|
||||
expect.assertions(2);
|
||||
|
||||
const run = function () {
|
||||
config.set('test.enable', 'something');
|
||||
};
|
||||
expect(run).to.throwException(function (err) {
|
||||
expect(err).to.have.property('name', 'ValidationError');
|
||||
expect(err.details[0].message).to.be('"enable" must be a boolean');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
try {
|
||||
run();
|
||||
} catch (err) {
|
||||
expect(err).toHaveProperty('name', 'ValidationError');
|
||||
expect(err.details[0].message).toBe('"enable" must be a boolean');
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
@ -181,30 +185,30 @@ describe('lib/config/config', function () {
|
|||
it('should return the whole config object when called without a key', function () {
|
||||
const newData = _.cloneDeep(data);
|
||||
newData.test.enable = true;
|
||||
expect(config.get()).to.eql(newData);
|
||||
expect(config.get()).toEqual(newData);
|
||||
});
|
||||
|
||||
it('should return the value using dot notation', function () {
|
||||
expect(config.get('test.enable')).to.be(true);
|
||||
expect(config.get('test.enable')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return the clone of partial object using dot notation', function () {
|
||||
expect(config.get('test.client')).to.not.be(data.test.client);
|
||||
expect(config.get('test.client')).to.eql(data.test.client);
|
||||
expect(config.get('test.client')).not.toBe(data.test.client);
|
||||
expect(config.get('test.client')).toEqual(data.test.client);
|
||||
});
|
||||
|
||||
it('should throw exception for unknown config values', function () {
|
||||
const run = function () {
|
||||
config.get('test.does.not.exist');
|
||||
};
|
||||
expect(run).to.throwException(/Unknown config key: test.does.not.exist/);
|
||||
expect(run).toThrowError(/Unknown config key: test.does.not.exist/);
|
||||
});
|
||||
|
||||
it('should not throw exception for undefined known config values', function () {
|
||||
const run = function getUndefValue() {
|
||||
config.get('test.undefValue');
|
||||
};
|
||||
expect(run).to.not.throwException();
|
||||
expect(run).not.toThrow();
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -218,15 +222,15 @@ describe('lib/config/config', function () {
|
|||
it('should allow you to extend the schema at the top level', function () {
|
||||
const newSchema = Joi.object({ test: Joi.boolean().default(true) }).default();
|
||||
config.extendSchema(newSchema, {}, 'myTest');
|
||||
expect(config.get('myTest.test')).to.be(true);
|
||||
expect(config.get('myTest.test')).toBe(true);
|
||||
});
|
||||
|
||||
it('should allow you to extend the schema with a prefix', function () {
|
||||
const newSchema = Joi.object({ test: Joi.boolean().default(true) }).default();
|
||||
config.extendSchema(newSchema, {}, 'prefix.myTest');
|
||||
expect(config.get('prefix')).to.eql({ myTest: { test: true } });
|
||||
expect(config.get('prefix.myTest')).to.eql({ test: true });
|
||||
expect(config.get('prefix.myTest.test')).to.be(true);
|
||||
expect(config.get('prefix')).toEqual({ myTest: { test: true } });
|
||||
expect(config.get('prefix.myTest')).toEqual({ test: true });
|
||||
expect(config.get('prefix.myTest.test')).toBe(true);
|
||||
});
|
||||
|
||||
it('should NOT allow you to extend the schema if somethign else is there', function () {
|
||||
|
@ -234,7 +238,7 @@ describe('lib/config/config', function () {
|
|||
const run = function () {
|
||||
config.extendSchema('test', newSchema);
|
||||
};
|
||||
expect(run).to.throwException();
|
||||
expect(run).toThrow();
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -245,15 +249,15 @@ describe('lib/config/config', function () {
|
|||
a: Joi.number().default(1)
|
||||
}));
|
||||
|
||||
expect(config.get('a')).to.be(1);
|
||||
expect(config.get('a')).toBe(1);
|
||||
config.removeSchema('a');
|
||||
expect(() => config.get('a')).to.throwException('Unknown config key');
|
||||
expect(() => config.get('a')).toThrowError('Unknown config key');
|
||||
});
|
||||
|
||||
it('only removes existing keys', function () {
|
||||
const config = new Config(Joi.object());
|
||||
|
||||
expect(() => config.removeSchema('b')).to.throwException('Unknown schema');
|
||||
expect(() => config.removeSchema('b')).toThrowError('Unknown schema');
|
||||
});
|
||||
});
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
import explodeBy from '../explode_by';
|
||||
import expect from 'expect.js';
|
||||
import explodeBy from './explode_by';
|
||||
|
||||
describe('explode_by(dot, flatObject)', function () {
|
||||
|
||||
|
@ -8,7 +7,7 @@ describe('explode_by(dot, flatObject)', function () {
|
|||
'test.enable': true,
|
||||
'test.hosts': ['host-01', 'host-02']
|
||||
};
|
||||
expect(explodeBy('.', flatObject)).to.eql({
|
||||
expect(explodeBy('.', flatObject)).toEqual({
|
||||
test: {
|
||||
enable: true,
|
||||
hosts: ['host-01', 'host-02']
|
||||
|
@ -21,7 +20,7 @@ describe('explode_by(dot, flatObject)', function () {
|
|||
'test/enable': true,
|
||||
'test/hosts': ['host-01', 'host-02']
|
||||
};
|
||||
expect(explodeBy('/', flatObject)).to.eql({
|
||||
expect(explodeBy('/', flatObject)).toEqual({
|
||||
test: {
|
||||
enable: true,
|
||||
hosts: ['host-01', 'host-02']
|
|
@ -1,5 +1,4 @@
|
|||
import override from '../override';
|
||||
import expect from 'expect.js';
|
||||
import override from './override';
|
||||
|
||||
describe('override(target, source)', function () {
|
||||
|
||||
|
@ -14,7 +13,7 @@ describe('override(target, source)', function () {
|
|||
}
|
||||
};
|
||||
const source = { test: { client: { type: 'nosql' } } };
|
||||
expect(override(target, source)).to.eql({
|
||||
expect(override(target, source)).toEqual({
|
||||
test: {
|
||||
enable: true,
|
||||
host: ['host-01', 'host-02'],
|
|
@ -1,5 +1,4 @@
|
|||
import schemaProvider from '../schema';
|
||||
import expect from 'expect.js';
|
||||
import schemaProvider from './schema';
|
||||
import Joi from 'joi';
|
||||
import { set } from 'lodash';
|
||||
|
||||
|
@ -14,39 +13,39 @@ describe('Config schema', function () {
|
|||
describe('server', function () {
|
||||
it('everything is optional', function () {
|
||||
const { error } = validate({});
|
||||
expect(error).to.be(null);
|
||||
expect(error).toBe(null);
|
||||
});
|
||||
|
||||
describe('basePath', function () {
|
||||
it('accepts empty strings', function () {
|
||||
const { error, value } = validate({ server: { basePath: '' } });
|
||||
expect(error == null).to.be.ok();
|
||||
expect(value.server.basePath).to.be('');
|
||||
expect(error).toBe(null);
|
||||
expect(value.server.basePath).toBe('');
|
||||
});
|
||||
|
||||
it('accepts strings with leading slashes', function () {
|
||||
const { error, value } = validate({ server: { basePath: '/path' } });
|
||||
expect(error == null).to.be.ok();
|
||||
expect(value.server.basePath).to.be('/path');
|
||||
expect(error).toBe(null);
|
||||
expect(value.server.basePath).toBe('/path');
|
||||
});
|
||||
|
||||
it('rejects strings with trailing slashes', function () {
|
||||
const { error } = validate({ server: { basePath: '/path/' } });
|
||||
expect(error).to.have.property('details');
|
||||
expect(error.details[0]).to.have.property('path', 'server.basePath');
|
||||
expect(error).toHaveProperty('details');
|
||||
expect(error.details[0]).toHaveProperty('path', 'server.basePath');
|
||||
});
|
||||
|
||||
it('rejects strings without leading slashes', function () {
|
||||
const { error } = validate({ server: { basePath: 'path' } });
|
||||
expect(error).to.have.property('details');
|
||||
expect(error.details[0]).to.have.property('path', 'server.basePath');
|
||||
expect(error).toHaveProperty('details');
|
||||
expect(error.details[0]).toHaveProperty('path', 'server.basePath');
|
||||
});
|
||||
|
||||
it('rejects things that are not strings', function () {
|
||||
for (const value of [1, true, {}, [], /foo/]) {
|
||||
const { error } = validate({ server: { basePath: value } });
|
||||
expect(error).to.have.property('details');
|
||||
expect(error.details[0]).to.have.property('path', 'server.basePath');
|
||||
expect(error).toHaveProperty('details');
|
||||
expect(error.details[0]).toHaveProperty('path', 'server.basePath');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -54,32 +53,32 @@ describe('Config schema', function () {
|
|||
describe('rewriteBasePath', function () {
|
||||
it('defaults to false', () => {
|
||||
const { error, value } = validate({});
|
||||
expect(error).to.be(null);
|
||||
expect(value.server.rewriteBasePath).to.be(false);
|
||||
expect(error).toBe(null);
|
||||
expect(value.server.rewriteBasePath).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts false', function () {
|
||||
const { error, value } = validate({ server: { rewriteBasePath: false } });
|
||||
expect(error).to.be(null);
|
||||
expect(value.server.rewriteBasePath).to.be(false);
|
||||
expect(error).toBe(null);
|
||||
expect(value.server.rewriteBasePath).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts true if basePath set', function () {
|
||||
const { error, value } = validate({ server: { basePath: '/foo', rewriteBasePath: true } });
|
||||
expect(error).to.be(null);
|
||||
expect(value.server.rewriteBasePath).to.be(true);
|
||||
expect(error).toBe(null);
|
||||
expect(value.server.rewriteBasePath).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects true if basePath not set', function () {
|
||||
const { error } = validate({ server: { rewriteBasePath: true } });
|
||||
expect(error).to.have.property('details');
|
||||
expect(error.details[0]).to.have.property('path', 'server.rewriteBasePath');
|
||||
expect(error).toHaveProperty('details');
|
||||
expect(error.details[0]).toHaveProperty('path', 'server.rewriteBasePath');
|
||||
});
|
||||
|
||||
it('rejects strings', function () {
|
||||
const { error } = validate({ server: { rewriteBasePath: 'foo' } });
|
||||
expect(error).to.have.property('details');
|
||||
expect(error.details[0]).to.have.property('path', 'server.rewriteBasePath');
|
||||
expect(error).toHaveProperty('details');
|
||||
expect(error.details[0]).toHaveProperty('path', 'server.rewriteBasePath');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -90,9 +89,9 @@ describe('Config schema', function () {
|
|||
const config = {};
|
||||
set(config, 'server.ssl.enabled', 'bogus');
|
||||
const { error } = validate(config);
|
||||
expect(error).to.be.an(Object);
|
||||
expect(error).to.have.property('details');
|
||||
expect(error.details[0]).to.have.property('path', 'server.ssl.enabled');
|
||||
expect(error).toBeInstanceOf(Object);
|
||||
expect(error).toHaveProperty('details');
|
||||
expect(error.details[0]).toHaveProperty('path', 'server.ssl.enabled');
|
||||
});
|
||||
|
||||
it('can be true', function () {
|
||||
|
@ -101,14 +100,14 @@ describe('Config schema', function () {
|
|||
set(config, 'server.ssl.certificate', '/path.cert');
|
||||
set(config, 'server.ssl.key', '/path.key');
|
||||
const { error } = validate(config);
|
||||
expect(error).to.be(null);
|
||||
expect(error).toBe(null);
|
||||
});
|
||||
|
||||
it('can be false', function () {
|
||||
const config = {};
|
||||
set(config, 'server.ssl.enabled', false);
|
||||
const { error } = validate(config);
|
||||
expect(error).to.be(null);
|
||||
expect(error).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -118,7 +117,7 @@ describe('Config schema', function () {
|
|||
const config = {};
|
||||
set(config, 'server.ssl.enabled', false);
|
||||
const { error } = validate(config);
|
||||
expect(error).to.be(null);
|
||||
expect(error).toBe(null);
|
||||
});
|
||||
|
||||
it('is required when ssl is enabled', function () {
|
||||
|
@ -126,9 +125,9 @@ describe('Config schema', function () {
|
|||
set(config, 'server.ssl.enabled', true);
|
||||
set(config, 'server.ssl.key', '/path.key');
|
||||
const { error } = validate(config);
|
||||
expect(error).to.be.an(Object);
|
||||
expect(error).to.have.property('details');
|
||||
expect(error.details[0]).to.have.property('path', 'server.ssl.certificate');
|
||||
expect(error).toBeInstanceOf(Object);
|
||||
expect(error).toHaveProperty('details');
|
||||
expect(error.details[0]).toHaveProperty('path', 'server.ssl.certificate');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -137,7 +136,7 @@ describe('Config schema', function () {
|
|||
const config = {};
|
||||
set(config, 'server.ssl.enabled', false);
|
||||
const { error } = validate(config);
|
||||
expect(error).to.be(null);
|
||||
expect(error).toBe(null);
|
||||
});
|
||||
|
||||
it('is required when ssl is enabled', function () {
|
||||
|
@ -145,18 +144,18 @@ describe('Config schema', function () {
|
|||
set(config, 'server.ssl.enabled', true);
|
||||
set(config, 'server.ssl.certificate', '/path.cert');
|
||||
const { error } = validate(config);
|
||||
expect(error).to.be.an(Object);
|
||||
expect(error).to.have.property('details');
|
||||
expect(error.details[0]).to.have.property('path', 'server.ssl.key');
|
||||
expect(error).toBeInstanceOf(Object);
|
||||
expect(error).toHaveProperty('details');
|
||||
expect(error.details[0]).toHaveProperty('path', 'server.ssl.key');
|
||||
});
|
||||
});
|
||||
|
||||
describe('keyPassphrase', function () {
|
||||
it ('is a possible config value', function () {
|
||||
it('is a possible config value', function () {
|
||||
const config = {};
|
||||
set(config, 'server.ssl.keyPassphrase', 'password');
|
||||
const { error } = validate(config);
|
||||
expect(error).to.be(null);
|
||||
expect(error).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -165,14 +164,14 @@ describe('Config schema', function () {
|
|||
const config = {};
|
||||
set(config, 'server.ssl.certificateAuthorities', ['/path1.crt', '/path2.crt']);
|
||||
const { error } = validate(config);
|
||||
expect(error).to.be(null);
|
||||
expect(error).toBe(null);
|
||||
});
|
||||
|
||||
it('allows a single string', function () {
|
||||
const config = {};
|
||||
set(config, 'server.ssl.certificateAuthorities', '/path1.crt');
|
||||
const { error } = validate(config);
|
||||
expect(error).to.be(null);
|
||||
expect(error).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -182,25 +181,25 @@ describe('Config schema', function () {
|
|||
const config = {};
|
||||
set(config, 'server.ssl.supportedProtocols', ['SSLv2']);
|
||||
const { error } = validate(config);
|
||||
expect(error).to.be.an(Object);
|
||||
expect(error).to.have.property('details');
|
||||
expect(error.details[0]).to.have.property('path', 'server.ssl.supportedProtocols.0');
|
||||
expect(error).toBeInstanceOf(Object);
|
||||
expect(error).toHaveProperty('details');
|
||||
expect(error.details[0]).toHaveProperty('path', 'server.ssl.supportedProtocols.0');
|
||||
});
|
||||
|
||||
it('rejects SSLv3', function () {
|
||||
const config = {};
|
||||
set(config, 'server.ssl.supportedProtocols', ['SSLv3']);
|
||||
const { error } = validate(config);
|
||||
expect(error).to.be.an(Object);
|
||||
expect(error).to.have.property('details');
|
||||
expect(error.details[0]).to.have.property('path', 'server.ssl.supportedProtocols.0');
|
||||
expect(error).toBeInstanceOf(Object);
|
||||
expect(error).toHaveProperty('details');
|
||||
expect(error.details[0]).toHaveProperty('path', 'server.ssl.supportedProtocols.0');
|
||||
});
|
||||
|
||||
it('accepts TLSv1, TLSv1.1, TLSv1.2', function () {
|
||||
const config = {};
|
||||
set(config, 'server.ssl.supportedProtocols', ['TLSv1', 'TLSv1.1', 'TLSv1.2']);
|
||||
const { error } = validate(config);
|
||||
expect(error).to.be(null);
|
||||
expect(error).toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -208,14 +207,14 @@ describe('Config schema', function () {
|
|||
describe('xsrf', () => {
|
||||
it('disableProtection is `false` by default.', () => {
|
||||
const { error, value: { server: { xsrf: { disableProtection } } } } = validate({});
|
||||
expect(error).to.be(null);
|
||||
expect(disableProtection).to.be(false);
|
||||
expect(error).toBe(null);
|
||||
expect(disableProtection).toBe(false);
|
||||
});
|
||||
|
||||
it('whitelist is empty by default.', () => {
|
||||
const { value: { server: { xsrf: { whitelist } } } } = validate({});
|
||||
expect(whitelist).to.be.an(Array);
|
||||
expect(whitelist).to.have.length(0);
|
||||
expect(whitelist).toBeInstanceOf(Array);
|
||||
expect(whitelist).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('whitelist rejects paths that do not start with a slash.', () => {
|
||||
|
@ -223,9 +222,9 @@ describe('Config schema', function () {
|
|||
set(config, 'server.xsrf.whitelist', ['path/to']);
|
||||
|
||||
const { error } = validate(config);
|
||||
expect(error).to.be.an(Object);
|
||||
expect(error).to.have.property('details');
|
||||
expect(error.details[0]).to.have.property('path', 'server.xsrf.whitelist.0');
|
||||
expect(error).toBeInstanceOf(Object);
|
||||
expect(error).toHaveProperty('details');
|
||||
expect(error.details[0]).toHaveProperty('path', 'server.xsrf.whitelist.0');
|
||||
});
|
||||
|
||||
it('whitelist accepts paths that start with a slash.', () => {
|
||||
|
@ -233,10 +232,10 @@ describe('Config schema', function () {
|
|||
set(config, 'server.xsrf.whitelist', ['/path/to']);
|
||||
|
||||
const { error, value: { server: { xsrf: { whitelist } } } } = validate(config);
|
||||
expect(error).to.be(null);
|
||||
expect(whitelist).to.be.an(Array);
|
||||
expect(whitelist).to.have.length(1);
|
||||
expect(whitelist).to.contain('/path/to');
|
||||
expect(error).toBe(null);
|
||||
expect(whitelist).toBeInstanceOf(Array);
|
||||
expect(whitelist).toHaveLength(1);
|
||||
expect(whitelist).toContain('/path/to');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,6 +1,5 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import { transformDeprecations } from '../transform_deprecations';
|
||||
import { transformDeprecations } from './transform_deprecations';
|
||||
|
||||
describe('server/config', function () {
|
||||
describe('transformDeprecations', function () {
|
||||
|
@ -16,7 +15,7 @@ describe('server/config', function () {
|
|||
};
|
||||
|
||||
const result = transformDeprecations(settings);
|
||||
expect(result.server.ssl.enabled).to.be(true);
|
||||
expect(result.server.ssl.enabled).toBe(true);
|
||||
});
|
||||
|
||||
it('logs a message when automatically setting enabled to true', function () {
|
||||
|
@ -31,7 +30,7 @@ describe('server/config', function () {
|
|||
|
||||
const log = sinon.spy();
|
||||
transformDeprecations(settings, log);
|
||||
expect(log.calledOnce).to.be(true);
|
||||
expect(log.calledOnce).toBe(true);
|
||||
});
|
||||
|
||||
it(`doesn't set enabled when key and cert aren't set`, function () {
|
||||
|
@ -42,7 +41,7 @@ describe('server/config', function () {
|
|||
};
|
||||
|
||||
const result = transformDeprecations(settings);
|
||||
expect(result.server.ssl.enabled).to.be(undefined);
|
||||
expect(result.server.ssl.enabled).toBe(undefined);
|
||||
});
|
||||
|
||||
it(`doesn't log a message when not automatically setting enabled`, function () {
|
||||
|
@ -54,7 +53,7 @@ describe('server/config', function () {
|
|||
|
||||
const log = sinon.spy();
|
||||
transformDeprecations(settings, log);
|
||||
expect(log.called).to.be(false);
|
||||
expect(log.called).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -66,7 +65,7 @@ describe('server/config', function () {
|
|||
}
|
||||
};
|
||||
|
||||
expect(transformDeprecations(settings)).to.eql({});
|
||||
expect(transformDeprecations(settings)).toEqual({});
|
||||
});
|
||||
|
||||
it('keeps the savedObjects property if it has other keys', () => {
|
||||
|
@ -77,7 +76,7 @@ describe('server/config', function () {
|
|||
}
|
||||
};
|
||||
|
||||
expect(transformDeprecations(settings)).to.eql({
|
||||
expect(transformDeprecations(settings)).toEqual({
|
||||
savedObjects: {
|
||||
foo: 'bar'
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
import expect from 'expect.js';
|
||||
import secureOptions from '../secure_options';
|
||||
import crypto from 'crypto';
|
||||
|
||||
const constants = crypto.constants;
|
||||
|
||||
describe('secure_options', function () {
|
||||
it('allows null', function () {
|
||||
expect(secureOptions(null)).to.be(null);
|
||||
});
|
||||
|
||||
it ('allows an empty array', function () {
|
||||
expect(secureOptions([])).to.be(null);
|
||||
});
|
||||
|
||||
it ('removes TLSv1 if we only support TLSv1.1 and TLSv1.2', function () {
|
||||
expect(secureOptions(['TLSv1.1', 'TLSv1.2'])).to.be(constants.SSL_OP_NO_TLSv1);
|
||||
});
|
||||
|
||||
it ('removes TLSv1.1 and TLSv1.2 if we only support TLSv1', function () {
|
||||
expect(secureOptions(['TLSv1'])).to.be(constants.SSL_OP_NO_TLSv1_1 | constants.SSL_OP_NO_TLSv1_2);
|
||||
});
|
||||
|
||||
it ('removes TLSv1 and TLSv1.1 if we only support TLSv1.2', function () {
|
||||
expect(secureOptions(['TLSv1.2'])).to.be(constants.SSL_OP_NO_TLSv1 | constants.SSL_OP_NO_TLSv1_1);
|
||||
});
|
||||
|
||||
});
|
27
src/server/http/secure_options.test.js
Normal file
27
src/server/http/secure_options.test.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
import secureOptions from './secure_options';
|
||||
import crypto from 'crypto';
|
||||
|
||||
const constants = crypto.constants;
|
||||
|
||||
describe('secure_options', function () {
|
||||
it('allows null', function () {
|
||||
expect(secureOptions(null)).toBe(null);
|
||||
});
|
||||
|
||||
it ('allows an empty array', function () {
|
||||
expect(secureOptions([])).toBe(null);
|
||||
});
|
||||
|
||||
it ('removes TLSv1 if we only support TLSv1.1 and TLSv1.2', function () {
|
||||
expect(secureOptions(['TLSv1.1', 'TLSv1.2'])).toBe(constants.SSL_OP_NO_TLSv1);
|
||||
});
|
||||
|
||||
it ('removes TLSv1.1 and TLSv1.2 if we only support TLSv1', function () {
|
||||
expect(secureOptions(['TLSv1'])).toBe(constants.SSL_OP_NO_TLSv1_1 | constants.SSL_OP_NO_TLSv1_2);
|
||||
});
|
||||
|
||||
it ('removes TLSv1 and TLSv1.1 if we only support TLSv1.2', function () {
|
||||
expect(secureOptions(['TLSv1.2'])).toBe(constants.SSL_OP_NO_TLSv1 | constants.SSL_OP_NO_TLSv1_1);
|
||||
});
|
||||
|
||||
});
|
|
@ -1,8 +1,7 @@
|
|||
import { Server } from 'hapi';
|
||||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import { setupBasePathRewrite } from '../setup_base_path_rewrite';
|
||||
import { setupBasePathRewrite } from './setup_base_path_rewrite';
|
||||
|
||||
describe('server / setup_base_path_rewrite', () => {
|
||||
function createServer({ basePath, rewriteBasePath }) {
|
||||
|
@ -40,15 +39,15 @@ describe('server / setup_base_path_rewrite', () => {
|
|||
|
||||
describe('no base path', () => {
|
||||
let server;
|
||||
before(() => server = createServer({ basePath: '', rewriteBasePath: false }));
|
||||
after(() => server = undefined);
|
||||
beforeAll(() => server = createServer({ basePath: '', rewriteBasePath: false }));
|
||||
afterAll(() => server = undefined);
|
||||
|
||||
it('/bar => 404', async () => {
|
||||
const resp = await server.inject({
|
||||
url: '/bar'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(404);
|
||||
expect(resp.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
it('/bar/ => 404', async () => {
|
||||
|
@ -56,7 +55,7 @@ describe('server / setup_base_path_rewrite', () => {
|
|||
url: '/bar/'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(404);
|
||||
expect(resp.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
it('/bar/foo => 404', async () => {
|
||||
|
@ -64,7 +63,7 @@ describe('server / setup_base_path_rewrite', () => {
|
|||
url: '/bar/foo'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(404);
|
||||
expect(resp.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
it('/ => /', async () => {
|
||||
|
@ -72,8 +71,8 @@ describe('server / setup_base_path_rewrite', () => {
|
|||
url: '/'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be('resp:/');
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toBe('resp:/');
|
||||
});
|
||||
|
||||
it('/foo => /foo', async () => {
|
||||
|
@ -81,22 +80,22 @@ describe('server / setup_base_path_rewrite', () => {
|
|||
url: '/foo'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be('resp:/foo');
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toBe('resp:/foo');
|
||||
});
|
||||
});
|
||||
|
||||
describe('base path /bar, rewrite = false', () => {
|
||||
let server;
|
||||
before(() => server = createServer({ basePath: '/bar', rewriteBasePath: false }));
|
||||
after(() => server = undefined);
|
||||
beforeAll(() => server = createServer({ basePath: '/bar', rewriteBasePath: false }));
|
||||
afterAll(() => server = undefined);
|
||||
|
||||
it('/bar => 404', async () => {
|
||||
const resp = await server.inject({
|
||||
url: '/bar'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(404);
|
||||
expect(resp.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
it('/bar/ => 404', async () => {
|
||||
|
@ -104,7 +103,7 @@ describe('server / setup_base_path_rewrite', () => {
|
|||
url: '/bar/'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(404);
|
||||
expect(resp.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
it('/bar/foo => 404', async () => {
|
||||
|
@ -112,7 +111,7 @@ describe('server / setup_base_path_rewrite', () => {
|
|||
url: '/bar/foo'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(404);
|
||||
expect(resp.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
it('/ => /', async () => {
|
||||
|
@ -120,8 +119,8 @@ describe('server / setup_base_path_rewrite', () => {
|
|||
url: '/'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be('resp:/');
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toBe('resp:/');
|
||||
});
|
||||
|
||||
it('/foo => /foo', async () => {
|
||||
|
@ -129,23 +128,23 @@ describe('server / setup_base_path_rewrite', () => {
|
|||
url: '/foo'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be('resp:/foo');
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toBe('resp:/foo');
|
||||
});
|
||||
});
|
||||
|
||||
describe('base path /bar, rewrite = true', () => {
|
||||
let server;
|
||||
before(() => server = createServer({ basePath: '/bar', rewriteBasePath: true }));
|
||||
after(() => server = undefined);
|
||||
beforeAll(() => server = createServer({ basePath: '/bar', rewriteBasePath: true }));
|
||||
afterAll(() => server = undefined);
|
||||
|
||||
it('/bar => /', async () => {
|
||||
const resp = await server.inject({
|
||||
url: '/bar'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be('resp:/');
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toBe('resp:/');
|
||||
});
|
||||
|
||||
it('/bar/ => 404', async () => {
|
||||
|
@ -153,8 +152,8 @@ describe('server / setup_base_path_rewrite', () => {
|
|||
url: '/bar/'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be('resp:/');
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toBe('resp:/');
|
||||
});
|
||||
|
||||
it('/bar/foo => 404', async () => {
|
||||
|
@ -162,8 +161,8 @@ describe('server / setup_base_path_rewrite', () => {
|
|||
url: '/bar/foo'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be('resp:/foo');
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toBe('resp:/foo');
|
||||
});
|
||||
|
||||
it('/ => 404', async () => {
|
||||
|
@ -171,7 +170,7 @@ describe('server / setup_base_path_rewrite', () => {
|
|||
url: '/'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(404);
|
||||
expect(resp.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
it('/foo => 404', async () => {
|
||||
|
@ -179,7 +178,7 @@ describe('server / setup_base_path_rewrite', () => {
|
|||
url: '/foo'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(404);
|
||||
expect(resp.statusCode).toBe(404);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,4 +1,4 @@
|
|||
import { shortUrlAssertValid } from '../short_url_assert_valid';
|
||||
import { shortUrlAssertValid } from './short_url_assert_valid';
|
||||
|
||||
|
||||
describe('shortUrlAssertValid()', () => {
|
|
@ -1,6 +1,5 @@
|
|||
import expect from 'expect.js';
|
||||
import _ from 'lodash';
|
||||
import { handleShortUrlError } from '../short_url_error';
|
||||
import { handleShortUrlError } from './short_url_error';
|
||||
|
||||
function createErrorWithStatus(status) {
|
||||
const error = new Error();
|
||||
|
@ -35,19 +34,19 @@ describe('handleShortUrlError()', () => {
|
|||
|
||||
caughtErrorsWithStatus.forEach((err) => {
|
||||
it(`should handle errors with status of ${err.status}`, function () {
|
||||
expect(_.get(handleShortUrlError(err), 'output.statusCode')).to.be(err.status);
|
||||
expect(_.get(handleShortUrlError(err), 'output.statusCode')).toBe(err.status);
|
||||
});
|
||||
});
|
||||
|
||||
caughtErrorsWithStatusCode.forEach((err) => {
|
||||
it(`should handle errors with statusCode of ${err.statusCode}`, function () {
|
||||
expect(_.get(handleShortUrlError(err), 'output.statusCode')).to.be(err.statusCode);
|
||||
expect(_.get(handleShortUrlError(err), 'output.statusCode')).toBe(err.statusCode);
|
||||
});
|
||||
});
|
||||
|
||||
uncaughtErrors.forEach((err) => {
|
||||
it(`should not handle unknown errors`, function () {
|
||||
expect(_.get(handleShortUrlError(err), 'output.statusCode')).to.be(500);
|
||||
expect(_.get(handleShortUrlError(err), 'output.statusCode')).toBe(500);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,7 +1,6 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import { shortUrlLookupProvider } from '../short_url_lookup';
|
||||
import { SavedObjectsClient } from '../../saved_objects/client';
|
||||
import { shortUrlLookupProvider } from './short_url_lookup';
|
||||
import { SavedObjectsClient } from '../saved_objects/client';
|
||||
|
||||
describe('shortUrlLookupProvider', () => {
|
||||
const ID = 'bf00ad16941fc51420f91a93428b27a0';
|
||||
|
@ -33,7 +32,7 @@ describe('shortUrlLookupProvider', () => {
|
|||
describe('generateUrlId', () => {
|
||||
it('returns the document id', async () => {
|
||||
const id = await shortUrl.generateUrlId(URL, req);
|
||||
expect(id).to.eql(ID);
|
||||
expect(id).toEqual(ID);
|
||||
});
|
||||
|
||||
it('provides correct arguments to savedObjectsClient', async () => {
|
||||
|
@ -42,10 +41,10 @@ describe('shortUrlLookupProvider', () => {
|
|||
sinon.assert.calledOnce(savedObjectsClient.create);
|
||||
const [type, attributes, options] = savedObjectsClient.create.getCall(0).args;
|
||||
|
||||
expect(type).to.eql(TYPE);
|
||||
expect(attributes).to.only.have.keys('url', 'accessCount', 'createDate', 'accessDate');
|
||||
expect(attributes.url).to.eql(URL);
|
||||
expect(options.id).to.eql(ID);
|
||||
expect(type).toEqual(TYPE);
|
||||
expect(Object.keys(attributes).sort()).toEqual(['accessCount', 'accessDate', 'createDate', 'url']);
|
||||
expect(attributes.url).toEqual(URL);
|
||||
expect(options.id).toEqual(ID);
|
||||
});
|
||||
|
||||
it('passes persists attributes', async () => {
|
||||
|
@ -54,16 +53,16 @@ describe('shortUrlLookupProvider', () => {
|
|||
sinon.assert.calledOnce(savedObjectsClient.create);
|
||||
const [type, attributes] = savedObjectsClient.create.getCall(0).args;
|
||||
|
||||
expect(type).to.eql(TYPE);
|
||||
expect(attributes).to.only.have.keys('url', 'accessCount', 'createDate', 'accessDate');
|
||||
expect(attributes.url).to.eql(URL);
|
||||
expect(type).toEqual(TYPE);
|
||||
expect(Object.keys(attributes).sort()).toEqual(['accessCount', 'accessDate', 'createDate', 'url']);
|
||||
expect(attributes.url).toEqual(URL);
|
||||
});
|
||||
|
||||
it('gracefully handles version conflict', async () => {
|
||||
const error = savedObjectsClient.errors.decorateConflictError(new Error());
|
||||
savedObjectsClient.create.throws(error);
|
||||
const id = await shortUrl.generateUrlId(URL, req);
|
||||
expect(id).to.eql(ID);
|
||||
expect(id).toEqual(ID);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -79,13 +78,13 @@ describe('shortUrlLookupProvider', () => {
|
|||
sinon.assert.calledOnce(savedObjectsClient.get);
|
||||
const [type, id] = savedObjectsClient.get.getCall(0).args;
|
||||
|
||||
expect(type).to.eql(TYPE);
|
||||
expect(id).to.eql(ID);
|
||||
expect(type).toEqual(TYPE);
|
||||
expect(id).toEqual(ID);
|
||||
});
|
||||
|
||||
it('returns the url', async () => {
|
||||
const response = await shortUrl.getUrl(ID, req);
|
||||
expect(response).to.eql(URL);
|
||||
expect(response).toEqual(URL);
|
||||
});
|
||||
|
||||
it('increments accessCount', async () => {
|
||||
|
@ -94,10 +93,10 @@ describe('shortUrlLookupProvider', () => {
|
|||
sinon.assert.calledOnce(savedObjectsClient.update);
|
||||
const [type, id, attributes] = savedObjectsClient.update.getCall(0).args;
|
||||
|
||||
expect(type).to.eql(TYPE);
|
||||
expect(id).to.eql(ID);
|
||||
expect(attributes).to.only.have.keys('accessCount', 'accessDate');
|
||||
expect(attributes.accessCount).to.eql(3);
|
||||
expect(type).toEqual(TYPE);
|
||||
expect(id).toEqual(ID);
|
||||
expect(Object.keys(attributes).sort()).toEqual(['accessCount', 'accessDate']);
|
||||
expect(attributes.accessCount).toEqual(3);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,9 +1,8 @@
|
|||
import expect from 'expect.js';
|
||||
import { fromNode } from 'bluebird';
|
||||
import { resolve } from 'path';
|
||||
import * as kbnTestServer from '../../../test_utils/kbn_server';
|
||||
import * as kbnTestServer from '../../test_utils/kbn_server';
|
||||
|
||||
const src = resolve.bind(null, __dirname, '../../../../src');
|
||||
const src = resolve.bind(null, __dirname, '../../../src');
|
||||
|
||||
const versionHeader = 'kbn-version';
|
||||
const version = require(src('../package.json')).version;
|
||||
|
@ -46,8 +45,8 @@ describe('version_check request filter', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be('ok');
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toBe('ok');
|
||||
});
|
||||
|
||||
it('rejects requests with an incorrect version passed in the version header', async function () {
|
||||
|
@ -59,9 +58,9 @@ describe('version_check request filter', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(400);
|
||||
expect(resp.headers).to.have.property(versionHeader, version);
|
||||
expect(resp.payload).to.match(/"Browser client is out of date/);
|
||||
expect(resp.statusCode).toBe(400);
|
||||
expect(resp.headers).toHaveProperty(versionHeader, version);
|
||||
expect(resp.payload).toMatch(/"Browser client is out of date/);
|
||||
});
|
||||
|
||||
it('accepts requests that do not include a version header', async function () {
|
||||
|
@ -70,7 +69,7 @@ describe('version_check request filter', function () {
|
|||
method: 'GET'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be('ok');
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toBe('ok');
|
||||
});
|
||||
});
|
|
@ -1,10 +1,9 @@
|
|||
import expect from 'expect.js';
|
||||
import { fromNode as fn } from 'bluebird';
|
||||
import { resolve } from 'path';
|
||||
import * as kbnTestServer from '../../../test_utils/kbn_server';
|
||||
import * as kbnTestServer from '../../test_utils/kbn_server';
|
||||
|
||||
const destructiveMethods = ['POST', 'PUT', 'DELETE'];
|
||||
const src = resolve.bind(null, __dirname, '../../../../src');
|
||||
const src = resolve.bind(null, __dirname, '../../../src');
|
||||
|
||||
const xsrfHeader = 'kbn-xsrf';
|
||||
const versionHeader = 'kbn-version';
|
||||
|
@ -88,8 +87,8 @@ describe('xsrf request filter', function () {
|
|||
method: 'GET'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be('ok');
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toBe('ok');
|
||||
});
|
||||
|
||||
it('accepts requests with the xsrf header', async function () {
|
||||
|
@ -101,8 +100,8 @@ describe('xsrf request filter', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be('ok');
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toBe('ok');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -113,8 +112,8 @@ describe('xsrf request filter', function () {
|
|||
method: 'HEAD'
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be.empty();
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('accepts requests with the xsrf header', async function () {
|
||||
|
@ -126,8 +125,8 @@ describe('xsrf request filter', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be.empty();
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -142,8 +141,8 @@ describe('xsrf request filter', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be('ok');
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toBe('ok');
|
||||
});
|
||||
|
||||
// this is still valid for existing csrf protection support
|
||||
|
@ -157,8 +156,8 @@ describe('xsrf request filter', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be('ok');
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toBe('ok');
|
||||
});
|
||||
|
||||
it('rejects requests without either an xsrf or version header', async function () {
|
||||
|
@ -167,8 +166,8 @@ describe('xsrf request filter', function () {
|
|||
method: method
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(400);
|
||||
expect(resp.result.message).to.be('Request must contain a kbn-xsrf header.');
|
||||
expect(resp.statusCode).toBe(400);
|
||||
expect(resp.result.message).toBe('Request must contain a kbn-xsrf header.');
|
||||
});
|
||||
|
||||
it('accepts whitelisted requests without either an xsrf or version header', async function () {
|
||||
|
@ -177,8 +176,8 @@ describe('xsrf request filter', function () {
|
|||
method: method
|
||||
});
|
||||
|
||||
expect(resp.statusCode).to.be(200);
|
||||
expect(resp.payload).to.be('ok');
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.payload).toBe('ok');
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
// errors module is tested in test/api_integration/apis/index_patterns/es_errors/errors.js
|
||||
// so it can get real errors from elasticsearch and the es client to test with
|
4
src/server/index_patterns/service/lib/errors.test.js
Normal file
4
src/server/index_patterns/service/lib/errors.test.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
test('test', () => {
|
||||
// errors module is tested in test/api_integration/apis/index_patterns/es_errors/errors.js
|
||||
// so it can get real errors from elasticsearch and the es client to test with
|
||||
});
|
|
@ -1,11 +1,10 @@
|
|||
/* eslint import/no-duplicates: 0 */
|
||||
import sinon from 'sinon';
|
||||
import expect from 'expect.js';
|
||||
|
||||
import { convertEsError } from '../errors';
|
||||
import * as convertEsErrorNS from '../errors';
|
||||
import { convertEsError } from './errors';
|
||||
import * as convertEsErrorNS from './errors';
|
||||
|
||||
import { callIndexAliasApi, callFieldCapsApi } from '../es_api';
|
||||
import { callIndexAliasApi, callFieldCapsApi } from './es_api';
|
||||
|
||||
describe('server/index_patterns/service/lib/es_api', () => {
|
||||
describe('#callIndexAliasApi()', () => {
|
||||
|
@ -25,7 +24,7 @@ describe('server/index_patterns/service/lib/es_api', () => {
|
|||
const callCluster = sinon.stub();
|
||||
await callIndexAliasApi(callCluster, football);
|
||||
sinon.assert.calledOnce(callCluster);
|
||||
expect(callCluster.args[0][1].index).to.be(football);
|
||||
expect(callCluster.args[0][1].index).toBe(football);
|
||||
});
|
||||
|
||||
it('returns the es response directly', async () => {
|
||||
|
@ -33,7 +32,7 @@ describe('server/index_patterns/service/lib/es_api', () => {
|
|||
const callCluster = sinon.stub().returns(football);
|
||||
const resp = await callIndexAliasApi(callCluster);
|
||||
sinon.assert.calledOnce(callCluster);
|
||||
expect(resp).to.be(football);
|
||||
expect(resp).toBe(football);
|
||||
});
|
||||
|
||||
it('sets ignoreUnavailable and allowNoIndices params', async () => {
|
||||
|
@ -42,8 +41,8 @@ describe('server/index_patterns/service/lib/es_api', () => {
|
|||
sinon.assert.calledOnce(callCluster);
|
||||
|
||||
const passedOpts = callCluster.args[0][1];
|
||||
expect(passedOpts).to.have.property('ignoreUnavailable', true);
|
||||
expect(passedOpts).to.have.property('allowNoIndices', false);
|
||||
expect(passedOpts).toHaveProperty('ignoreUnavailable', true);
|
||||
expect(passedOpts).toHaveProperty('allowNoIndices', false);
|
||||
});
|
||||
|
||||
it('handles errors with convertEsError()', async () => {
|
||||
|
@ -57,10 +56,10 @@ describe('server/index_patterns/service/lib/es_api', () => {
|
|||
await callIndexAliasApi(callCluster, indices);
|
||||
throw new Error('expected callIndexAliasApi() to throw');
|
||||
} catch (error) {
|
||||
expect(error).to.be(convertedError);
|
||||
expect(error).toBe(convertedError);
|
||||
sinon.assert.calledOnce(convertEsError);
|
||||
expect(convertEsError.args[0][0]).to.be(indices);
|
||||
expect(convertEsError.args[0][1]).to.be(esError);
|
||||
expect(convertEsError.args[0][0]).toBe(indices);
|
||||
expect(convertEsError.args[0][1]).toBe(esError);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -82,7 +81,7 @@ describe('server/index_patterns/service/lib/es_api', () => {
|
|||
const callCluster = sinon.stub();
|
||||
await callFieldCapsApi(callCluster, football);
|
||||
sinon.assert.calledOnce(callCluster);
|
||||
expect(callCluster.args[0][1].index).to.be(football);
|
||||
expect(callCluster.args[0][1].index).toBe(football);
|
||||
});
|
||||
|
||||
it('returns the es response directly', async () => {
|
||||
|
@ -90,7 +89,7 @@ describe('server/index_patterns/service/lib/es_api', () => {
|
|||
const callCluster = sinon.stub().returns(football);
|
||||
const resp = await callFieldCapsApi(callCluster);
|
||||
sinon.assert.calledOnce(callCluster);
|
||||
expect(resp).to.be(football);
|
||||
expect(resp).toBe(football);
|
||||
});
|
||||
|
||||
it('sets ignoreUnavailable, allowNoIndices, and fields params', async () => {
|
||||
|
@ -99,9 +98,9 @@ describe('server/index_patterns/service/lib/es_api', () => {
|
|||
sinon.assert.calledOnce(callCluster);
|
||||
|
||||
const passedOpts = callCluster.args[0][1];
|
||||
expect(passedOpts).to.have.property('fields', '*');
|
||||
expect(passedOpts).to.have.property('ignoreUnavailable', true);
|
||||
expect(passedOpts).to.have.property('allowNoIndices', false);
|
||||
expect(passedOpts).toHaveProperty('fields', '*');
|
||||
expect(passedOpts).toHaveProperty('ignoreUnavailable', true);
|
||||
expect(passedOpts).toHaveProperty('allowNoIndices', false);
|
||||
});
|
||||
|
||||
it('handles errors with convertEsError()', async () => {
|
||||
|
@ -115,10 +114,10 @@ describe('server/index_patterns/service/lib/es_api', () => {
|
|||
await callFieldCapsApi(callCluster, indices);
|
||||
throw new Error('expected callFieldCapsApi() to throw');
|
||||
} catch (error) {
|
||||
expect(error).to.be(convertedError);
|
||||
expect(error).toBe(convertedError);
|
||||
sinon.assert.calledOnce(convertEsError);
|
||||
expect(convertEsError.args[0][0]).to.be(indices);
|
||||
expect(convertEsError.args[0][1]).to.be(esError);
|
||||
expect(convertEsError.args[0][0]).toBe(indices);
|
||||
expect(convertEsError.args[0][1]).toBe(esError);
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,18 +1,17 @@
|
|||
/* eslint import/no-duplicates: 0 */
|
||||
import sinon from 'sinon';
|
||||
import expect from 'expect.js';
|
||||
import { identity, shuffle, sortBy } from 'lodash';
|
||||
|
||||
import { getFieldCapabilities } from '../field_capabilities';
|
||||
|
||||
import { callFieldCapsApi } from '../../es_api';
|
||||
import * as callFieldCapsApiNS from '../../es_api';
|
||||
import { callFieldCapsApi } from '../es_api';
|
||||
import * as callFieldCapsApiNS from '../es_api';
|
||||
|
||||
import { readFieldCapsResponse } from '../field_caps_response';
|
||||
import * as readFieldCapsResponseNS from '../field_caps_response';
|
||||
import { readFieldCapsResponse } from './field_caps_response';
|
||||
import * as readFieldCapsResponseNS from './field_caps_response';
|
||||
|
||||
import { mergeOverrides } from '../overrides';
|
||||
import * as mergeOverridesNS from '../overrides';
|
||||
import { mergeOverrides } from './overrides';
|
||||
import * as mergeOverridesNS from './overrides';
|
||||
|
||||
describe('index_patterns/field_capabilities/field_capabilities', () => {
|
||||
let sandbox;
|
||||
|
@ -73,7 +72,7 @@ describe('index_patterns/field_capabilities/field_capabilities', () => {
|
|||
});
|
||||
|
||||
const fieldNames = (await getFieldCapabilities()).map(field => field.name);
|
||||
expect(fieldNames).to.eql(sortedLetters);
|
||||
expect(fieldNames).toEqual(sortedLetters);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -87,8 +86,8 @@ describe('index_patterns/field_capabilities/field_capabilities', () => {
|
|||
});
|
||||
|
||||
const resp = await getFieldCapabilities(undefined, undefined, ['meta1', 'meta2']);
|
||||
expect(resp).to.have.length(4);
|
||||
expect(resp.map(field => field.name)).to.eql(['bar', 'foo', 'meta1', 'meta2']);
|
||||
expect(resp).toHaveLength(4);
|
||||
expect(resp.map(field => field.name)).toEqual(['bar', 'foo', 'meta1', 'meta2']);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -120,15 +119,15 @@ describe('index_patterns/field_capabilities/field_capabilities', () => {
|
|||
});
|
||||
|
||||
const resp = await getFieldCapabilities();
|
||||
expect(resp).to.have.length(1);
|
||||
expect(resp[0]).to.have.property(property);
|
||||
expect(resp[0][property]).to.not.be(footballs[0]);
|
||||
expect(resp).toHaveLength(1);
|
||||
expect(resp[0]).toHaveProperty(property);
|
||||
expect(resp[0][property]).not.toBe(footballs[0]);
|
||||
|
||||
// ensure field object was not mutated
|
||||
expect(field).to.not.have.property(property);
|
||||
expect(field).not.toHaveProperty(property);
|
||||
Object.keys(field).forEach(key => {
|
||||
// ensure response field has original values from field
|
||||
expect(resp[0][key]).to.be(footballs[0]);
|
||||
expect(resp[0][key]).toBe(footballs[0]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -149,9 +148,9 @@ describe('index_patterns/field_capabilities/field_capabilities', () => {
|
|||
await getFieldCapabilities();
|
||||
sinon.assert.calledThrice(mergeOverrides);
|
||||
|
||||
expect(mergeOverrides.args[0][0]).to.have.property('name', 'foo');
|
||||
expect(mergeOverrides.args[1][0]).to.have.property('name', 'bar');
|
||||
expect(mergeOverrides.args[2][0]).to.have.property('name', 'baz');
|
||||
expect(mergeOverrides.args[0][0]).toHaveProperty('name', 'foo');
|
||||
expect(mergeOverrides.args[1][0]).toHaveProperty('name', 'bar');
|
||||
expect(mergeOverrides.args[2][0]).toHaveProperty('name', 'baz');
|
||||
});
|
||||
|
||||
it('replaces field with return value', async () => {
|
||||
|
@ -167,7 +166,7 @@ describe('index_patterns/field_capabilities/field_capabilities', () => {
|
|||
}
|
||||
});
|
||||
|
||||
expect(await getFieldCapabilities()).to.eql([
|
||||
expect(await getFieldCapabilities()).toEqual([
|
||||
{ notFieldAnymore: 1 },
|
||||
{ notFieldAnymore: 1 }
|
||||
]);
|
|
@ -1,14 +1,13 @@
|
|||
/* eslint import/no-duplicates: 0 */
|
||||
import { cloneDeep } from 'lodash';
|
||||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import * as shouldReadFieldFromDocValuesNS from '../should_read_field_from_doc_values';
|
||||
import { shouldReadFieldFromDocValues } from '../should_read_field_from_doc_values';
|
||||
import * as shouldReadFieldFromDocValuesNS from './should_read_field_from_doc_values';
|
||||
import { shouldReadFieldFromDocValues } from './should_read_field_from_doc_values';
|
||||
|
||||
import { getKbnFieldType } from '../../../../../../utils';
|
||||
import { readFieldCapsResponse } from '../field_caps_response';
|
||||
import esResponse from './fixtures/es_field_caps_response.json';
|
||||
import { getKbnFieldType } from '../../../../../utils';
|
||||
import { readFieldCapsResponse } from './field_caps_response';
|
||||
import esResponse from './__fixtures__/es_field_caps_response.json';
|
||||
|
||||
describe('index_patterns/field_capabilities/field_caps_response', () => {
|
||||
let sandbox;
|
||||
|
@ -19,7 +18,7 @@ describe('index_patterns/field_capabilities/field_caps_response', () => {
|
|||
describe('conflicts', () => {
|
||||
it('returns a field for each in response, no filtering', () => {
|
||||
const fields = readFieldCapsResponse(esResponse);
|
||||
expect(fields).to.have.length(19);
|
||||
expect(fields).toHaveLength(19);
|
||||
});
|
||||
|
||||
it('includes only name, type, searchable, aggregatable, readFromDocValues, and maybe conflictDescriptions of each field', () => {
|
||||
|
@ -33,7 +32,7 @@ describe('index_patterns/field_capabilities/field_caps_response', () => {
|
|||
delete field.conflictDescriptions;
|
||||
}
|
||||
|
||||
expect(Object.keys(field)).to.eql([
|
||||
expect(Object.keys(field)).toEqual([
|
||||
'name',
|
||||
'type',
|
||||
'searchable',
|
||||
|
@ -61,7 +60,7 @@ describe('index_patterns/field_capabilities/field_caps_response', () => {
|
|||
it('returns fields with multiple types as conflicts', () => {
|
||||
const fields = readFieldCapsResponse(esResponse);
|
||||
const conflicts = fields.filter(f => f.type === 'conflict');
|
||||
expect(conflicts).to.eql([
|
||||
expect(conflicts).toEqual([
|
||||
{
|
||||
name: 'success',
|
||||
type: 'conflict',
|
||||
|
@ -84,24 +83,24 @@ describe('index_patterns/field_capabilities/field_caps_response', () => {
|
|||
const fields = readFieldCapsResponse(esResponse);
|
||||
const resolvableToString = fields.find(f => f.name === 'resolvable_to_string');
|
||||
const resolvableToNumber = fields.find(f => f.name === 'resolvable_to_number');
|
||||
expect(resolvableToString.type).to.be('string');
|
||||
expect(resolvableToNumber.type).to.be('number');
|
||||
expect(resolvableToString.type).toBe('string');
|
||||
expect(resolvableToNumber.type).toBe('number');
|
||||
});
|
||||
|
||||
it('returns aggregatable if at least one field is aggregatable', () => {
|
||||
const fields = readFieldCapsResponse(esResponse);
|
||||
const mixAggregatable = fields.find(f => f.name === 'mix_aggregatable');
|
||||
const mixAggregatableOther = fields.find(f => f.name === 'mix_aggregatable_other');
|
||||
expect(mixAggregatable.aggregatable).to.be(true);
|
||||
expect(mixAggregatableOther.aggregatable).to.be(true);
|
||||
expect(mixAggregatable.aggregatable).toBe(true);
|
||||
expect(mixAggregatableOther.aggregatable).toBe(true);
|
||||
});
|
||||
|
||||
it('returns searchable if at least one field is searchable', () => {
|
||||
const fields = readFieldCapsResponse(esResponse);
|
||||
const mixSearchable = fields.find(f => f.name === 'mix_searchable');
|
||||
const mixSearchableOther = fields.find(f => f.name === 'mix_searchable_other');
|
||||
expect(mixSearchable.searchable).to.be(true);
|
||||
expect(mixSearchableOther.searchable).to.be(true);
|
||||
expect(mixSearchable.searchable).toBe(true);
|
||||
expect(mixSearchableOther.searchable).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,14 +1,13 @@
|
|||
/* eslint import/no-duplicates: 0 */
|
||||
import sinon from 'sinon';
|
||||
import expect from 'expect.js';
|
||||
import { noop } from 'lodash';
|
||||
|
||||
import { callIndexAliasApi } from '../es_api';
|
||||
import * as callIndexAliasApiNS from '../es_api';
|
||||
import { timePatternToWildcard } from '../time_pattern_to_wildcard';
|
||||
import * as timePatternToWildcardNS from '../time_pattern_to_wildcard';
|
||||
import { callIndexAliasApi } from './es_api';
|
||||
import * as callIndexAliasApiNS from './es_api';
|
||||
import { timePatternToWildcard } from './time_pattern_to_wildcard';
|
||||
import * as timePatternToWildcardNS from './time_pattern_to_wildcard';
|
||||
|
||||
import { resolveTimePattern } from '../resolve_time_pattern';
|
||||
import { resolveTimePattern } from './resolve_time_pattern';
|
||||
|
||||
const TIME_PATTERN = '[logs-]dddd-YYYY.w';
|
||||
|
||||
|
@ -34,7 +33,7 @@ describe('server/index_patterns/service/lib/resolve_time_pattern', () => {
|
|||
|
||||
await resolveTimePattern(noop, timePattern);
|
||||
sinon.assert.calledOnce(timePatternToWildcard);
|
||||
expect(timePatternToWildcard.firstCall.args).to.eql([timePattern]);
|
||||
expect(timePatternToWildcard.firstCall.args).toEqual([timePattern]);
|
||||
});
|
||||
|
||||
it('passes the converted wildcard as the index to callIndexAliasApi()', async () => {
|
||||
|
@ -47,7 +46,7 @@ describe('server/index_patterns/service/lib/resolve_time_pattern', () => {
|
|||
|
||||
await resolveTimePattern(noop, timePattern);
|
||||
sinon.assert.calledOnce(callIndexAliasApi);
|
||||
expect(callIndexAliasApi.firstCall.args[1]).to.be(wildcard);
|
||||
expect(callIndexAliasApi.firstCall.args[1]).toBe(wildcard);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -64,8 +63,8 @@ describe('server/index_patterns/service/lib/resolve_time_pattern', () => {
|
|||
});
|
||||
|
||||
const resp = await resolveTimePattern(noop, TIME_PATTERN);
|
||||
expect(resp).to.have.property('all');
|
||||
expect(resp.all).to.eql([
|
||||
expect(resp).toHaveProperty('all');
|
||||
expect(resp.all).toEqual([
|
||||
'logs-Saturday-2017.1',
|
||||
'logs-Friday-2017.1',
|
||||
'logs-Sunday-2017.1',
|
||||
|
@ -88,8 +87,8 @@ describe('server/index_patterns/service/lib/resolve_time_pattern', () => {
|
|||
});
|
||||
|
||||
const resp = await resolveTimePattern(noop, TIME_PATTERN);
|
||||
expect(resp).to.have.property('matches');
|
||||
expect(resp.matches).to.eql([
|
||||
expect(resp).toHaveProperty('matches');
|
||||
expect(resp.matches).toEqual([
|
||||
'logs-Saturday-2017.1',
|
||||
'logs-Friday-2017.1',
|
||||
'logs-Sunday-2017.1'
|
|
@ -1,4 +1,4 @@
|
|||
import { timePatternToWildcard } from '../time_pattern_to_wildcard';
|
||||
import { timePatternToWildcard } from './time_pattern_to_wildcard';
|
||||
|
||||
describe('server/index_patterns/service/lib/time_pattern_to_wildcard', () => {
|
||||
const tests = [
|
|
@ -1,9 +1,8 @@
|
|||
import expect from 'expect.js';
|
||||
import mockFs from 'mock-fs';
|
||||
import sinon from 'sinon';
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
import { Keystore } from '../keystore';
|
||||
import { Keystore } from './keystore';
|
||||
|
||||
describe('Keystore', () => {
|
||||
const sandbox = sinon.sandbox.create();
|
||||
|
@ -35,16 +34,16 @@ describe('Keystore', () => {
|
|||
|
||||
describe('save', () => {
|
||||
it('thows permission denied', () => {
|
||||
expect.assertions(1);
|
||||
const path = '/inaccessible/test.keystore';
|
||||
|
||||
try {
|
||||
const keystore = new Keystore(path);
|
||||
keystore.save();
|
||||
|
||||
expect().fail('should throw error');
|
||||
} catch(e) {
|
||||
expect(e.code).to.eql('EACCES');
|
||||
expect(e.code).toEqual('EACCES');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
it('creates keystore with version', () => {
|
||||
|
@ -57,8 +56,8 @@ describe('Keystore', () => {
|
|||
const contents = fileBuffer.toString();
|
||||
const [version, data] = contents.split(':');
|
||||
|
||||
expect(version).to.eql(1);
|
||||
expect(data.length).to.be.greaterThan(100);
|
||||
expect(version).toEqual('1');
|
||||
expect(data.length).toBeGreaterThan(100);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -68,21 +67,20 @@ describe('Keystore', () => {
|
|||
|
||||
new Keystore('/data/protected.keystore', 'changeme');
|
||||
|
||||
expect(load.calledOnce).to.be(true);
|
||||
expect(load.calledOnce).toBe(true);
|
||||
});
|
||||
|
||||
it('can load a password protected keystore', () => {
|
||||
const keystore = new Keystore('/data/protected.keystore', 'changeme');
|
||||
expect(keystore.data).to.eql({ 'a1.b2.c3': 'foo', 'a2': 'bar' });
|
||||
expect(keystore.data).toEqual({ 'a1.b2.c3': 'foo', 'a2': 'bar' });
|
||||
});
|
||||
|
||||
it('throws unable to read keystore', () => {
|
||||
expect.assertions(1);
|
||||
try {
|
||||
new Keystore('/data/protected.keystore', 'wrongpassword');
|
||||
|
||||
expect().fail('should throw error');
|
||||
} catch(e) {
|
||||
expect(e).to.be.a(Keystore.errors.UnableToReadKeystore);
|
||||
expect(e).toBeInstanceOf(Keystore.errors.UnableToReadKeystore);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -95,7 +93,7 @@ describe('Keystore', () => {
|
|||
it('clears the data', () => {
|
||||
const keystore = new Keystore('/data/protected.keystore', 'changeme');
|
||||
keystore.reset();
|
||||
expect(keystore.data).to.eql([]);
|
||||
expect(keystore.data).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -104,7 +102,7 @@ describe('Keystore', () => {
|
|||
const keystore = new Keystore('/data/unprotected.keystore');
|
||||
const keys = keystore.keys();
|
||||
|
||||
expect(keys).to.eql(['a1.b2.c3', 'a2']);
|
||||
expect(keys).toEqual(['a1.b2.c3', 'a2']);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -112,13 +110,13 @@ describe('Keystore', () => {
|
|||
it('returns true if key exists', () => {
|
||||
const keystore = new Keystore('/data/unprotected.keystore');
|
||||
|
||||
expect(keystore.has('a2')).to.be(true);
|
||||
expect(keystore.has('a2')).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false if key does not exist', () => {
|
||||
const keystore = new Keystore('/data/unprotected.keystore');
|
||||
|
||||
expect(keystore.has('invalid')).to.be(false);
|
||||
expect(keystore.has('invalid')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -127,7 +125,7 @@ describe('Keystore', () => {
|
|||
const keystore = new Keystore('/data/unprotected.keystore');
|
||||
keystore.add('a3', 'baz');
|
||||
|
||||
expect(keystore.data).to.eql({
|
||||
expect(keystore.data).toEqual({
|
||||
'a1.b2.c3': 'foo',
|
||||
'a2': 'bar',
|
||||
'a3': 'baz',
|
||||
|
@ -140,7 +138,7 @@ describe('Keystore', () => {
|
|||
const keystore = new Keystore('/data/unprotected.keystore');
|
||||
keystore.remove('a1.b2.c3');
|
||||
|
||||
expect(keystore.data).to.eql({
|
||||
expect(keystore.data).toEqual({
|
||||
'a2': 'bar',
|
||||
});
|
||||
});
|
||||
|
@ -154,7 +152,7 @@ describe('Keystore', () => {
|
|||
const dataOne = Keystore.encrypt(text, password);
|
||||
const dataTwo = Keystore.encrypt(text, password);
|
||||
|
||||
expect(dataOne).to.not.eql(dataTwo);
|
||||
expect(dataOne).not.toEqual(dataTwo);
|
||||
});
|
||||
|
||||
it('can immediately be decrypted', () => {
|
||||
|
@ -164,7 +162,7 @@ describe('Keystore', () => {
|
|||
const data = Keystore.encrypt(secretText, password);
|
||||
const text = Keystore.decrypt(data, password);
|
||||
|
||||
expect(text).to.eql(secretText);
|
||||
expect(text).toEqual(secretText);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -177,24 +175,24 @@ describe('Keystore', () => {
|
|||
|
||||
it('can decrypt data', () => {
|
||||
const data = Keystore.decrypt(ciphertext, password);
|
||||
expect(data).to.eql(text);
|
||||
expect(data).toEqual(text);
|
||||
});
|
||||
|
||||
it('throws error for invalid password', () => {
|
||||
expect.assertions(1);
|
||||
try {
|
||||
Keystore.decrypt(ciphertext, 'invalid');
|
||||
expect().fail('should throw error');
|
||||
} catch(e) {
|
||||
expect(e).to.be.a(Keystore.errors.UnableToReadKeystore);
|
||||
expect(e).toBeInstanceOf(Keystore.errors.UnableToReadKeystore);
|
||||
}
|
||||
});
|
||||
|
||||
it('throws error for corrupt ciphertext', () => {
|
||||
expect.assertions(1);
|
||||
try {
|
||||
Keystore.decrypt('thisisinvalid', password);
|
||||
expect().fail('should throw error');
|
||||
} catch(e) {
|
||||
expect(e).to.be.a(Keystore.errors.UnableToReadKeystore);
|
||||
expect(e).toBeInstanceOf(Keystore.errors.UnableToReadKeystore);
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,5 +1,4 @@
|
|||
import applyFiltersToKeys from '../apply_filters_to_keys';
|
||||
import expect from 'expect.js';
|
||||
import applyFiltersToKeys from './apply_filters_to_keys';
|
||||
|
||||
describe('applyFiltersToKeys(obj, actionsByKey)', function () {
|
||||
it('applies for each key+prop in actionsByKey', function () {
|
||||
|
@ -23,7 +22,7 @@ describe('applyFiltersToKeys(obj, actionsByKey)', function () {
|
|||
authorization: '/([^\\s]+)$/'
|
||||
});
|
||||
|
||||
expect(data).to.eql({
|
||||
expect(data).toEqual({
|
||||
a: {
|
||||
d: {
|
||||
e: 'XXXXXX',
|
|
@ -1,12 +1,11 @@
|
|||
import moment from 'moment';
|
||||
import expect from 'expect.js';
|
||||
|
||||
import {
|
||||
createListStream,
|
||||
createPromiseFromStreams,
|
||||
} from '../../../utils';
|
||||
} from '../../utils';
|
||||
|
||||
import KbnLoggerJsonFormat from '../log_format_json';
|
||||
import KbnLoggerJsonFormat from './log_format_json';
|
||||
|
||||
const time = +moment('2010-01-01T05:15:59Z', moment.ISO_8601);
|
||||
|
||||
|
@ -31,8 +30,8 @@ describe('KbnLoggerJsonFormat', () => {
|
|||
]);
|
||||
const { type, message } = JSON.parse(result);
|
||||
|
||||
expect(type).to.be('log');
|
||||
expect(message).to.be('undefined');
|
||||
expect(type).toBe('log');
|
||||
expect(message).toBe('undefined');
|
||||
});
|
||||
|
||||
it('response', async () => {
|
||||
|
@ -56,10 +55,10 @@ describe('KbnLoggerJsonFormat', () => {
|
|||
]);
|
||||
const { type, method, statusCode, message } = JSON.parse(result);
|
||||
|
||||
expect(type).to.be('response');
|
||||
expect(method).to.be('GET');
|
||||
expect(statusCode).to.be(200);
|
||||
expect(message).to.be('GET /path/to/resource 200 12000ms - 13.0B');
|
||||
expect(type).toBe('response');
|
||||
expect(method).toBe('GET');
|
||||
expect(statusCode).toBe(200);
|
||||
expect(message).toBe('GET /path/to/resource 200 12000ms - 13.0B');
|
||||
});
|
||||
|
||||
it('ops', async () => {
|
||||
|
@ -75,8 +74,8 @@ describe('KbnLoggerJsonFormat', () => {
|
|||
]);
|
||||
const { type, message } = JSON.parse(result);
|
||||
|
||||
expect(type).to.be('ops');
|
||||
expect(message).to.be('memory: 0.0B uptime: 0:00:00 load: [1.00 1.00 2.00] delay: 0.000');
|
||||
expect(type).toBe('ops');
|
||||
expect(message).toBe('memory: 0.0B uptime: 0:00:00 load: [1.00 1.00 2.00] delay: 0.000');
|
||||
});
|
||||
|
||||
describe('errors', () => {
|
||||
|
@ -93,9 +92,9 @@ describe('KbnLoggerJsonFormat', () => {
|
|||
]);
|
||||
const { level, message, error } = JSON.parse(result);
|
||||
|
||||
expect(level).to.be('error');
|
||||
expect(message).to.be('test error 0');
|
||||
expect(error).to.eql({ message: 'test error 0' });
|
||||
expect(level).toBe('error');
|
||||
expect(message).toBe('test error 0');
|
||||
expect(error).toEqual({ message: 'test error 0' });
|
||||
});
|
||||
|
||||
it('with no message', async () => {
|
||||
|
@ -109,9 +108,9 @@ describe('KbnLoggerJsonFormat', () => {
|
|||
]);
|
||||
const { level, message, error } = JSON.parse(result);
|
||||
|
||||
expect(level).to.be('error');
|
||||
expect(message).to.be('Unknown error (no message)');
|
||||
expect(error).to.eql({});
|
||||
expect(level).toBe('error');
|
||||
expect(message).toBe('Unknown error (no message)');
|
||||
expect(error).toEqual({});
|
||||
});
|
||||
|
||||
it('event data instanceof Error', async () => {
|
||||
|
@ -124,14 +123,14 @@ describe('KbnLoggerJsonFormat', () => {
|
|||
]);
|
||||
const { level, message, error } = JSON.parse(result);
|
||||
|
||||
expect(level).to.be('error');
|
||||
expect(message).to.be('test error 2');
|
||||
expect(level).toBe('error');
|
||||
expect(message).toBe('test error 2');
|
||||
|
||||
expect(error.message).to.be(event.data.message);
|
||||
expect(error.name).to.be(event.data.name);
|
||||
expect(error.stack).to.be(event.data.stack);
|
||||
expect(error.code).to.be(event.data.code);
|
||||
expect(error.signal).to.be(event.data.signal);
|
||||
expect(error.message).toBe(event.data.message);
|
||||
expect(error.name).toBe(event.data.name);
|
||||
expect(error.stack).toBe(event.data.stack);
|
||||
expect(error.code).toBe(event.data.code);
|
||||
expect(error.signal).toBe(event.data.signal);
|
||||
});
|
||||
|
||||
it('event data instanceof Error - fatal', async () => {
|
||||
|
@ -145,15 +144,15 @@ describe('KbnLoggerJsonFormat', () => {
|
|||
]);
|
||||
const { tags, level, message, error } = JSON.parse(result);
|
||||
|
||||
expect(tags).to.eql(['fatal', 'tag2']);
|
||||
expect(level).to.be('fatal');
|
||||
expect(message).to.be('test error 2');
|
||||
expect(tags).toEqual(['fatal', 'tag2']);
|
||||
expect(level).toBe('fatal');
|
||||
expect(message).toBe('test error 2');
|
||||
|
||||
expect(error.message).to.be(event.data.message);
|
||||
expect(error.name).to.be(event.data.name);
|
||||
expect(error.stack).to.be(event.data.stack);
|
||||
expect(error.code).to.be(event.data.code);
|
||||
expect(error.signal).to.be(event.data.signal);
|
||||
expect(error.message).toBe(event.data.message);
|
||||
expect(error.name).toBe(event.data.name);
|
||||
expect(error.stack).toBe(event.data.stack);
|
||||
expect(error.code).toBe(event.data.code);
|
||||
expect(error.signal).toBe(event.data.signal);
|
||||
});
|
||||
|
||||
it('event data instanceof Error, no message', async () => {
|
||||
|
@ -166,14 +165,14 @@ describe('KbnLoggerJsonFormat', () => {
|
|||
]);
|
||||
const { level, message, error } = JSON.parse(result);
|
||||
|
||||
expect(level).to.be('error');
|
||||
expect(message).to.be('Unknown error object (no message)');
|
||||
expect(level).toBe('error');
|
||||
expect(message).toBe('Unknown error object (no message)');
|
||||
|
||||
expect(error.message).to.be(event.data.message);
|
||||
expect(error.name).to.be(event.data.name);
|
||||
expect(error.stack).to.be(event.data.stack);
|
||||
expect(error.code).to.be(event.data.code);
|
||||
expect(error.signal).to.be(event.data.signal);
|
||||
expect(error.message).toBe(event.data.message);
|
||||
expect(error.name).toBe(event.data.name);
|
||||
expect(error.stack).toBe(event.data.stack);
|
||||
expect(error.code).toBe(event.data.code);
|
||||
expect(error.signal).toBe(event.data.signal);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -190,7 +189,7 @@ describe('KbnLoggerJsonFormat', () => {
|
|||
]);
|
||||
|
||||
const { '@timestamp': timestamp } = JSON.parse(result);
|
||||
expect(timestamp).to.be(moment.utc(time).format());
|
||||
expect(timestamp).toBe(moment.utc(time).format());
|
||||
});
|
||||
|
||||
it('logs in local timezone when useUTC is false', async () => {
|
||||
|
@ -204,7 +203,7 @@ describe('KbnLoggerJsonFormat', () => {
|
|||
]);
|
||||
|
||||
const { '@timestamp': timestamp } = JSON.parse(result);
|
||||
expect(timestamp).to.be(moment(time).format());
|
||||
expect(timestamp).toBe(moment(time).format());
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,12 +1,11 @@
|
|||
import moment from 'moment';
|
||||
import expect from 'expect.js';
|
||||
|
||||
import {
|
||||
createListStream,
|
||||
createPromiseFromStreams,
|
||||
} from '../../../utils';
|
||||
} from '../../utils';
|
||||
|
||||
import KbnLoggerStringFormat from '../log_format_string';
|
||||
import KbnLoggerStringFormat from './log_format_string';
|
||||
|
||||
const time = +moment('2010-01-01T05:15:59Z', moment.ISO_8601);
|
||||
|
||||
|
@ -30,7 +29,7 @@ describe('KbnLoggerStringFormat', () => {
|
|||
]);
|
||||
|
||||
expect(String(result))
|
||||
.to.contain(moment.utc(time).format('HH:mm:ss.SSS'));
|
||||
.toContain(moment.utc(time).format('HH:mm:ss.SSS'));
|
||||
});
|
||||
|
||||
it('logs in local timezone when useUTC is false', async () => {
|
||||
|
@ -43,7 +42,7 @@ describe('KbnLoggerStringFormat', () => {
|
|||
format
|
||||
]);
|
||||
|
||||
expect(String(result)).to
|
||||
.contain(moment(time).format('HH:mm:ss.SSS'));
|
||||
expect(String(result))
|
||||
.toContain(moment(time).format('HH:mm:ss.SSS'));
|
||||
});
|
||||
});
|
|
@ -1,6 +1,4 @@
|
|||
import expect from 'expect.js';
|
||||
|
||||
import { LogInterceptor } from '../log_interceptor';
|
||||
import { LogInterceptor } from './log_interceptor';
|
||||
|
||||
function stubClientErrorEvent(errorMeta) {
|
||||
const error = new Error();
|
||||
|
@ -19,10 +17,10 @@ const stubEpipeEvent = () => stubClientErrorEvent({ errno: 'EPIPE' });
|
|||
const stubEcanceledEvent = () => stubClientErrorEvent({ errno: 'ECANCELED' });
|
||||
|
||||
function assertDowngraded(transformed) {
|
||||
expect(!!transformed).to.be(true);
|
||||
expect(transformed).to.have.property('event', 'log');
|
||||
expect(transformed).to.have.property('tags');
|
||||
expect(transformed.tags).to.not.contain('error');
|
||||
expect(!!transformed).toBe(true);
|
||||
expect(transformed).toHaveProperty('event', 'log');
|
||||
expect(transformed).toHaveProperty('tags');
|
||||
expect(transformed.tags).not.toContain('error');
|
||||
}
|
||||
|
||||
describe('server logging LogInterceptor', () => {
|
||||
|
@ -37,20 +35,20 @@ describe('server logging LogInterceptor', () => {
|
|||
const interceptor = new LogInterceptor();
|
||||
const event = stubEconnresetEvent();
|
||||
event.tags = [...event.tags.slice(1), event.tags[0]];
|
||||
expect(interceptor.downgradeIfEconnreset(event)).to.be(null);
|
||||
expect(interceptor.downgradeIfEconnreset(event)).toBe(null);
|
||||
});
|
||||
|
||||
it('ignores non ECONNRESET events', () => {
|
||||
const interceptor = new LogInterceptor();
|
||||
const event = stubClientErrorEvent({ errno: 'not ECONNRESET' });
|
||||
expect(interceptor.downgradeIfEconnreset(event)).to.be(null);
|
||||
expect(interceptor.downgradeIfEconnreset(event)).toBe(null);
|
||||
});
|
||||
|
||||
it('ignores if tags are wrong', () => {
|
||||
const interceptor = new LogInterceptor();
|
||||
const event = stubEconnresetEvent();
|
||||
event.tags = ['different', 'tags'];
|
||||
expect(interceptor.downgradeIfEconnreset(event)).to.be(null);
|
||||
expect(interceptor.downgradeIfEconnreset(event)).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -65,20 +63,20 @@ describe('server logging LogInterceptor', () => {
|
|||
const interceptor = new LogInterceptor();
|
||||
const event = stubEpipeEvent();
|
||||
event.tags = [...event.tags.slice(1), event.tags[0]];
|
||||
expect(interceptor.downgradeIfEpipe(event)).to.be(null);
|
||||
expect(interceptor.downgradeIfEpipe(event)).toBe(null);
|
||||
});
|
||||
|
||||
it('ignores non EPIPE events', () => {
|
||||
const interceptor = new LogInterceptor();
|
||||
const event = stubClientErrorEvent({ errno: 'not EPIPE' });
|
||||
expect(interceptor.downgradeIfEpipe(event)).to.be(null);
|
||||
expect(interceptor.downgradeIfEpipe(event)).toBe(null);
|
||||
});
|
||||
|
||||
it('ignores if tags are wrong', () => {
|
||||
const interceptor = new LogInterceptor();
|
||||
const event = stubEpipeEvent();
|
||||
event.tags = ['different', 'tags'];
|
||||
expect(interceptor.downgradeIfEpipe(event)).to.be(null);
|
||||
expect(interceptor.downgradeIfEpipe(event)).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -93,20 +91,20 @@ describe('server logging LogInterceptor', () => {
|
|||
const interceptor = new LogInterceptor();
|
||||
const event = stubEcanceledEvent();
|
||||
event.tags = [...event.tags.slice(1), event.tags[0]];
|
||||
expect(interceptor.downgradeIfEcanceled(event)).to.be(null);
|
||||
expect(interceptor.downgradeIfEcanceled(event)).toBe(null);
|
||||
});
|
||||
|
||||
it('ignores non ECANCELED events', () => {
|
||||
const interceptor = new LogInterceptor();
|
||||
const event = stubClientErrorEvent({ errno: 'not ECANCELLED' });
|
||||
expect(interceptor.downgradeIfEcanceled(event)).to.be(null);
|
||||
expect(interceptor.downgradeIfEcanceled(event)).toBe(null);
|
||||
});
|
||||
|
||||
it('ignores if tags are wrong', () => {
|
||||
const interceptor = new LogInterceptor();
|
||||
const event = stubEcanceledEvent();
|
||||
event.tags = ['different', 'tags'];
|
||||
expect(interceptor.downgradeIfEcanceled(event)).to.be(null);
|
||||
expect(interceptor.downgradeIfEcanceled(event)).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -120,7 +118,7 @@ describe('server logging LogInterceptor', () => {
|
|||
it('ignores non events', () => {
|
||||
const interceptor = new LogInterceptor();
|
||||
const event = stubClientErrorEvent({ message: 'Parse Error', code: 'NOT_HPE_INVALID_METHOD' });
|
||||
expect(interceptor.downgradeIfEcanceled(event)).to.be(null);
|
||||
expect(interceptor.downgradeIfEcanceled(event)).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -135,7 +133,7 @@ describe('server logging LogInterceptor', () => {
|
|||
it('ignores non events', () => {
|
||||
const interceptor = new LogInterceptor();
|
||||
const event = stubClientErrorEvent({ message: 'Not error' });
|
||||
expect(interceptor.downgradeIfEcanceled(event)).to.be(null);
|
||||
expect(interceptor.downgradeIfEcanceled(event)).toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,8 +1,7 @@
|
|||
import expect from 'expect.js';
|
||||
import Chance from 'chance';
|
||||
|
||||
import { IndexMappings } from '../index_mappings';
|
||||
import { getRootType } from '../lib';
|
||||
import { IndexMappings } from './index_mappings';
|
||||
import { getRootType } from './lib';
|
||||
|
||||
const chance = new Chance();
|
||||
|
||||
|
@ -11,9 +10,9 @@ describe('server/mapping/index_mapping', function () {
|
|||
it('initializes with a default mapping when no args', () => {
|
||||
const mapping = new IndexMappings();
|
||||
const dsl = mapping.getDsl();
|
||||
expect(dsl).to.be.an('object');
|
||||
expect(getRootType(dsl)).to.be.a('string');
|
||||
expect(dsl[getRootType(dsl)]).to.be.an('object');
|
||||
expect(typeof dsl).toBe('object');
|
||||
expect(typeof getRootType(dsl)).toBe('string');
|
||||
expect(typeof dsl[getRootType(dsl)]).toBe('object');
|
||||
});
|
||||
|
||||
it('accepts a default mapping dsl as the only argument', () => {
|
||||
|
@ -24,7 +23,7 @@ describe('server/mapping/index_mapping', function () {
|
|||
}
|
||||
});
|
||||
|
||||
expect(mapping.getDsl()).to.eql({
|
||||
expect(mapping.getDsl()).toEqual({
|
||||
foobar: {
|
||||
dynamic: false,
|
||||
properties: {}
|
||||
|
@ -39,7 +38,7 @@ describe('server/mapping/index_mapping', function () {
|
|||
type: chance.pickone(['string', 'keyword', 'geo_point'])
|
||||
}
|
||||
});
|
||||
}).to.throwException(/non-object/);
|
||||
}).toThrowError(/non-object/);
|
||||
});
|
||||
|
||||
it('throws if root type has no type and no properties', () => {
|
||||
|
@ -47,7 +46,7 @@ describe('server/mapping/index_mapping', function () {
|
|||
new IndexMappings({
|
||||
root: {}
|
||||
});
|
||||
}).to.throwException(/non-object/);
|
||||
}).toThrowError(/non-object/);
|
||||
});
|
||||
|
||||
it('initialized root type with properties object if not set', () => {
|
||||
|
@ -57,7 +56,7 @@ describe('server/mapping/index_mapping', function () {
|
|||
}
|
||||
});
|
||||
|
||||
expect(mapping.getDsl()).to.eql({
|
||||
expect(mapping.getDsl()).toEqual({
|
||||
root: {
|
||||
type: 'object',
|
||||
properties: {}
|
||||
|
@ -84,7 +83,7 @@ describe('server/mapping/index_mapping', function () {
|
|||
];
|
||||
|
||||
const mapping = new IndexMappings(initialMapping, extensions);
|
||||
expect(mapping.getDsl()).to.eql({
|
||||
expect(mapping.getDsl()).toEqual({
|
||||
x: {
|
||||
properties: {
|
||||
y: {
|
||||
|
@ -113,7 +112,7 @@ describe('server/mapping/index_mapping', function () {
|
|||
|
||||
expect(() => {
|
||||
new IndexMappings(initialMapping, extensions);
|
||||
}).to.throwException(/foo/);
|
||||
}).toThrowError(/foo/);
|
||||
});
|
||||
|
||||
it('includes the pluginId from the extension in the error message if defined', () => {
|
||||
|
@ -131,7 +130,7 @@ describe('server/mapping/index_mapping', function () {
|
|||
|
||||
expect(() => {
|
||||
new IndexMappings(initialMapping, extensions);
|
||||
}).to.throwException(/plugin abc123/);
|
||||
}).toThrowError(/plugin abc123/);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -139,7 +138,7 @@ describe('server/mapping/index_mapping', function () {
|
|||
// tests are light because this method is used all over these tests
|
||||
it('returns mapping as es dsl', function () {
|
||||
const mapping = new IndexMappings();
|
||||
expect(mapping.getDsl()).to.be.an('object');
|
||||
expect(typeof mapping.getDsl()).toBe('object');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,68 +0,0 @@
|
|||
import expect from 'expect.js';
|
||||
|
||||
import { getProperty } from '../get_property';
|
||||
|
||||
const MAPPINGS = {
|
||||
rootType: {
|
||||
properties: {
|
||||
foo: {
|
||||
properties: {
|
||||
name: {
|
||||
type: 'text'
|
||||
},
|
||||
description: {
|
||||
type: 'text'
|
||||
}
|
||||
}
|
||||
},
|
||||
bar: {
|
||||
properties: {
|
||||
baz: {
|
||||
type: 'text',
|
||||
fields: {
|
||||
box: {
|
||||
type: 'keyword'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function test(key, mapping) {
|
||||
expect(typeof key === 'string' || Array.isArray(key)).to.be.ok();
|
||||
expect(mapping).to.be.an('object');
|
||||
|
||||
expect(getProperty(MAPPINGS, key)).to.be(mapping);
|
||||
}
|
||||
|
||||
describe('getProperty(mappings, path)', () => {
|
||||
describe('string key', () => {
|
||||
it('finds root properties', () => {
|
||||
test('foo', MAPPINGS.rootType.properties.foo);
|
||||
});
|
||||
it('finds nested properties', () => {
|
||||
test('foo.name', MAPPINGS.rootType.properties.foo.properties.name);
|
||||
test('foo.description', MAPPINGS.rootType.properties.foo.properties.description);
|
||||
test('bar.baz', MAPPINGS.rootType.properties.bar.properties.baz);
|
||||
});
|
||||
it('finds nested multi-fields', () => {
|
||||
test('bar.baz.box', MAPPINGS.rootType.properties.bar.properties.baz.fields.box);
|
||||
});
|
||||
});
|
||||
describe('array of string keys', () => {
|
||||
it('finds root properties', () => {
|
||||
test(['foo'], MAPPINGS.rootType.properties.foo);
|
||||
});
|
||||
it('finds nested properties', () => {
|
||||
test(['foo', 'name'], MAPPINGS.rootType.properties.foo.properties.name);
|
||||
test(['foo', 'description'], MAPPINGS.rootType.properties.foo.properties.description);
|
||||
test(['bar', 'baz'], MAPPINGS.rootType.properties.bar.properties.baz);
|
||||
});
|
||||
it('finds nested multi-fields', () => {
|
||||
test(['bar', 'baz', 'box'], MAPPINGS.rootType.properties.bar.properties.baz.fields.box);
|
||||
});
|
||||
});
|
||||
});
|
66
src/server/mappings/lib/get_property.test.js
Normal file
66
src/server/mappings/lib/get_property.test.js
Normal file
|
@ -0,0 +1,66 @@
|
|||
import { getProperty } from './get_property';
|
||||
|
||||
const MAPPINGS = {
|
||||
rootType: {
|
||||
properties: {
|
||||
foo: {
|
||||
properties: {
|
||||
name: {
|
||||
type: 'text'
|
||||
},
|
||||
description: {
|
||||
type: 'text'
|
||||
}
|
||||
}
|
||||
},
|
||||
bar: {
|
||||
properties: {
|
||||
baz: {
|
||||
type: 'text',
|
||||
fields: {
|
||||
box: {
|
||||
type: 'keyword'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function runTest(key, mapping) {
|
||||
expect(typeof key === 'string' || Array.isArray(key)).toBeTruthy();
|
||||
expect(typeof mapping).toBe('object');
|
||||
|
||||
expect(getProperty(MAPPINGS, key)).toBe(mapping);
|
||||
}
|
||||
|
||||
describe('getProperty(mappings, path)', () => {
|
||||
describe('string key', () => {
|
||||
it('finds root properties', () => {
|
||||
runTest('foo', MAPPINGS.rootType.properties.foo);
|
||||
});
|
||||
it('finds nested properties', () => {
|
||||
runTest('foo.name', MAPPINGS.rootType.properties.foo.properties.name);
|
||||
runTest('foo.description', MAPPINGS.rootType.properties.foo.properties.description);
|
||||
runTest('bar.baz', MAPPINGS.rootType.properties.bar.properties.baz);
|
||||
});
|
||||
it('finds nested multi-fields', () => {
|
||||
runTest('bar.baz.box', MAPPINGS.rootType.properties.bar.properties.baz.fields.box);
|
||||
});
|
||||
});
|
||||
describe('array of string keys', () => {
|
||||
it('finds root properties', () => {
|
||||
runTest(['foo'], MAPPINGS.rootType.properties.foo);
|
||||
});
|
||||
it('finds nested properties', () => {
|
||||
runTest(['foo', 'name'], MAPPINGS.rootType.properties.foo.properties.name);
|
||||
runTest(['foo', 'description'], MAPPINGS.rootType.properties.foo.properties.description);
|
||||
runTest(['bar', 'baz'], MAPPINGS.rootType.properties.bar.properties.baz);
|
||||
});
|
||||
it('finds nested multi-fields', () => {
|
||||
runTest(['bar', 'baz', 'box'], MAPPINGS.rootType.properties.bar.properties.baz.fields.box);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,15 +1,14 @@
|
|||
import expect from 'expect.js';
|
||||
import { getConfig, getData } from '../';
|
||||
import { getConfig, getData } from './';
|
||||
import { accessSync, R_OK } from 'fs';
|
||||
|
||||
describe('Default path finder', function () {
|
||||
it('should find a kibana.yml', () => {
|
||||
const configPath = getConfig();
|
||||
expect(() => accessSync(configPath, R_OK)).to.not.throwError();
|
||||
expect(() => accessSync(configPath, R_OK)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should find a data directory', () => {
|
||||
const dataPath = getData();
|
||||
expect(() => accessSync(dataPath, R_OK)).to.not.throwError();
|
||||
expect(() => accessSync(dataPath, R_OK)).not.toThrow();
|
||||
});
|
||||
});
|
|
@ -1,6 +1,5 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import { callPluginHook } from '../call_plugin_hook';
|
||||
import { callPluginHook } from './call_plugin_hook';
|
||||
|
||||
describe('server/plugins/callPluginHook', () => {
|
||||
it('should call in correct order based on requirements', async () => {
|
||||
|
@ -51,7 +50,7 @@ describe('server/plugins/callPluginHook', () => {
|
|||
await callPluginHook('init', plugins, 'foo', []);
|
||||
throw new Error('expected callPluginHook to throw');
|
||||
} catch (error) {
|
||||
expect(error.message).to.contain('"bar" for plugin "foo"');
|
||||
expect(error.message).toContain('"bar" for plugin "foo"');
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -81,7 +80,7 @@ describe('server/plugins/callPluginHook', () => {
|
|||
await callPluginHook('init', plugins, 'foo', []);
|
||||
throw new Error('expected callPluginHook to throw');
|
||||
} catch (error) {
|
||||
expect(error.message).to.contain('foo -> bar -> baz -> foo');
|
||||
expect(error.message).toContain('foo -> bar -> baz -> foo');
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,91 +0,0 @@
|
|||
import expect from 'expect.js';
|
||||
import { errors as esErrors } from 'elasticsearch';
|
||||
|
||||
import { decorateEsError } from '../decorate_es_error';
|
||||
import {
|
||||
isEsUnavailableError,
|
||||
isConflictError,
|
||||
isNotAuthorizedError,
|
||||
isForbiddenError,
|
||||
isNotFoundError,
|
||||
isBadRequestError,
|
||||
} from '../errors';
|
||||
|
||||
describe('savedObjectsClient/decorateEsError', () => {
|
||||
it('always returns the same error it receives', () => {
|
||||
const error = new Error();
|
||||
expect(decorateEsError(error)).to.be(error);
|
||||
});
|
||||
|
||||
it('makes es.ConnectionFault a SavedObjectsClient/EsUnavailable error', () => {
|
||||
const error = new esErrors.ConnectionFault();
|
||||
expect(isEsUnavailableError(error)).to.be(false);
|
||||
expect(decorateEsError(error)).to.be(error);
|
||||
expect(isEsUnavailableError(error)).to.be(true);
|
||||
});
|
||||
|
||||
it('makes es.ServiceUnavailable a SavedObjectsClient/EsUnavailable error', () => {
|
||||
const error = new esErrors.ServiceUnavailable();
|
||||
expect(isEsUnavailableError(error)).to.be(false);
|
||||
expect(decorateEsError(error)).to.be(error);
|
||||
expect(isEsUnavailableError(error)).to.be(true);
|
||||
});
|
||||
|
||||
it('makes es.NoConnections a SavedObjectsClient/EsUnavailable error', () => {
|
||||
const error = new esErrors.NoConnections();
|
||||
expect(isEsUnavailableError(error)).to.be(false);
|
||||
expect(decorateEsError(error)).to.be(error);
|
||||
expect(isEsUnavailableError(error)).to.be(true);
|
||||
});
|
||||
|
||||
it('makes es.RequestTimeout a SavedObjectsClient/EsUnavailable error', () => {
|
||||
const error = new esErrors.RequestTimeout();
|
||||
expect(isEsUnavailableError(error)).to.be(false);
|
||||
expect(decorateEsError(error)).to.be(error);
|
||||
expect(isEsUnavailableError(error)).to.be(true);
|
||||
});
|
||||
|
||||
it('makes es.Conflict a SavedObjectsClient/Conflict error', () => {
|
||||
const error = new esErrors.Conflict();
|
||||
expect(isConflictError(error)).to.be(false);
|
||||
expect(decorateEsError(error)).to.be(error);
|
||||
expect(isConflictError(error)).to.be(true);
|
||||
});
|
||||
|
||||
it('makes es.AuthenticationException a SavedObjectsClient/NotAuthorized error', () => {
|
||||
const error = new esErrors.AuthenticationException();
|
||||
expect(isNotAuthorizedError(error)).to.be(false);
|
||||
expect(decorateEsError(error)).to.be(error);
|
||||
expect(isNotAuthorizedError(error)).to.be(true);
|
||||
});
|
||||
|
||||
it('makes es.Forbidden a SavedObjectsClient/Forbidden error', () => {
|
||||
const error = new esErrors.Forbidden();
|
||||
expect(isForbiddenError(error)).to.be(false);
|
||||
expect(decorateEsError(error)).to.be(error);
|
||||
expect(isForbiddenError(error)).to.be(true);
|
||||
});
|
||||
|
||||
it('discards es.NotFound errors and returns a generic NotFound error', () => {
|
||||
const error = new esErrors.NotFound();
|
||||
expect(isNotFoundError(error)).to.be(false);
|
||||
const genericError = decorateEsError(error);
|
||||
expect(genericError).to.not.be(error);
|
||||
expect(isNotFoundError(error)).to.be(false);
|
||||
expect(isNotFoundError(genericError)).to.be(true);
|
||||
});
|
||||
|
||||
it('makes es.BadRequest a SavedObjectsClient/BadRequest error', () => {
|
||||
const error = new esErrors.BadRequest();
|
||||
expect(isBadRequestError(error)).to.be(false);
|
||||
expect(decorateEsError(error)).to.be(error);
|
||||
expect(isBadRequestError(error)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns other errors as Boom errors', () => {
|
||||
const error = new Error();
|
||||
expect(error).to.not.have.property('isBoom');
|
||||
expect(decorateEsError(error)).to.be(error);
|
||||
expect(error).to.have.property('isBoom');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,90 @@
|
|||
import { errors as esErrors } from 'elasticsearch';
|
||||
|
||||
import { decorateEsError } from './decorate_es_error';
|
||||
import {
|
||||
isEsUnavailableError,
|
||||
isConflictError,
|
||||
isNotAuthorizedError,
|
||||
isForbiddenError,
|
||||
isNotFoundError,
|
||||
isBadRequestError,
|
||||
} from './errors';
|
||||
|
||||
describe('savedObjectsClient/decorateEsError', () => {
|
||||
it('always returns the same error it receives', () => {
|
||||
const error = new Error();
|
||||
expect(decorateEsError(error)).toBe(error);
|
||||
});
|
||||
|
||||
it('makes es.ConnectionFault a SavedObjectsClient/EsUnavailable error', () => {
|
||||
const error = new esErrors.ConnectionFault();
|
||||
expect(isEsUnavailableError(error)).toBe(false);
|
||||
expect(decorateEsError(error)).toBe(error);
|
||||
expect(isEsUnavailableError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('makes es.ServiceUnavailable a SavedObjectsClient/EsUnavailable error', () => {
|
||||
const error = new esErrors.ServiceUnavailable();
|
||||
expect(isEsUnavailableError(error)).toBe(false);
|
||||
expect(decorateEsError(error)).toBe(error);
|
||||
expect(isEsUnavailableError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('makes es.NoConnections a SavedObjectsClient/EsUnavailable error', () => {
|
||||
const error = new esErrors.NoConnections();
|
||||
expect(isEsUnavailableError(error)).toBe(false);
|
||||
expect(decorateEsError(error)).toBe(error);
|
||||
expect(isEsUnavailableError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('makes es.RequestTimeout a SavedObjectsClient/EsUnavailable error', () => {
|
||||
const error = new esErrors.RequestTimeout();
|
||||
expect(isEsUnavailableError(error)).toBe(false);
|
||||
expect(decorateEsError(error)).toBe(error);
|
||||
expect(isEsUnavailableError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('makes es.Conflict a SavedObjectsClient/Conflict error', () => {
|
||||
const error = new esErrors.Conflict();
|
||||
expect(isConflictError(error)).toBe(false);
|
||||
expect(decorateEsError(error)).toBe(error);
|
||||
expect(isConflictError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('makes es.AuthenticationException a SavedObjectsClient/NotAuthorized error', () => {
|
||||
const error = new esErrors.AuthenticationException();
|
||||
expect(isNotAuthorizedError(error)).toBe(false);
|
||||
expect(decorateEsError(error)).toBe(error);
|
||||
expect(isNotAuthorizedError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('makes es.Forbidden a SavedObjectsClient/Forbidden error', () => {
|
||||
const error = new esErrors.Forbidden();
|
||||
expect(isForbiddenError(error)).toBe(false);
|
||||
expect(decorateEsError(error)).toBe(error);
|
||||
expect(isForbiddenError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('discards es.NotFound errors and returns a generic NotFound error', () => {
|
||||
const error = new esErrors.NotFound();
|
||||
expect(isNotFoundError(error)).toBe(false);
|
||||
const genericError = decorateEsError(error);
|
||||
expect(genericError).not.toBe(error);
|
||||
expect(isNotFoundError(error)).toBe(false);
|
||||
expect(isNotFoundError(genericError)).toBe(true);
|
||||
});
|
||||
|
||||
it('makes es.BadRequest a SavedObjectsClient/BadRequest error', () => {
|
||||
const error = new esErrors.BadRequest();
|
||||
expect(isBadRequestError(error)).toBe(false);
|
||||
expect(decorateEsError(error)).toBe(error);
|
||||
expect(isBadRequestError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns other errors as Boom errors', () => {
|
||||
const error = new Error();
|
||||
expect(error).not.toHaveProperty('isBoom');
|
||||
expect(decorateEsError(error)).toBe(error);
|
||||
expect(error).toHaveProperty('isBoom');
|
||||
});
|
||||
});
|
|
@ -1,4 +1,3 @@
|
|||
import expect from 'expect.js';
|
||||
import Boom from 'boom';
|
||||
|
||||
import {
|
||||
|
@ -17,47 +16,47 @@ import {
|
|||
decorateGeneralError,
|
||||
isEsAutoCreateIndexError,
|
||||
createEsAutoCreateIndexError,
|
||||
} from '../errors';
|
||||
} from './errors';
|
||||
|
||||
describe('savedObjectsClient/errorTypes', () => {
|
||||
describe('BadRequest error', () => {
|
||||
describe('decorateBadRequestError', () => {
|
||||
it('returns original object', () => {
|
||||
const error = new Error();
|
||||
expect(decorateBadRequestError(error)).to.be(error);
|
||||
expect(decorateBadRequestError(error)).toBe(error);
|
||||
});
|
||||
|
||||
it('makes the error identifiable as a BadRequest error', () => {
|
||||
const error = new Error();
|
||||
expect(isBadRequestError(error)).to.be(false);
|
||||
expect(isBadRequestError(error)).toBe(false);
|
||||
decorateBadRequestError(error);
|
||||
expect(isBadRequestError(error)).to.be(true);
|
||||
expect(isBadRequestError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('adds boom properties', () => {
|
||||
const error = decorateBadRequestError(new Error());
|
||||
expect(error.output).to.be.an('object');
|
||||
expect(error.output.statusCode).to.be(400);
|
||||
expect(typeof error.output).toBe('object');
|
||||
expect(error.output.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
it('preserves boom properties of input', () => {
|
||||
const error = Boom.notFound();
|
||||
decorateBadRequestError(error);
|
||||
expect(error.output.statusCode).to.be(404);
|
||||
expect(error.output.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
describe('error.output', () => {
|
||||
it('defaults to message of erorr', () => {
|
||||
const error = decorateBadRequestError(new Error('foobar'));
|
||||
expect(error.output.payload).to.have.property('message', 'foobar');
|
||||
expect(error.output.payload).toHaveProperty('message', 'foobar');
|
||||
});
|
||||
it('prefixes message with passed reason', () => {
|
||||
const error = decorateBadRequestError(new Error('foobar'), 'biz');
|
||||
expect(error.output.payload).to.have.property('message', 'biz: foobar');
|
||||
expect(error.output.payload).toHaveProperty('message', 'biz: foobar');
|
||||
});
|
||||
it('sets statusCode to 400', () => {
|
||||
const error = decorateBadRequestError(new Error('foo'));
|
||||
expect(error.output).to.have.property('statusCode', 400);
|
||||
expect(error.output).toHaveProperty('statusCode', 400);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -66,40 +65,40 @@ describe('savedObjectsClient/errorTypes', () => {
|
|||
describe('decorateNotAuthorizedError', () => {
|
||||
it('returns original object', () => {
|
||||
const error = new Error();
|
||||
expect(decorateNotAuthorizedError(error)).to.be(error);
|
||||
expect(decorateNotAuthorizedError(error)).toBe(error);
|
||||
});
|
||||
|
||||
it('makes the error identifiable as a NotAuthorized error', () => {
|
||||
const error = new Error();
|
||||
expect(isNotAuthorizedError(error)).to.be(false);
|
||||
expect(isNotAuthorizedError(error)).toBe(false);
|
||||
decorateNotAuthorizedError(error);
|
||||
expect(isNotAuthorizedError(error)).to.be(true);
|
||||
expect(isNotAuthorizedError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('adds boom properties', () => {
|
||||
const error = decorateNotAuthorizedError(new Error());
|
||||
expect(error.output).to.be.an('object');
|
||||
expect(error.output.statusCode).to.be(401);
|
||||
expect(typeof error.output).toBe('object');
|
||||
expect(error.output.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
it('preserves boom properties of input', () => {
|
||||
const error = Boom.notFound();
|
||||
decorateNotAuthorizedError(error);
|
||||
expect(error.output.statusCode).to.be(404);
|
||||
expect(error.output.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
describe('error.output', () => {
|
||||
it('defaults to message of erorr', () => {
|
||||
const error = decorateNotAuthorizedError(new Error('foobar'));
|
||||
expect(error.output.payload).to.have.property('message', 'foobar');
|
||||
expect(error.output.payload).toHaveProperty('message', 'foobar');
|
||||
});
|
||||
it('prefixes message with passed reason', () => {
|
||||
const error = decorateNotAuthorizedError(new Error('foobar'), 'biz');
|
||||
expect(error.output.payload).to.have.property('message', 'biz: foobar');
|
||||
expect(error.output.payload).toHaveProperty('message', 'biz: foobar');
|
||||
});
|
||||
it('sets statusCode to 401', () => {
|
||||
const error = decorateNotAuthorizedError(new Error('foo'));
|
||||
expect(error.output).to.have.property('statusCode', 401);
|
||||
expect(error.output).toHaveProperty('statusCode', 401);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -108,40 +107,40 @@ describe('savedObjectsClient/errorTypes', () => {
|
|||
describe('decorateForbiddenError', () => {
|
||||
it('returns original object', () => {
|
||||
const error = new Error();
|
||||
expect(decorateForbiddenError(error)).to.be(error);
|
||||
expect(decorateForbiddenError(error)).toBe(error);
|
||||
});
|
||||
|
||||
it('makes the error identifiable as a Forbidden error', () => {
|
||||
const error = new Error();
|
||||
expect(isForbiddenError(error)).to.be(false);
|
||||
expect(isForbiddenError(error)).toBe(false);
|
||||
decorateForbiddenError(error);
|
||||
expect(isForbiddenError(error)).to.be(true);
|
||||
expect(isForbiddenError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('adds boom properties', () => {
|
||||
const error = decorateForbiddenError(new Error());
|
||||
expect(error.output).to.be.an('object');
|
||||
expect(error.output.statusCode).to.be(403);
|
||||
expect(typeof error.output).toBe('object');
|
||||
expect(error.output.statusCode).toBe(403);
|
||||
});
|
||||
|
||||
it('preserves boom properties of input', () => {
|
||||
const error = Boom.notFound();
|
||||
decorateForbiddenError(error);
|
||||
expect(error.output.statusCode).to.be(404);
|
||||
expect(error.output.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
describe('error.output', () => {
|
||||
it('defaults to message of erorr', () => {
|
||||
const error = decorateForbiddenError(new Error('foobar'));
|
||||
expect(error.output.payload).to.have.property('message', 'foobar');
|
||||
expect(error.output.payload).toHaveProperty('message', 'foobar');
|
||||
});
|
||||
it('prefixes message with passed reason', () => {
|
||||
const error = decorateForbiddenError(new Error('foobar'), 'biz');
|
||||
expect(error.output.payload).to.have.property('message', 'biz: foobar');
|
||||
expect(error.output.payload).toHaveProperty('message', 'biz: foobar');
|
||||
});
|
||||
it('sets statusCode to 403', () => {
|
||||
const error = decorateForbiddenError(new Error('foo'));
|
||||
expect(error.output).to.have.property('statusCode', 403);
|
||||
expect(error.output).toHaveProperty('statusCode', 403);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -150,24 +149,24 @@ describe('savedObjectsClient/errorTypes', () => {
|
|||
describe('createGenericNotFoundError', () => {
|
||||
it('makes an error identifiable as a NotFound error', () => {
|
||||
const error = createGenericNotFoundError();
|
||||
expect(isNotFoundError(error)).to.be(true);
|
||||
expect(isNotFoundError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('is a boom error, has boom properties', () => {
|
||||
const error = createGenericNotFoundError();
|
||||
expect(error).to.have.property('isBoom', true);
|
||||
expect(error.output).to.be.an('object');
|
||||
expect(error.output.statusCode).to.be(404);
|
||||
expect(error).toHaveProperty('isBoom');
|
||||
expect(typeof error.output).toBe('object');
|
||||
expect(error.output.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
describe('error.output', () => {
|
||||
it('Uses "Not Found" message', () => {
|
||||
const error = createGenericNotFoundError();
|
||||
expect(error.output.payload).to.have.property('message', 'Not Found');
|
||||
expect(error.output.payload).toHaveProperty('message', 'Not Found');
|
||||
});
|
||||
it('sets statusCode to 404', () => {
|
||||
const error = createGenericNotFoundError();
|
||||
expect(error.output).to.have.property('statusCode', 404);
|
||||
expect(error.output).toHaveProperty('statusCode', 404);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -176,40 +175,40 @@ describe('savedObjectsClient/errorTypes', () => {
|
|||
describe('decorateConflictError', () => {
|
||||
it('returns original object', () => {
|
||||
const error = new Error();
|
||||
expect(decorateConflictError(error)).to.be(error);
|
||||
expect(decorateConflictError(error)).toBe(error);
|
||||
});
|
||||
|
||||
it('makes the error identifiable as a Conflict error', () => {
|
||||
const error = new Error();
|
||||
expect(isConflictError(error)).to.be(false);
|
||||
expect(isConflictError(error)).toBe(false);
|
||||
decorateConflictError(error);
|
||||
expect(isConflictError(error)).to.be(true);
|
||||
expect(isConflictError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('adds boom properties', () => {
|
||||
const error = decorateConflictError(new Error());
|
||||
expect(error.output).to.be.an('object');
|
||||
expect(error.output.statusCode).to.be(409);
|
||||
expect(typeof error.output).toBe('object');
|
||||
expect(error.output.statusCode).toBe(409);
|
||||
});
|
||||
|
||||
it('preserves boom properties of input', () => {
|
||||
const error = Boom.notFound();
|
||||
decorateConflictError(error);
|
||||
expect(error.output.statusCode).to.be(404);
|
||||
expect(error.output.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
describe('error.output', () => {
|
||||
it('defaults to message of erorr', () => {
|
||||
const error = decorateConflictError(new Error('foobar'));
|
||||
expect(error.output.payload).to.have.property('message', 'foobar');
|
||||
expect(error.output.payload).toHaveProperty('message', 'foobar');
|
||||
});
|
||||
it('prefixes message with passed reason', () => {
|
||||
const error = decorateConflictError(new Error('foobar'), 'biz');
|
||||
expect(error.output.payload).to.have.property('message', 'biz: foobar');
|
||||
expect(error.output.payload).toHaveProperty('message', 'biz: foobar');
|
||||
});
|
||||
it('sets statusCode to 409', () => {
|
||||
const error = decorateConflictError(new Error('foo'));
|
||||
expect(error.output).to.have.property('statusCode', 409);
|
||||
expect(error.output).toHaveProperty('statusCode', 409);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -218,40 +217,40 @@ describe('savedObjectsClient/errorTypes', () => {
|
|||
describe('decorateEsUnavailableError', () => {
|
||||
it('returns original object', () => {
|
||||
const error = new Error();
|
||||
expect(decorateEsUnavailableError(error)).to.be(error);
|
||||
expect(decorateEsUnavailableError(error)).toBe(error);
|
||||
});
|
||||
|
||||
it('makes the error identifiable as a EsUnavailable error', () => {
|
||||
const error = new Error();
|
||||
expect(isEsUnavailableError(error)).to.be(false);
|
||||
expect(isEsUnavailableError(error)).toBe(false);
|
||||
decorateEsUnavailableError(error);
|
||||
expect(isEsUnavailableError(error)).to.be(true);
|
||||
expect(isEsUnavailableError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('adds boom properties', () => {
|
||||
const error = decorateEsUnavailableError(new Error());
|
||||
expect(error.output).to.be.an('object');
|
||||
expect(error.output.statusCode).to.be(503);
|
||||
expect(typeof error.output).toBe('object');
|
||||
expect(error.output.statusCode).toBe(503);
|
||||
});
|
||||
|
||||
it('preserves boom properties of input', () => {
|
||||
const error = Boom.notFound();
|
||||
decorateEsUnavailableError(error);
|
||||
expect(error.output.statusCode).to.be(404);
|
||||
expect(error.output.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
describe('error.output', () => {
|
||||
it('defaults to message of erorr', () => {
|
||||
const error = decorateEsUnavailableError(new Error('foobar'));
|
||||
expect(error.output.payload).to.have.property('message', 'foobar');
|
||||
expect(error.output.payload).toHaveProperty('message', 'foobar');
|
||||
});
|
||||
it('prefixes message with passed reason', () => {
|
||||
const error = decorateEsUnavailableError(new Error('foobar'), 'biz');
|
||||
expect(error.output.payload).to.have.property('message', 'biz: foobar');
|
||||
expect(error.output.payload).toHaveProperty('message', 'biz: foobar');
|
||||
});
|
||||
it('sets statusCode to 503', () => {
|
||||
const error = decorateEsUnavailableError(new Error('foo'));
|
||||
expect(error.output).to.have.property('statusCode', 503);
|
||||
expect(error.output).toHaveProperty('statusCode', 503);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -260,29 +259,29 @@ describe('savedObjectsClient/errorTypes', () => {
|
|||
describe('decorateGeneralError', () => {
|
||||
it('returns original object', () => {
|
||||
const error = new Error();
|
||||
expect(decorateGeneralError(error)).to.be(error);
|
||||
expect(decorateGeneralError(error)).toBe(error);
|
||||
});
|
||||
|
||||
it('adds boom properties', () => {
|
||||
const error = decorateGeneralError(new Error());
|
||||
expect(error.output).to.be.an('object');
|
||||
expect(error.output.statusCode).to.be(500);
|
||||
expect(typeof error.output).toBe('object');
|
||||
expect(error.output.statusCode).toBe(500);
|
||||
});
|
||||
|
||||
it('preserves boom properties of input', () => {
|
||||
const error = Boom.notFound();
|
||||
decorateGeneralError(error);
|
||||
expect(error.output.statusCode).to.be(404);
|
||||
expect(error.output.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
describe('error.output', () => {
|
||||
it('ignores error message', () => {
|
||||
const error = decorateGeneralError(new Error('foobar'));
|
||||
expect(error.output.payload).to.have.property('message').match(/internal server error/i);
|
||||
expect(error.output.payload.message).toMatch(/internal server error/i);
|
||||
});
|
||||
it('sets statusCode to 500', () => {
|
||||
const error = decorateGeneralError(new Error('foo'));
|
||||
expect(error.output).to.have.property('statusCode', 500);
|
||||
expect(error.output).toHaveProperty('statusCode', 500);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -292,32 +291,32 @@ describe('savedObjectsClient/errorTypes', () => {
|
|||
describe('createEsAutoCreateIndexError', () => {
|
||||
it('does not take an error argument', () => {
|
||||
const error = new Error();
|
||||
expect(createEsAutoCreateIndexError(error)).to.not.be(error);
|
||||
expect(createEsAutoCreateIndexError(error)).not.toBe(error);
|
||||
});
|
||||
|
||||
it('returns a new Error', () => {
|
||||
expect(createEsAutoCreateIndexError()).to.be.a(Error);
|
||||
expect(createEsAutoCreateIndexError()).toBeInstanceOf(Error);
|
||||
});
|
||||
|
||||
it('makes errors identifiable as EsAutoCreateIndex errors', () => {
|
||||
expect(isEsAutoCreateIndexError(createEsAutoCreateIndexError())).to.be(true);
|
||||
expect(isEsAutoCreateIndexError(createEsAutoCreateIndexError())).toBe(true);
|
||||
});
|
||||
|
||||
it('returns a boom error', () => {
|
||||
const error = createEsAutoCreateIndexError();
|
||||
expect(error).to.have.property('isBoom', true);
|
||||
expect(error.output).to.be.an('object');
|
||||
expect(error.output.statusCode).to.be(503);
|
||||
expect(error).toHaveProperty('isBoom');
|
||||
expect(typeof error.output).toBe('object');
|
||||
expect(error.output.statusCode).toBe(503);
|
||||
});
|
||||
|
||||
describe('error.output', () => {
|
||||
it('uses "Automatic index creation failed" message', () => {
|
||||
const error = createEsAutoCreateIndexError();
|
||||
expect(error.output.payload).to.have.property('message', 'Automatic index creation failed');
|
||||
expect(error.output.payload).toHaveProperty('message', 'Automatic index creation failed');
|
||||
});
|
||||
it('sets statusCode to 503', () => {
|
||||
const error = createEsAutoCreateIndexError();
|
||||
expect(error.output).to.have.property('statusCode', 503);
|
||||
expect(error.output).toHaveProperty('statusCode', 503);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,44 +1,43 @@
|
|||
import expect from 'expect.js';
|
||||
import { includedFields } from '../included_fields';
|
||||
import { includedFields } from './included_fields';
|
||||
|
||||
describe('includedFields', () => {
|
||||
it('returns undefined if fields are not provided', () => {
|
||||
expect(includedFields()).to.be(undefined);
|
||||
expect(includedFields()).toBe(undefined);
|
||||
});
|
||||
|
||||
it('includes type', () => {
|
||||
const fields = includedFields('config', 'foo');
|
||||
expect(fields).to.have.length(3);
|
||||
expect(fields).to.contain('type');
|
||||
expect(fields).toHaveLength(3);
|
||||
expect(fields).toContain('type');
|
||||
});
|
||||
|
||||
it('accepts field as string', () => {
|
||||
const fields = includedFields('config', 'foo');
|
||||
expect(fields).to.have.length(3);
|
||||
expect(fields).to.contain('config.foo');
|
||||
expect(fields).toHaveLength(3);
|
||||
expect(fields).toContain('config.foo');
|
||||
});
|
||||
|
||||
it('accepts fields as an array', () => {
|
||||
const fields = includedFields('config', ['foo', 'bar']);
|
||||
|
||||
expect(fields).to.have.length(5);
|
||||
expect(fields).to.contain('config.foo');
|
||||
expect(fields).to.contain('config.bar');
|
||||
expect(fields).toHaveLength(5);
|
||||
expect(fields).toContain('config.foo');
|
||||
expect(fields).toContain('config.bar');
|
||||
});
|
||||
|
||||
it('uses wildcard when type is not provided', () => {
|
||||
const fields = includedFields(undefined, 'foo');
|
||||
expect(fields).to.have.length(3);
|
||||
expect(fields).to.contain('*.foo');
|
||||
expect(fields).toHaveLength(3);
|
||||
expect(fields).toContain('*.foo');
|
||||
});
|
||||
|
||||
describe('v5 compatibility', () => {
|
||||
it('includes legacy field path', () => {
|
||||
const fields = includedFields('config', ['foo', 'bar']);
|
||||
|
||||
expect(fields).to.have.length(5);
|
||||
expect(fields).to.contain('foo');
|
||||
expect(fields).to.contain('bar');
|
||||
expect(fields).toHaveLength(5);
|
||||
expect(fields).toContain('foo');
|
||||
expect(fields).toContain('bar');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,6 +1,4 @@
|
|||
import expect from 'expect.js';
|
||||
|
||||
import { getQueryParams } from '../query_params';
|
||||
import { getQueryParams } from './query_params';
|
||||
|
||||
const MAPPINGS = {
|
||||
rootType: {
|
||||
|
@ -42,14 +40,14 @@ describe('searchDsl/queryParams', () => {
|
|||
describe('{}', () => {
|
||||
it('searches for everything', () => {
|
||||
expect(getQueryParams(MAPPINGS))
|
||||
.to.eql({});
|
||||
.toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe('{type}', () => {
|
||||
it('includes just a terms filter', () => {
|
||||
expect(getQueryParams(MAPPINGS, 'saved'))
|
||||
.to.eql({
|
||||
.toEqual({
|
||||
query: {
|
||||
bool: {
|
||||
filter: [
|
||||
|
@ -66,7 +64,7 @@ describe('searchDsl/queryParams', () => {
|
|||
describe('{search}', () => {
|
||||
it('includes just a sqs query', () => {
|
||||
expect(getQueryParams(MAPPINGS, null, 'us*'))
|
||||
.to.eql({
|
||||
.toEqual({
|
||||
query: {
|
||||
bool: {
|
||||
must: [
|
||||
|
@ -86,7 +84,7 @@ describe('searchDsl/queryParams', () => {
|
|||
describe('{type,search}', () => {
|
||||
it('includes bool with sqs query and term filter for type', () => {
|
||||
expect(getQueryParams(MAPPINGS, 'saved', 'y*'))
|
||||
.to.eql({
|
||||
.toEqual({
|
||||
query: {
|
||||
bool: {
|
||||
filter: [
|
||||
|
@ -109,7 +107,7 @@ describe('searchDsl/queryParams', () => {
|
|||
describe('{search,searchFields}', () => {
|
||||
it('includes all types for field', () => {
|
||||
expect(getQueryParams(MAPPINGS, null, 'y*', ['title']))
|
||||
.to.eql({
|
||||
.toEqual({
|
||||
query: {
|
||||
bool: {
|
||||
must: [
|
||||
|
@ -130,7 +128,7 @@ describe('searchDsl/queryParams', () => {
|
|||
});
|
||||
it('supports field boosting', () => {
|
||||
expect(getQueryParams(MAPPINGS, null, 'y*', ['title^3']))
|
||||
.to.eql({
|
||||
.toEqual({
|
||||
query: {
|
||||
bool: {
|
||||
must: [
|
||||
|
@ -151,7 +149,7 @@ describe('searchDsl/queryParams', () => {
|
|||
});
|
||||
it('supports field and multi-field', () => {
|
||||
expect(getQueryParams(MAPPINGS, null, 'y*', ['title', 'title.raw']))
|
||||
.to.eql({
|
||||
.toEqual({
|
||||
query: {
|
||||
bool: {
|
||||
must: [
|
||||
|
@ -178,7 +176,7 @@ describe('searchDsl/queryParams', () => {
|
|||
describe('{type,search,searchFields}', () => {
|
||||
it('includes bool, and sqs with field list', () => {
|
||||
expect(getQueryParams(MAPPINGS, 'saved', 'y*', ['title']))
|
||||
.to.eql({
|
||||
.toEqual({
|
||||
query: {
|
||||
bool: {
|
||||
filter: [
|
||||
|
@ -200,7 +198,7 @@ describe('searchDsl/queryParams', () => {
|
|||
});
|
||||
it('supports fields pointing to multi-fields', () => {
|
||||
expect(getQueryParams(MAPPINGS, 'saved', 'y*', ['title.raw']))
|
||||
.to.eql({
|
||||
.toEqual({
|
||||
query: {
|
||||
bool: {
|
||||
filter: [
|
||||
|
@ -222,7 +220,7 @@ describe('searchDsl/queryParams', () => {
|
|||
});
|
||||
it('supports multiple search fields', () => {
|
||||
expect(getQueryParams(MAPPINGS, 'saved', 'y*', ['title', 'title.raw']))
|
||||
.to.eql({
|
||||
.toEqual({
|
||||
query: {
|
||||
bool: {
|
||||
filter: [
|
|
@ -1,8 +1,7 @@
|
|||
import sinon from 'sinon';
|
||||
import expect from 'expect.js';
|
||||
import { getSearchDsl } from '../search_dsl';
|
||||
import * as queryParamsNS from '../query_params';
|
||||
import * as sortParamsNS from '../sorting_params';
|
||||
import { getSearchDsl } from './search_dsl';
|
||||
import * as queryParamsNS from './query_params';
|
||||
import * as sortParamsNS from './sorting_params';
|
||||
|
||||
describe('getSearchDsl', () => {
|
||||
const sandbox = sinon.sandbox.create();
|
||||
|
@ -15,7 +14,7 @@ describe('getSearchDsl', () => {
|
|||
type: undefined,
|
||||
sortField: 'title'
|
||||
});
|
||||
}).to.throwException(/sort without .+ type/);
|
||||
}).toThrowError(/sort without .+ type/);
|
||||
});
|
||||
it('throws when sortOrder without sortField', () => {
|
||||
expect(() => {
|
||||
|
@ -23,7 +22,7 @@ describe('getSearchDsl', () => {
|
|||
type: 'foo',
|
||||
sortOrder: 'desc'
|
||||
});
|
||||
}).to.throwException(/sortOrder requires a sortField/);
|
||||
}).toThrowError(/sortOrder requires a sortField/);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -71,7 +70,7 @@ describe('getSearchDsl', () => {
|
|||
it('returns combination of getQueryParams and getSortingParams', () => {
|
||||
sandbox.stub(queryParamsNS, 'getQueryParams').returns({ a: 'a' });
|
||||
sandbox.stub(sortParamsNS, 'getSortingParams').returns({ b: 'b' });
|
||||
expect(getSearchDsl({})).to.eql({ a: 'a', b: 'b' });
|
||||
expect(getSearchDsl({})).toEqual({ a: 'a', b: 'b' });
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,6 +1,4 @@
|
|||
import expect from 'expect.js';
|
||||
|
||||
import { getSortingParams } from '../sorting_params';
|
||||
import { getSortingParams } from './sorting_params';
|
||||
|
||||
const MAPPINGS = {
|
||||
rootType: {
|
||||
|
@ -39,21 +37,21 @@ describe('searchDsl/getSortParams', () => {
|
|||
describe('no sortField, type, or order', () => {
|
||||
it('returns no params', () => {
|
||||
expect(getSortingParams(MAPPINGS))
|
||||
.to.eql({});
|
||||
.toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe('type, no sortField', () => {
|
||||
it('returns no params', () => {
|
||||
expect(getSortingParams(MAPPINGS, 'pending'))
|
||||
.to.eql({});
|
||||
.toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe('type, order, no sortField', () => {
|
||||
it('returns no params', () => {
|
||||
expect(getSortingParams(MAPPINGS, 'saved', null, 'desc'))
|
||||
.to.eql({});
|
||||
.toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -61,7 +59,7 @@ describe('searchDsl/getSortParams', () => {
|
|||
describe('search field is simple property', () => {
|
||||
it('returns correct params', () => {
|
||||
expect(getSortingParams(MAPPINGS, 'saved', 'title'))
|
||||
.to.eql({
|
||||
.toEqual({
|
||||
sort: [
|
||||
{
|
||||
'saved.title': {
|
||||
|
@ -76,7 +74,7 @@ describe('searchDsl/getSortParams', () => {
|
|||
describe('search field is multi-field', () => {
|
||||
it('returns correct params', () => {
|
||||
expect(getSortingParams(MAPPINGS, 'saved', 'title.raw'))
|
||||
.to.eql({
|
||||
.toEqual({
|
||||
sort: [
|
||||
{
|
||||
'saved.title.raw': {
|
||||
|
@ -94,7 +92,7 @@ describe('searchDsl/getSortParams', () => {
|
|||
describe('search field is simple property', () => {
|
||||
it('returns correct params', () => {
|
||||
expect(getSortingParams(MAPPINGS, 'saved', 'title', 'desc'))
|
||||
.to.eql({
|
||||
.toEqual({
|
||||
sort: [
|
||||
{
|
||||
'saved.title': {
|
||||
|
@ -109,7 +107,7 @@ describe('searchDsl/getSortParams', () => {
|
|||
describe('search field is multi-field', () => {
|
||||
it('returns correct params', () => {
|
||||
expect(getSortingParams(MAPPINGS, 'saved', 'title.raw', 'asc'))
|
||||
.to.eql({
|
||||
.toEqual({
|
||||
sort: [
|
||||
{
|
||||
'saved.title.raw': {
|
|
@ -1,9 +1,8 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import { delay } from 'bluebird';
|
||||
import { SavedObjectsClient } from '../saved_objects_client';
|
||||
import * as getSearchDslNS from '../lib/search_dsl/search_dsl';
|
||||
import { getSearchDsl } from '../lib';
|
||||
import { SavedObjectsClient } from './saved_objects_client';
|
||||
import * as getSearchDslNS from './lib/search_dsl/search_dsl';
|
||||
import { getSearchDsl } from './lib';
|
||||
import elasticsearch from 'elasticsearch';
|
||||
|
||||
describe('SavedObjectsClient', () => {
|
||||
|
@ -110,7 +109,7 @@ describe('SavedObjectsClient', () => {
|
|||
title: 'Logstash'
|
||||
});
|
||||
|
||||
expect(response).to.eql({
|
||||
expect(response).toEqual({
|
||||
type: 'index-pattern',
|
||||
id: 'logstash-*',
|
||||
...mockTimestampFields,
|
||||
|
@ -249,7 +248,7 @@ describe('SavedObjectsClient', () => {
|
|||
{ type: 'index-pattern', id: 'two', attributes: { title: 'Test Two' } }
|
||||
]);
|
||||
|
||||
expect(response).to.eql([
|
||||
expect(response).toEqual([
|
||||
{
|
||||
id: 'one',
|
||||
type: 'config',
|
||||
|
@ -287,7 +286,7 @@ describe('SavedObjectsClient', () => {
|
|||
{ type: 'index-pattern', id: 'two', attributes: { title: 'Test Two' } }
|
||||
]);
|
||||
|
||||
expect(response).to.eql([
|
||||
expect(response).toEqual([
|
||||
{
|
||||
id: 'one',
|
||||
type: 'config',
|
||||
|
@ -307,18 +306,17 @@ describe('SavedObjectsClient', () => {
|
|||
|
||||
describe('#delete', () => {
|
||||
it('throws notFound when ES is unable to find the document', async () => {
|
||||
expect.assertions(1);
|
||||
|
||||
callAdminCluster.returns(Promise.resolve({
|
||||
result: 'not_found'
|
||||
}));
|
||||
|
||||
try {
|
||||
await savedObjectsClient.delete('index-pattern', 'logstash-*');
|
||||
sinon.assert.calledOnce(onBeforeWrite);
|
||||
expect().fail('should throw error');
|
||||
} catch(e) {
|
||||
expect(e.output.statusCode).to.eql(404);
|
||||
expect(e.output.statusCode).toEqual(404);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
it('passes the parameters to callAdminCluster', async () => {
|
||||
|
@ -352,7 +350,7 @@ describe('SavedObjectsClient', () => {
|
|||
} catch (error) {
|
||||
sinon.assert.notCalled(callAdminCluster);
|
||||
sinon.assert.notCalled(onBeforeWrite);
|
||||
expect(error).to.have.property('message').contain('must be an array');
|
||||
expect(error.message).toMatch('must be an array');
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -363,7 +361,7 @@ describe('SavedObjectsClient', () => {
|
|||
} catch (error) {
|
||||
sinon.assert.notCalled(callAdminCluster);
|
||||
sinon.assert.notCalled(onBeforeWrite);
|
||||
expect(error).to.have.property('message').contain('must be an array');
|
||||
expect(error.message).toMatch('must be an array');
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -399,11 +397,11 @@ describe('SavedObjectsClient', () => {
|
|||
|
||||
const response = await savedObjectsClient.find();
|
||||
|
||||
expect(response.total).to.be(count);
|
||||
expect(response.saved_objects).to.have.length(count);
|
||||
expect(response.total).toBe(count);
|
||||
expect(response.saved_objects).toHaveLength(count);
|
||||
|
||||
searchResults.hits.hits.forEach((doc, i) => {
|
||||
expect(response.saved_objects[i]).to.eql({
|
||||
expect(response.saved_objects[i]).toEqual({
|
||||
id: doc._id.replace(/(index-pattern|config)\:/, ''),
|
||||
type: doc._source.type,
|
||||
...mockTimestampFields,
|
||||
|
@ -458,7 +456,7 @@ describe('SavedObjectsClient', () => {
|
|||
it('formats Elasticsearch response', async () => {
|
||||
const response = await savedObjectsClient.get('index-pattern', 'logstash-*');
|
||||
sinon.assert.notCalled(onBeforeWrite);
|
||||
expect(response).to.eql({
|
||||
expect(response).toEqual({
|
||||
id: 'logstash-*',
|
||||
type: 'index-pattern',
|
||||
updated_at: mockTimestamp,
|
||||
|
@ -508,7 +506,7 @@ describe('SavedObjectsClient', () => {
|
|||
|
||||
const response = await savedObjectsClient.bulkGet([]);
|
||||
|
||||
expect(response.saved_objects).to.have.length(0);
|
||||
expect(response.saved_objects).toHaveLength(0);
|
||||
sinon.assert.notCalled(callAdminCluster);
|
||||
sinon.assert.notCalled(onBeforeWrite);
|
||||
});
|
||||
|
@ -535,15 +533,15 @@ describe('SavedObjectsClient', () => {
|
|||
sinon.assert.notCalled(onBeforeWrite);
|
||||
sinon.assert.calledOnce(callAdminCluster);
|
||||
|
||||
expect(savedObjects).to.have.length(2);
|
||||
expect(savedObjects[0]).to.eql({
|
||||
expect(savedObjects).toHaveLength(2);
|
||||
expect(savedObjects[0]).toEqual({
|
||||
id: 'good',
|
||||
type: 'config',
|
||||
...mockTimestampFields,
|
||||
version: 2,
|
||||
attributes: { title: 'Test' }
|
||||
});
|
||||
expect(savedObjects[1]).to.eql({
|
||||
expect(savedObjects[1]).toEqual({
|
||||
id: 'bad',
|
||||
type: 'config',
|
||||
error: { statusCode: 404, message: 'Not found' }
|
||||
|
@ -568,7 +566,7 @@ describe('SavedObjectsClient', () => {
|
|||
|
||||
it('returns current ES document version', async () => {
|
||||
const response = await savedObjectsClient.update('index-pattern', 'logstash-*', attributes);
|
||||
expect(response).to.eql({
|
||||
expect(response).toEqual({
|
||||
id,
|
||||
type,
|
||||
...mockTimestampFields,
|
||||
|
@ -626,17 +624,18 @@ describe('SavedObjectsClient', () => {
|
|||
});
|
||||
|
||||
it('can throw es errors and have them decorated as SavedObjectsClient errors', async () => {
|
||||
expect.assertions(3);
|
||||
|
||||
const es401 = new elasticsearch.errors[401];
|
||||
expect(SavedObjectsClient.errors.isNotAuthorizedError(es401)).to.be(false);
|
||||
expect(SavedObjectsClient.errors.isNotAuthorizedError(es401)).toBe(false);
|
||||
onBeforeWrite.throws(es401);
|
||||
|
||||
try {
|
||||
await savedObjectsClient.delete('type', 'id');
|
||||
throw new Error('expected savedObjectsClient.delete() to reject');
|
||||
} catch (error) {
|
||||
sinon.assert.calledOnce(onBeforeWrite);
|
||||
expect(error).to.be(es401);
|
||||
expect(SavedObjectsClient.errors.isNotAuthorizedError(error)).to.be(true);
|
||||
expect(error).toBe(es401);
|
||||
expect(SavedObjectsClient.errors.isNotAuthorizedError(error)).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,7 +1,6 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import { createBulkGetRoute } from '../bulk_get';
|
||||
import { MockServer } from './mock_server';
|
||||
import { createBulkGetRoute } from './bulk_get';
|
||||
import { MockServer } from './_mock_server';
|
||||
|
||||
describe('POST /api/saved_objects/bulk_get', () => {
|
||||
const savedObjectsClient = { bulkGet: sinon.stub() };
|
||||
|
@ -50,8 +49,8 @@ describe('POST /api/saved_objects/bulk_get', () => {
|
|||
const { payload, statusCode } = await server.inject(request);
|
||||
const response = JSON.parse(payload);
|
||||
|
||||
expect(statusCode).to.be(200);
|
||||
expect(response).to.eql(clientResponse);
|
||||
expect(statusCode).toBe(200);
|
||||
expect(response).toEqual(clientResponse);
|
||||
});
|
||||
|
||||
it('calls upon savedObjectClient.bulkGet', async () => {
|
||||
|
@ -67,10 +66,10 @@ describe('POST /api/saved_objects/bulk_get', () => {
|
|||
};
|
||||
|
||||
await server.inject(request);
|
||||
expect(savedObjectsClient.bulkGet.calledOnce).to.be(true);
|
||||
expect(savedObjectsClient.bulkGet.calledOnce).toBe(true);
|
||||
|
||||
const args = savedObjectsClient.bulkGet.getCall(0).args;
|
||||
expect(args[0]).to.eql(docs);
|
||||
expect(args[0]).toEqual(docs);
|
||||
});
|
||||
|
||||
});
|
|
@ -1,7 +1,6 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import { createCreateRoute } from '../create';
|
||||
import { MockServer } from './mock_server';
|
||||
import { createCreateRoute } from './create';
|
||||
import { MockServer } from './_mock_server';
|
||||
|
||||
describe('POST /api/saved_objects/{type}', () => {
|
||||
const savedObjectsClient = { create: sinon.stub() };
|
||||
|
@ -47,8 +46,8 @@ describe('POST /api/saved_objects/{type}', () => {
|
|||
const { payload, statusCode } = await server.inject(request);
|
||||
const response = JSON.parse(payload);
|
||||
|
||||
expect(statusCode).to.be(200);
|
||||
expect(response).to.eql(clientResponse);
|
||||
expect(statusCode).toBe(200);
|
||||
expect(response).toEqual(clientResponse);
|
||||
});
|
||||
|
||||
it('requires attributes', async () => {
|
||||
|
@ -61,10 +60,10 @@ describe('POST /api/saved_objects/{type}', () => {
|
|||
const { statusCode, payload } = await server.inject(request);
|
||||
const response = JSON.parse(payload);
|
||||
|
||||
expect(response.validation.keys).to.contain('attributes');
|
||||
expect(response.message).to.match(/is required/);
|
||||
expect(response.statusCode).to.be(400);
|
||||
expect(statusCode).to.be(400);
|
||||
expect(response.validation.keys).toContain('attributes');
|
||||
expect(response.message).toMatch(/is required/);
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(statusCode).toBe(400);
|
||||
});
|
||||
|
||||
it('calls upon savedObjectClient.create', async () => {
|
||||
|
@ -79,13 +78,13 @@ describe('POST /api/saved_objects/{type}', () => {
|
|||
};
|
||||
|
||||
await server.inject(request);
|
||||
expect(savedObjectsClient.create.calledOnce).to.be(true);
|
||||
expect(savedObjectsClient.create.calledOnce).toBe(true);
|
||||
|
||||
const args = savedObjectsClient.create.getCall(0).args;
|
||||
const options = { overwrite: false, id: undefined };
|
||||
const attributes = { title: 'Testing' };
|
||||
|
||||
expect(args).to.eql(['index-pattern', attributes, options]);
|
||||
expect(args).toEqual(['index-pattern', attributes, options]);
|
||||
});
|
||||
|
||||
it('can specify an id', async () => {
|
||||
|
@ -100,12 +99,12 @@ describe('POST /api/saved_objects/{type}', () => {
|
|||
};
|
||||
|
||||
await server.inject(request);
|
||||
expect(savedObjectsClient.create.calledOnce).to.be(true);
|
||||
expect(savedObjectsClient.create.calledOnce).toBe(true);
|
||||
|
||||
const args = savedObjectsClient.create.getCall(0).args;
|
||||
const options = { overwrite: false, id: 'logstash-*' };
|
||||
const attributes = { title: 'Testing' };
|
||||
|
||||
expect(args).to.eql(['index-pattern', attributes, options]);
|
||||
expect(args).toEqual(['index-pattern', attributes, options]);
|
||||
});
|
||||
});
|
|
@ -1,7 +1,6 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import { createDeleteRoute } from '../delete';
|
||||
import { MockServer } from './mock_server';
|
||||
import { createDeleteRoute } from './delete';
|
||||
import { MockServer } from './_mock_server';
|
||||
|
||||
describe('DELETE /api/saved_objects/{type}/{id}', () => {
|
||||
const savedObjectsClient = { delete: sinon.stub() };
|
||||
|
@ -38,8 +37,8 @@ describe('DELETE /api/saved_objects/{type}/{id}', () => {
|
|||
const { payload, statusCode } = await server.inject(request);
|
||||
const response = JSON.parse(payload);
|
||||
|
||||
expect(statusCode).to.be(200);
|
||||
expect(response).to.eql(clientResponse);
|
||||
expect(statusCode).toBe(200);
|
||||
expect(response).toEqual(clientResponse);
|
||||
});
|
||||
|
||||
it('calls upon savedObjectClient.delete', async () => {
|
||||
|
@ -49,9 +48,9 @@ describe('DELETE /api/saved_objects/{type}/{id}', () => {
|
|||
};
|
||||
|
||||
await server.inject(request);
|
||||
expect(savedObjectsClient.delete.calledOnce).to.be(true);
|
||||
expect(savedObjectsClient.delete.calledOnce).toBe(true);
|
||||
|
||||
const args = savedObjectsClient.delete.getCall(0).args;
|
||||
expect(args).to.eql(['index-pattern', 'logstash-*']);
|
||||
expect(args).toEqual(['index-pattern', 'logstash-*']);
|
||||
});
|
||||
});
|
|
@ -1,7 +1,6 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import { createFindRoute } from '../find';
|
||||
import { MockServer } from './mock_server';
|
||||
import { createFindRoute } from './find';
|
||||
import { MockServer } from './_mock_server';
|
||||
|
||||
describe('GET /api/saved_objects/{type?}', () => {
|
||||
const savedObjectsClient = { find: sinon.stub() };
|
||||
|
@ -56,8 +55,8 @@ describe('GET /api/saved_objects/{type?}', () => {
|
|||
const { payload, statusCode } = await server.inject(request);
|
||||
const response = JSON.parse(payload);
|
||||
|
||||
expect(statusCode).to.be(200);
|
||||
expect(response).to.eql(clientResponse);
|
||||
expect(statusCode).toBe(200);
|
||||
expect(response).toEqual(clientResponse);
|
||||
});
|
||||
|
||||
it('calls upon savedObjectClient.find with defaults', async () => {
|
||||
|
@ -68,10 +67,10 @@ describe('GET /api/saved_objects/{type?}', () => {
|
|||
|
||||
await server.inject(request);
|
||||
|
||||
expect(savedObjectsClient.find.calledOnce).to.be(true);
|
||||
expect(savedObjectsClient.find.calledOnce).toBe(true);
|
||||
|
||||
const options = savedObjectsClient.find.getCall(0).args[0];
|
||||
expect(options).to.eql({ perPage: 20, page: 1 });
|
||||
expect(options).toEqual({ perPage: 20, page: 1 });
|
||||
});
|
||||
|
||||
it('accepts the query parameter page/per_page', async () => {
|
||||
|
@ -82,10 +81,10 @@ describe('GET /api/saved_objects/{type?}', () => {
|
|||
|
||||
await server.inject(request);
|
||||
|
||||
expect(savedObjectsClient.find.calledOnce).to.be(true);
|
||||
expect(savedObjectsClient.find.calledOnce).toBe(true);
|
||||
|
||||
const options = savedObjectsClient.find.getCall(0).args[0];
|
||||
expect(options).to.eql({ perPage: 10, page: 50 });
|
||||
expect(options).toEqual({ perPage: 10, page: 50 });
|
||||
});
|
||||
|
||||
it('accepts the query parameter search_fields', async () => {
|
||||
|
@ -96,10 +95,10 @@ describe('GET /api/saved_objects/{type?}', () => {
|
|||
|
||||
await server.inject(request);
|
||||
|
||||
expect(savedObjectsClient.find.calledOnce).to.be(true);
|
||||
expect(savedObjectsClient.find.calledOnce).toBe(true);
|
||||
|
||||
const options = savedObjectsClient.find.getCall(0).args[0];
|
||||
expect(options).to.eql({ perPage: 20, page: 1, searchFields: ['title'] });
|
||||
expect(options).toEqual({ perPage: 20, page: 1, searchFields: ['title'] });
|
||||
});
|
||||
|
||||
it('accepts the query parameter fields as a string', async () => {
|
||||
|
@ -110,10 +109,10 @@ describe('GET /api/saved_objects/{type?}', () => {
|
|||
|
||||
await server.inject(request);
|
||||
|
||||
expect(savedObjectsClient.find.calledOnce).to.be(true);
|
||||
expect(savedObjectsClient.find.calledOnce).toBe(true);
|
||||
|
||||
const options = savedObjectsClient.find.getCall(0).args[0];
|
||||
expect(options).to.eql({ perPage: 20, page: 1, fields: ['title'] });
|
||||
expect(options).toEqual({ perPage: 20, page: 1, fields: ['title'] });
|
||||
});
|
||||
|
||||
it('accepts the query parameter fields as an array', async () => {
|
||||
|
@ -124,10 +123,10 @@ describe('GET /api/saved_objects/{type?}', () => {
|
|||
|
||||
await server.inject(request);
|
||||
|
||||
expect(savedObjectsClient.find.calledOnce).to.be(true);
|
||||
expect(savedObjectsClient.find.calledOnce).toBe(true);
|
||||
|
||||
const options = savedObjectsClient.find.getCall(0).args[0];
|
||||
expect(options).to.eql({
|
||||
expect(options).toEqual({
|
||||
perPage: 20, page: 1, fields: ['title', 'description']
|
||||
});
|
||||
});
|
||||
|
@ -140,10 +139,10 @@ describe('GET /api/saved_objects/{type?}', () => {
|
|||
|
||||
await server.inject(request);
|
||||
|
||||
expect(savedObjectsClient.find.calledOnce).to.be(true);
|
||||
expect(savedObjectsClient.find.calledOnce).toBe(true);
|
||||
|
||||
const options = savedObjectsClient.find.getCall(0).args[0];
|
||||
expect(options).to.eql({ perPage: 20, page: 1, type: 'index-pattern' });
|
||||
expect(options).toEqual({ perPage: 20, page: 1, type: 'index-pattern' });
|
||||
});
|
||||
|
||||
it('accepts the type as a URL parameter', async () => {
|
||||
|
@ -154,9 +153,9 @@ describe('GET /api/saved_objects/{type?}', () => {
|
|||
|
||||
await server.inject(request);
|
||||
|
||||
expect(savedObjectsClient.find.calledOnce).to.be(true);
|
||||
expect(savedObjectsClient.find.calledOnce).toBe(true);
|
||||
|
||||
const options = savedObjectsClient.find.getCall(0).args[0];
|
||||
expect(options).to.eql({ perPage: 20, page: 1, type: 'index-pattern' });
|
||||
expect(options).toEqual({ perPage: 20, page: 1, type: 'index-pattern' });
|
||||
});
|
||||
});
|
|
@ -1,7 +1,6 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import { createGetRoute } from '../get';
|
||||
import { MockServer } from './mock_server';
|
||||
import { createGetRoute } from './get';
|
||||
import { MockServer } from './_mock_server';
|
||||
|
||||
describe('GET /api/saved_objects/{type}/{id}', () => {
|
||||
const savedObjectsClient = { get: sinon.stub() };
|
||||
|
@ -43,8 +42,8 @@ describe('GET /api/saved_objects/{type}/{id}', () => {
|
|||
const { payload, statusCode } = await server.inject(request);
|
||||
const response = JSON.parse(payload);
|
||||
|
||||
expect(statusCode).to.be(200);
|
||||
expect(response).to.eql(clientResponse);
|
||||
expect(statusCode).toBe(200);
|
||||
expect(response).toEqual(clientResponse);
|
||||
});
|
||||
|
||||
it('calls upon savedObjectClient.get', async () => {
|
||||
|
@ -54,10 +53,10 @@ describe('GET /api/saved_objects/{type}/{id}', () => {
|
|||
};
|
||||
|
||||
await server.inject(request);
|
||||
expect(savedObjectsClient.get.calledOnce).to.be(true);
|
||||
expect(savedObjectsClient.get.calledOnce).toBe(true);
|
||||
|
||||
const args = savedObjectsClient.get.getCall(0).args;
|
||||
expect(args).to.eql(['index-pattern', 'logstash-*']);
|
||||
expect(args).toEqual(['index-pattern', 'logstash-*']);
|
||||
});
|
||||
|
||||
});
|
|
@ -1,7 +1,6 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import { createUpdateRoute } from '../update';
|
||||
import { MockServer } from './mock_server';
|
||||
import { createUpdateRoute } from './update';
|
||||
import { MockServer } from './_mock_server';
|
||||
|
||||
describe('PUT /api/saved_objects/{type}/{id?}', () => {
|
||||
const savedObjectsClient = { update: sinon.stub() };
|
||||
|
@ -42,8 +41,8 @@ describe('PUT /api/saved_objects/{type}/{id?}', () => {
|
|||
const { payload, statusCode } = await server.inject(request);
|
||||
const response = JSON.parse(payload);
|
||||
|
||||
expect(statusCode).to.be(200);
|
||||
expect(response).to.eql(true);
|
||||
expect(statusCode).toBe(200);
|
||||
expect(response).toEqual(true);
|
||||
});
|
||||
|
||||
it('calls upon savedObjectClient.update', async () => {
|
||||
|
@ -59,9 +58,9 @@ describe('PUT /api/saved_objects/{type}/{id?}', () => {
|
|||
};
|
||||
|
||||
await server.inject(request);
|
||||
expect(savedObjectsClient.update.calledOnce).to.be(true);
|
||||
expect(savedObjectsClient.update.calledOnce).toBe(true);
|
||||
|
||||
const args = savedObjectsClient.update.getCall(0).args;
|
||||
expect(args).to.eql(['index-pattern', 'logstash-*', attributes, options]);
|
||||
expect(args).toEqual(['index-pattern', 'logstash-*', attributes, options]);
|
||||
});
|
||||
});
|
|
@ -1,7 +1,6 @@
|
|||
import sinon from 'sinon';
|
||||
import expect from 'expect.js';
|
||||
|
||||
import { serverExtensionsMixin } from '../server_extensions_mixin';
|
||||
import { serverExtensionsMixin } from './server_extensions_mixin';
|
||||
|
||||
describe('server.addMemoizedFactoryToRequest()', () => {
|
||||
const setup = () => {
|
||||
|
@ -27,47 +26,46 @@ describe('server.addMemoizedFactoryToRequest()', () => {
|
|||
|
||||
it('throws when propertyName is not a string', () => {
|
||||
const { server } = setup();
|
||||
expect(() => server.addMemoizedFactoryToRequest()).to.throwError('propertyName must be a string');
|
||||
expect(() => server.addMemoizedFactoryToRequest(null)).to.throwError('propertyName must be a string');
|
||||
expect(() => server.addMemoizedFactoryToRequest(1)).to.throwError('propertyName must be a string');
|
||||
expect(() => server.addMemoizedFactoryToRequest(true)).to.throwError('propertyName must be a string');
|
||||
expect(() => server.addMemoizedFactoryToRequest(/abc/)).to.throwError('propertyName must be a string');
|
||||
expect(() => server.addMemoizedFactoryToRequest(['foo'])).to.throwError('propertyName must be a string');
|
||||
expect(() => server.addMemoizedFactoryToRequest([1])).to.throwError('propertyName must be a string');
|
||||
expect(() => server.addMemoizedFactoryToRequest({})).to.throwError('propertyName must be a string');
|
||||
expect(() => server.addMemoizedFactoryToRequest()).toThrowError('methodName must be a string');
|
||||
expect(() => server.addMemoizedFactoryToRequest(null)).toThrowError('methodName must be a string');
|
||||
expect(() => server.addMemoizedFactoryToRequest(1)).toThrowError('methodName must be a string');
|
||||
expect(() => server.addMemoizedFactoryToRequest(true)).toThrowError('methodName must be a string');
|
||||
expect(() => server.addMemoizedFactoryToRequest(/abc/)).toThrowError('methodName must be a string');
|
||||
expect(() => server.addMemoizedFactoryToRequest(['foo'])).toThrowError('methodName must be a string');
|
||||
expect(() => server.addMemoizedFactoryToRequest([1])).toThrowError('methodName must be a string');
|
||||
expect(() => server.addMemoizedFactoryToRequest({})).toThrowError('methodName must be a string');
|
||||
});
|
||||
|
||||
it('throws when factory is not a function', () => {
|
||||
const { server } = setup();
|
||||
expect(() => server.addMemoizedFactoryToRequest('name')).to.throwError('factory must be a function');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', null)).to.throwError('factory must be a function');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', 1)).to.throwError('factory must be a function');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', true)).to.throwError('factory must be a function');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', /abc/)).to.throwError('factory must be a function');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', ['foo'])).to.throwError('factory must be a function');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', [1])).to.throwError('factory must be a function');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', {})).to.throwError('factory must be a function');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name')).toThrowError('factory must be a function');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', null)).toThrowError('factory must be a function');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', 1)).toThrowError('factory must be a function');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', true)).toThrowError('factory must be a function');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', /abc/)).toThrowError('factory must be a function');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', ['foo'])).toThrowError('factory must be a function');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', [1])).toThrowError('factory must be a function');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', {})).toThrowError('factory must be a function');
|
||||
});
|
||||
|
||||
it('throws when factory takes more than one arg', () => {
|
||||
const { server } = setup();
|
||||
/* eslint-disable no-unused-vars */
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', () => {})).to.not.throwError('more than one argument');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', (a) => {})).to.not.throwError('more than one argument');
|
||||
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', (a, b) => {})).to.throwError('more than one argument');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', (a, b, c) => {})).to.throwError('more than one argument');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', (a, b, c, d) => {})).to.throwError('more than one argument');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', (a, b, c, d, e) => {})).to.throwError('more than one argument');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', () => {})).not.toThrowError('more than one argument');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', (a) => {})).not.toThrowError('more than one argument');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', (a, b) => {})).toThrowError('more than one argument');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', (a, b, c) => {})).toThrowError('more than one argument');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', (a, b, c, d) => {})).toThrowError('more than one argument');
|
||||
expect(() => server.addMemoizedFactoryToRequest('name', (a, b, c, d, e) => {})).toThrowError('more than one argument');
|
||||
/* eslint-enable no-unused-vars */
|
||||
});
|
||||
|
||||
it('decorates request objects with a function at `propertyName`', () => {
|
||||
const { server, Request } = setup();
|
||||
|
||||
expect(new Request()).to.not.have.property('decorated');
|
||||
expect(new Request()).not.toHaveProperty('decorated');
|
||||
server.addMemoizedFactoryToRequest('decorated', () => {});
|
||||
expect(new Request()).to.have.property('decorated').a('function');
|
||||
expect(typeof new Request().decorated).toBe('function');
|
||||
});
|
||||
|
||||
it('caches invocations of the factory to the request instance', () => {
|
||||
|
@ -80,17 +78,17 @@ describe('server.addMemoizedFactoryToRequest()', () => {
|
|||
|
||||
// call `foo()` on both requests a bunch of times, each time
|
||||
// the return value should be exactly the same
|
||||
expect(request1.foo()).to.be(request1);
|
||||
expect(request1.foo()).to.be(request1);
|
||||
expect(request1.foo()).to.be(request1);
|
||||
expect(request1.foo()).to.be(request1);
|
||||
expect(request1.foo()).to.be(request1);
|
||||
expect(request1.foo()).to.be(request1);
|
||||
expect(request1.foo()).toBe(request1);
|
||||
expect(request1.foo()).toBe(request1);
|
||||
expect(request1.foo()).toBe(request1);
|
||||
expect(request1.foo()).toBe(request1);
|
||||
expect(request1.foo()).toBe(request1);
|
||||
expect(request1.foo()).toBe(request1);
|
||||
|
||||
expect(request2.foo()).to.be(request2);
|
||||
expect(request2.foo()).to.be(request2);
|
||||
expect(request2.foo()).to.be(request2);
|
||||
expect(request2.foo()).to.be(request2);
|
||||
expect(request2.foo()).toBe(request2);
|
||||
expect(request2.foo()).toBe(request2);
|
||||
expect(request2.foo()).toBe(request2);
|
||||
expect(request2.foo()).toBe(request2);
|
||||
|
||||
// only two different requests, so factory should have only been
|
||||
// called twice with the two request objects
|
|
@ -1,7 +1,6 @@
|
|||
import expect from 'expect.js';
|
||||
import mockFs from 'mock-fs';
|
||||
import { cGroups as cGroupsFsStub } from './fs_stubs';
|
||||
import { getAllStats, readControlGroups, readCPUStat } from '../cgroup';
|
||||
import { cGroups as cGroupsFsStub } from './_fs_stubs';
|
||||
import { getAllStats, readControlGroups, readCPUStat } from './cgroup';
|
||||
|
||||
describe('Control Group', function () {
|
||||
const fsStub = cGroupsFsStub();
|
||||
|
@ -15,7 +14,7 @@ describe('Control Group', function () {
|
|||
mockFs({ '/proc/self/cgroup': fsStub.cGroupContents });
|
||||
const cGroup = await readControlGroups();
|
||||
|
||||
expect(cGroup).to.eql({
|
||||
expect(cGroup).toEqual({
|
||||
freezer: '/',
|
||||
net_cls: '/',
|
||||
net_prio: '/',
|
||||
|
@ -38,7 +37,7 @@ describe('Control Group', function () {
|
|||
mockFs({ '/sys/fs/cgroup/cpu/fakeGroup/cpu.stat': fsStub.cpuStatContents });
|
||||
const cpuStat = await readCPUStat('fakeGroup');
|
||||
|
||||
expect(cpuStat).to.eql({
|
||||
expect(cpuStat).toEqual({
|
||||
number_of_elapsed_periods: 0,
|
||||
number_of_times_throttled: 10,
|
||||
time_throttled_nanos: 20
|
||||
|
@ -49,7 +48,7 @@ describe('Control Group', function () {
|
|||
mockFs();
|
||||
const cpuStat = await readCPUStat('fakeGroup');
|
||||
|
||||
expect(cpuStat).to.eql({
|
||||
expect(cpuStat).toEqual({
|
||||
number_of_elapsed_periods: -1,
|
||||
number_of_times_throttled: -1,
|
||||
time_throttled_nanos: -1
|
||||
|
@ -69,7 +68,7 @@ describe('Control Group', function () {
|
|||
|
||||
const stats = await getAllStats({ cpuPath: '/docker' });
|
||||
|
||||
expect(stats).to.eql({
|
||||
expect(stats).toEqual({
|
||||
cpuacct: {
|
||||
control_group: `/${fsStub.hierarchy}`,
|
||||
usage_nanos: 357753491408,
|
||||
|
@ -98,7 +97,7 @@ describe('Control Group', function () {
|
|||
|
||||
const stats = await getAllStats();
|
||||
|
||||
expect(stats).to.be(null);
|
||||
expect(stats).toBe(null);
|
||||
});
|
||||
|
||||
it('can override the cpuacct group path', async () => {
|
||||
|
@ -112,7 +111,7 @@ describe('Control Group', function () {
|
|||
|
||||
const stats = await getAllStats({ cpuAcctPath: '/docker' });
|
||||
|
||||
expect(stats).to.eql({
|
||||
expect(stats).toEqual({
|
||||
cpuacct: {
|
||||
control_group: '/docker',
|
||||
usage_nanos: 357753491408,
|
||||
|
@ -134,7 +133,7 @@ describe('Control Group', function () {
|
|||
mockFs(fsStub.files);
|
||||
const stats = await getAllStats();
|
||||
|
||||
expect(stats).to.eql({
|
||||
expect(stats).toEqual({
|
||||
cpuacct: {
|
||||
control_group: `/${fsStub.hierarchy}`,
|
||||
usage_nanos: 357753491408,
|
||||
|
@ -155,7 +154,7 @@ describe('Control Group', function () {
|
|||
it('returns null when all files are missing', async () => {
|
||||
mockFs({});
|
||||
const stats = await getAllStats();
|
||||
expect(stats).to.be.null;
|
||||
expect(stats).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null if CPU accounting files are missing', async () => {
|
||||
|
@ -165,10 +164,10 @@ describe('Control Group', function () {
|
|||
});
|
||||
const stats = await getAllStats();
|
||||
|
||||
expect(stats).to.be.null;
|
||||
expect(stats).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null if cpuStat file is missing', async () => {
|
||||
it('returns -1 stat values if cpuStat file is missing', async () => {
|
||||
mockFs({
|
||||
'/proc/self/cgroup': fsStub.cGroupContents,
|
||||
[`${fsStub.cpuAcctDir}/cpuacct.usage`]: '357753491408',
|
||||
|
@ -177,7 +176,22 @@ describe('Control Group', function () {
|
|||
});
|
||||
const stats = await getAllStats();
|
||||
|
||||
expect(stats).to.be.null;
|
||||
expect(stats).toEqual({
|
||||
cpu: {
|
||||
cfs_period_micros: 100000,
|
||||
cfs_quota_micros: 5000,
|
||||
control_group: `/${fsStub.hierarchy}`,
|
||||
stat: {
|
||||
number_of_elapsed_periods: -1,
|
||||
number_of_times_throttled: -1,
|
||||
time_throttled_nanos: -1
|
||||
}
|
||||
},
|
||||
cpuacct: {
|
||||
control_group: `/${fsStub.hierarchy}`,
|
||||
usage_nanos: 357753491408
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,10 +1,9 @@
|
|||
import _ from 'lodash';
|
||||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import mockFs from 'mock-fs';
|
||||
import { cGroups as cGroupsFsStub } from './fs_stubs';
|
||||
import { cGroups as cGroupsFsStub } from './_fs_stubs';
|
||||
|
||||
import { Metrics } from '../metrics';
|
||||
import { Metrics } from './metrics';
|
||||
|
||||
describe('Metrics', function () {
|
||||
const sampleConfig = {
|
||||
|
@ -39,7 +38,7 @@ describe('Metrics', function () {
|
|||
sinon.stub(process, 'uptime').returns(5000);
|
||||
|
||||
const capturedMetrics = await metrics.capture();
|
||||
expect(capturedMetrics).to.eql({
|
||||
expect(capturedMetrics).toEqual({
|
||||
last_updated: '2017-04-14T18:35:41.534Z',
|
||||
collection_interval_in_millis: 5000,
|
||||
uptime_in_millis: 5000000,
|
||||
|
@ -67,7 +66,7 @@ describe('Metrics', function () {
|
|||
'host': '123'
|
||||
};
|
||||
|
||||
expect(metrics.captureEvent(hapiEvent)).to.eql({
|
||||
expect(metrics.captureEvent(hapiEvent)).toEqual({
|
||||
'concurrent_connections': 0,
|
||||
'os': {
|
||||
'cpu': {
|
||||
|
@ -109,7 +108,7 @@ describe('Metrics', function () {
|
|||
|
||||
const stats = await metrics.captureCGroups();
|
||||
|
||||
expect(stats).to.be(undefined);
|
||||
expect(stats).toBe(undefined);
|
||||
});
|
||||
|
||||
it('returns cgroups', async () => {
|
||||
|
@ -118,7 +117,7 @@ describe('Metrics', function () {
|
|||
|
||||
const capturedMetrics = await metrics.captureCGroups();
|
||||
|
||||
expect(capturedMetrics).to.eql({
|
||||
expect(capturedMetrics).toEqual({
|
||||
os: {
|
||||
cgroup: {
|
||||
cpuacct: {
|
||||
|
@ -150,10 +149,10 @@ describe('Metrics', function () {
|
|||
mockFs();
|
||||
sinon.spy(metrics, 'captureCGroups');
|
||||
|
||||
expect(metrics.checkCGroupStats).to.be(true);
|
||||
expect(metrics.checkCGroupStats).toBe(true);
|
||||
|
||||
await metrics.captureCGroupsIfAvailable();
|
||||
expect(metrics.checkCGroupStats).to.be(false);
|
||||
expect(metrics.checkCGroupStats).toBe(false);
|
||||
|
||||
await metrics.captureCGroupsIfAvailable();
|
||||
sinon.assert.calledOnce(metrics.captureCGroups);
|
||||
|
@ -164,10 +163,10 @@ describe('Metrics', function () {
|
|||
mockFs(fsStub.files);
|
||||
sinon.spy(metrics, 'captureCGroups');
|
||||
|
||||
expect(metrics.checkCGroupStats).to.be(true);
|
||||
expect(metrics.checkCGroupStats).toBe(true);
|
||||
|
||||
await metrics.captureCGroupsIfAvailable();
|
||||
expect(metrics.checkCGroupStats).to.be(true);
|
||||
expect(metrics.checkCGroupStats).toBe(true);
|
||||
|
||||
await metrics.captureCGroupsIfAvailable();
|
||||
sinon.assert.calledTwice(metrics.captureCGroups);
|
|
@ -1,10 +1,9 @@
|
|||
import { find } from 'lodash';
|
||||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import * as states from '../states';
|
||||
import Status from '../status';
|
||||
import ServerStatus from '../server_status';
|
||||
import * as states from './states';
|
||||
import Status from './status';
|
||||
import ServerStatus from './server_status';
|
||||
|
||||
describe('ServerStatus class', function () {
|
||||
const plugin = { id: 'name', version: '1.2.3' };
|
||||
|
@ -20,38 +19,38 @@ describe('ServerStatus class', function () {
|
|||
describe('#create(id)', () => {
|
||||
it('should create a new plugin with an id', () => {
|
||||
const status = serverStatus.create('someid');
|
||||
expect(status).to.be.a(Status);
|
||||
expect(status).toBeInstanceOf(Status);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#createForPlugin(plugin)', function () {
|
||||
it('should create a new status by plugin', function () {
|
||||
const status = serverStatus.createForPlugin(plugin);
|
||||
expect(status).to.be.a(Status);
|
||||
expect(status).toBeInstanceOf(Status);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#get(id)', () => {
|
||||
it('exposes statuses by their id', () => {
|
||||
const status = serverStatus.create('statusid');
|
||||
expect(serverStatus.get('statusid')).to.be(status);
|
||||
expect(serverStatus.get('statusid')).toBe(status);
|
||||
});
|
||||
|
||||
it('does not get the status for a plugin', () => {
|
||||
serverStatus.createForPlugin(plugin);
|
||||
expect(serverStatus.get(plugin)).to.be(undefined);
|
||||
expect(serverStatus.get(plugin)).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getForPluginId(plugin)', function () {
|
||||
it('exposes plugin status for the plugin', function () {
|
||||
const status = serverStatus.createForPlugin(plugin);
|
||||
expect(serverStatus.getForPluginId(plugin.id)).to.be(status);
|
||||
expect(serverStatus.getForPluginId(plugin.id)).toBe(status);
|
||||
});
|
||||
|
||||
it('does not get plain statuses by their id', function () {
|
||||
serverStatus.create('someid');
|
||||
expect(serverStatus.getForPluginId('someid')).to.be(undefined);
|
||||
expect(serverStatus.getForPluginId('someid')).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -59,7 +58,7 @@ describe('ServerStatus class', function () {
|
|||
it('should expose the state of a status by id', function () {
|
||||
const status = serverStatus.create('someid');
|
||||
status.green();
|
||||
expect(serverStatus.getState('someid')).to.be('green');
|
||||
expect(serverStatus.getState('someid')).toBe('green');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -67,7 +66,7 @@ describe('ServerStatus class', function () {
|
|||
it('should expose the state of a plugin by id', function () {
|
||||
const status = serverStatus.createForPlugin(plugin);
|
||||
status.green();
|
||||
expect(serverStatus.getStateForPluginId(plugin.id)).to.be('green');
|
||||
expect(serverStatus.getStateForPluginId(plugin.id)).toBe('green');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -75,14 +74,13 @@ describe('ServerStatus class', function () {
|
|||
it('considers each status to produce a summary', function () {
|
||||
const status = serverStatus.createForPlugin(plugin);
|
||||
|
||||
expect(serverStatus.overall().state).to.be('uninitialized');
|
||||
expect(serverStatus.overall().state).toBe('uninitialized');
|
||||
|
||||
const match = function (overall, state) {
|
||||
expect(overall).to.have.property('state', state.id);
|
||||
expect(overall).to.have.property('title', state.title);
|
||||
expect(overall).to.have.property('icon', state.icon);
|
||||
expect(overall).to.have.property('icon', state.icon);
|
||||
expect(state.nicknames).contain(overall.nickname);
|
||||
expect(overall).toHaveProperty('state', state.id);
|
||||
expect(overall).toHaveProperty('title', state.title);
|
||||
expect(overall).toHaveProperty('icon', state.icon);
|
||||
expect(state.nicknames).toContain(overall.nickname);
|
||||
};
|
||||
|
||||
status.green();
|
||||
|
@ -111,14 +109,14 @@ describe('ServerStatus class', function () {
|
|||
p2.red();
|
||||
|
||||
const json = JSON.parse(JSON.stringify(serverStatus));
|
||||
expect(json).to.have.property('overall');
|
||||
expect(json.overall.state).to.eql(serverStatus.overall().state);
|
||||
expect(json.statuses).to.have.length(3);
|
||||
expect(json).toHaveProperty('overall');
|
||||
expect(json.overall.state).toEqual(serverStatus.overall().state);
|
||||
expect(json.statuses).toHaveLength(3);
|
||||
|
||||
const out = status => find(json.statuses, { id: status.id });
|
||||
expect(out(service)).to.have.property('state', 'green');
|
||||
expect(out(p1)).to.have.property('state', 'yellow');
|
||||
expect(out(p2)).to.have.property('state', 'red');
|
||||
expect(out(service)).toHaveProperty('state', 'green');
|
||||
expect(out(p1)).toHaveProperty('state', 'yellow');
|
||||
expect(out(p2)).toHaveProperty('state', 'red');
|
||||
});
|
||||
});
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import ServerStatus from '../server_status';
|
||||
import ServerStatus from './server_status';
|
||||
|
||||
describe('Status class', function () {
|
||||
const plugin = { id: 'test', version: '1.2.3' };
|
||||
|
@ -13,23 +12,23 @@ describe('Status class', function () {
|
|||
serverStatus = new ServerStatus(server);
|
||||
});
|
||||
|
||||
it('should have an "uninitialized" state initially', function () {
|
||||
expect(serverStatus.createForPlugin(plugin)).to.have.property('state', 'uninitialized');
|
||||
it('should have an "uninitialized" state initially', () => {
|
||||
expect(serverStatus.createForPlugin(plugin)).toHaveProperty('state', 'uninitialized');
|
||||
});
|
||||
|
||||
it('emits change when the status is set', function (done) {
|
||||
const status = serverStatus.createForPlugin(plugin);
|
||||
|
||||
status.once('change', function (prevState, prevMsg, newState, newMsg) {
|
||||
expect(newState).to.be('green');
|
||||
expect(newMsg).to.be('GREEN');
|
||||
expect(prevState).to.be('uninitialized');
|
||||
expect(newState).toBe('green');
|
||||
expect(newMsg).toBe('GREEN');
|
||||
expect(prevState).toBe('uninitialized');
|
||||
|
||||
status.once('change', function (prevState, prevMsg, newState, newMsg) {
|
||||
expect(newState).to.be('red');
|
||||
expect(newMsg).to.be('RED');
|
||||
expect(prevState).to.be('green');
|
||||
expect(prevMsg).to.be('GREEN');
|
||||
expect(newState).toBe('red');
|
||||
expect(newMsg).toBe('RED');
|
||||
expect(prevState).toBe('green');
|
||||
expect(prevMsg).toBe('GREEN');
|
||||
|
||||
done();
|
||||
});
|
||||
|
@ -55,9 +54,9 @@ describe('Status class', function () {
|
|||
status.green('Ready');
|
||||
|
||||
const json = status.toJSON();
|
||||
expect(json.id).to.eql(status.id);
|
||||
expect(json.state).to.eql('green');
|
||||
expect(json.message).to.eql('Ready');
|
||||
expect(json.id).toEqual(status.id);
|
||||
expect(json.state).toEqual('green');
|
||||
expect(json.message).toEqual('Ready');
|
||||
});
|
||||
|
||||
it('should call on handler if status is already matched', function (done) {
|
||||
|
@ -66,10 +65,10 @@ describe('Status class', function () {
|
|||
status.green(msg);
|
||||
|
||||
status.on('green', function (prev, prevMsg) {
|
||||
expect(arguments.length).to.equal(2);
|
||||
expect(prev).to.be('green');
|
||||
expect(prevMsg).to.be(msg);
|
||||
expect(status.message).to.equal(msg);
|
||||
expect(arguments.length).toBe(2);
|
||||
expect(prev).toBe('green');
|
||||
expect(prevMsg).toBe(msg);
|
||||
expect(status.message).toBe(msg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -80,10 +79,10 @@ describe('Status class', function () {
|
|||
status.green(msg);
|
||||
|
||||
status.once('green', function (prev, prevMsg) {
|
||||
expect(arguments.length).to.equal(2);
|
||||
expect(prev).to.be('green');
|
||||
expect(prevMsg).to.be(msg);
|
||||
expect(status.message).to.equal(msg);
|
||||
expect(arguments.length).toBe(2);
|
||||
expect(prev).toBe('green');
|
||||
expect(prevMsg).toBe(msg);
|
||||
expect(status.message).toBe(msg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -93,19 +92,19 @@ describe('Status class', function () {
|
|||
const status = serverStatus.createForPlugin(plugin);
|
||||
const message = 'testing ' + color;
|
||||
status[color](message);
|
||||
expect(status).to.have.property('state', color);
|
||||
expect(status).to.have.property('message', message);
|
||||
expect(status).toHaveProperty('state', color);
|
||||
expect(status).toHaveProperty('message', message);
|
||||
});
|
||||
|
||||
it(`should trigger the "change" listner when #${color}() is called`, function (done) {
|
||||
const status = serverStatus.createForPlugin(plugin);
|
||||
const message = 'testing ' + color;
|
||||
status.on('change', function (prev, prevMsg) {
|
||||
expect(status.state).to.be(color);
|
||||
expect(status.message).to.be(message);
|
||||
expect(status.state).toBe(color);
|
||||
expect(status.message).toBe(message);
|
||||
|
||||
expect(prev).to.be('uninitialized');
|
||||
expect(prevMsg).to.be('uninitialized');
|
||||
expect(prev).toBe('uninitialized');
|
||||
expect(prevMsg).toBe('uninitialized');
|
||||
done();
|
||||
});
|
||||
status[color](message);
|
||||
|
@ -115,8 +114,8 @@ describe('Status class', function () {
|
|||
const status = serverStatus.createForPlugin(plugin);
|
||||
const message = 'testing ' + color;
|
||||
status.on(color, function () {
|
||||
expect(status.state).to.be(color);
|
||||
expect(status.message).to.be(message);
|
||||
expect(status.state).toBe(color);
|
||||
expect(status.message).toBe(message);
|
||||
done();
|
||||
});
|
||||
status[color](message);
|
|
@ -1,5 +1,4 @@
|
|||
import expect from 'expect.js';
|
||||
import wrapAuthConfig from '../wrap_auth_config';
|
||||
import wrapAuthConfig from './wrap_auth_config';
|
||||
|
||||
describe('Status wrapAuthConfig', () => {
|
||||
let options;
|
||||
|
@ -15,28 +14,28 @@ describe('Status wrapAuthConfig', () => {
|
|||
});
|
||||
|
||||
it('should return a function', () => {
|
||||
expect(wrapAuthConfig()).to.be.a('function');
|
||||
expect(wrapAuthConfig(true)).to.be.a('function');
|
||||
expect(wrapAuthConfig(false)).to.be.a('function');
|
||||
expect(typeof wrapAuthConfig()).toBe('function');
|
||||
expect(typeof wrapAuthConfig(true)).toBe('function');
|
||||
expect(typeof wrapAuthConfig(false)).toBe('function');
|
||||
});
|
||||
|
||||
it('should not add auth config by default', () => {
|
||||
const wrapAuth = wrapAuthConfig();
|
||||
const wrapped = wrapAuth(options);
|
||||
expect(wrapped).to.not.have.property('config');
|
||||
expect(wrapped).not.toHaveProperty('config');
|
||||
});
|
||||
|
||||
it('should not add auth config if allowAnonymous is false', () => {
|
||||
const wrapAuth = wrapAuthConfig(false);
|
||||
const wrapped = wrapAuth(options);
|
||||
expect(wrapped).to.not.have.property('config');
|
||||
expect(wrapped).not.toHaveProperty('config');
|
||||
});
|
||||
|
||||
it('should add auth config if allowAnonymous is true', () => {
|
||||
const wrapAuth = wrapAuthConfig(true);
|
||||
const wrapped = wrapAuth(options);
|
||||
expect(wrapped).to.have.property('config');
|
||||
expect(wrapped.config).to.have.property('auth');
|
||||
expect(wrapped.config.auth).to.be(false);
|
||||
expect(wrapped).toHaveProperty('config');
|
||||
expect(wrapped.config).toHaveProperty('auth');
|
||||
expect(wrapped.config.auth).toBe(false);
|
||||
});
|
||||
});
|
|
@ -1,8 +1,7 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import { PassThrough } from 'stream';
|
||||
|
||||
import { confirm, question } from '../prompt';
|
||||
import { confirm, question } from './prompt';
|
||||
|
||||
describe('prompt', () => {
|
||||
const sandbox = sinon.sandbox.create();
|
||||
|
@ -28,7 +27,7 @@ describe('prompt', () => {
|
|||
sinon.assert.calledOnce(onData);
|
||||
|
||||
const { args } = onData.getCall(0);
|
||||
expect(args[0]).to.eql('my question [y/N] ');
|
||||
expect(args[0]).toEqual('my question [y/N] ');
|
||||
});
|
||||
|
||||
it('prompts for question with default true', async () => {
|
||||
|
@ -39,42 +38,42 @@ describe('prompt', () => {
|
|||
sinon.assert.calledOnce(onData);
|
||||
|
||||
const { args } = onData.getCall(0);
|
||||
expect(args[0]).to.eql('my question [Y/n] ');
|
||||
expect(args[0]).toEqual('my question [Y/n] ');
|
||||
});
|
||||
|
||||
it('defaults to false', async () => {
|
||||
process.nextTick(() => input.write('\n'));
|
||||
|
||||
const answer = await confirm('my question', { output, input });
|
||||
expect(answer).to.be(false);
|
||||
expect(answer).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts "y"', async () => {
|
||||
process.nextTick(() => input.write('y\n'));
|
||||
|
||||
const answer = await confirm('my question', { output, input });
|
||||
expect(answer).to.be(true);
|
||||
expect(answer).toBe(true);
|
||||
});
|
||||
|
||||
it('accepts "Y"', async () => {
|
||||
process.nextTick(() => input.write('Y\n'));
|
||||
|
||||
const answer = await confirm('my question', { output, input });
|
||||
expect(answer).to.be(true);
|
||||
expect(answer).toBe(true);
|
||||
});
|
||||
|
||||
it('accepts "yes"', async () => {
|
||||
process.nextTick(() => input.write('yes\n'));
|
||||
|
||||
const answer = await confirm('my question', { output, input });
|
||||
expect(answer).to.be(true);
|
||||
expect(answer).toBe(true);
|
||||
});
|
||||
|
||||
it('is false when unknown', async () => {
|
||||
process.nextTick(() => input.write('unknown\n'));
|
||||
|
||||
const answer = await confirm('my question', { output, input });
|
||||
expect(answer).to.be(false);
|
||||
expect(answer).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -87,14 +86,14 @@ describe('prompt', () => {
|
|||
sinon.assert.calledOnce(onData);
|
||||
|
||||
const { args } = onData.getCall(0);
|
||||
expect(args[0]).to.eql('my question: ');
|
||||
expect(args[0]).toEqual('my question: ');
|
||||
});
|
||||
|
||||
it('can be answered', async () => {
|
||||
process.nextTick(() => input.write('my answer\n'));
|
||||
|
||||
const answer = await question('my question', { input, output });
|
||||
expect(answer).to.be('my answer');
|
||||
expect(answer).toBe('my answer');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -14,7 +14,7 @@ module.exports = function (grunt) {
|
|||
function runJest(jestScript) {
|
||||
const serverCmd = {
|
||||
cmd: 'node',
|
||||
args: [jestScript],
|
||||
args: [jestScript, '--no-cache', '--ci'],
|
||||
opts: { stdio: 'inherit' }
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue