1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-24 01:18:01 +02:00

Fix formatting

This commit is contained in:
Ivar 2017-11-02 09:23:38 +01:00
parent de496c337a
commit fe0e65a4f2
12 changed files with 10056 additions and 47 deletions

View File

@ -6,6 +6,7 @@ const moment = require('moment');
const lolex = require('lolex'); const lolex = require('lolex');
test.cb('should emit expire', t => { test.cb('should emit expire', t => {
const clock = lolex.install();
const list = new TTLList({ const list = new TTLList({
interval: 20, interval: 20,
expireAmount: 10, expireAmount: 10,
@ -15,10 +16,12 @@ test.cb('should emit expire', t => {
list.on('expire', entry => { list.on('expire', entry => {
list.destroy(); list.destroy();
t.true(entry.n === 1); t.true(entry.n === 1);
console.log('here');
t.end(); t.end();
}); });
list.add({ n: 1 }); list.add({ n: 1 });
clock.tick(21);
}); });
test.cb('should slice off list', t => { test.cb('should slice off list', t => {

View File

@ -67,7 +67,10 @@ class ClientApplicationsDb {
} }
getAll() { getAll() {
return this.db.select(COLUMNS).from(TABLE).map(mapRow); return this.db
.select(COLUMNS)
.from(TABLE)
.map(mapRow);
} }
getApplication(appName) { getApplication(appName) {

View File

@ -20,7 +20,10 @@ class StrategyStore {
this._updateStrategy(event.data) this._updateStrategy(event.data)
); );
eventStore.on(STRATEGY_DELETED, event => { eventStore.on(STRATEGY_DELETED, event => {
db(TABLE).where('name', event.data.name).del().catch(err => { db(TABLE)
.where('name', event.data.name)
.del()
.catch(err => {
logger.error('Could not delete strategy, error was: ', err); logger.error('Could not delete strategy, error was: ', err);
}); });
}); });

View File

@ -10,7 +10,10 @@ const validateRequest = require('../../error/validate-request');
const handleErrors = (req, res, error) => { const handleErrors = (req, res, error) => {
switch (error.constructor) { switch (error.constructor) {
case ValidationError: case ValidationError:
return res.status(400).json(req.validationErrors()).end(); return res
.status(400)
.json(req.validationErrors())
.end();
default: default:
logger.error('Server failed executing request', error); logger.error('Server failed executing request', error);
return res.status(500).end(); return res.status(500).end();

View File

@ -33,7 +33,10 @@ const handleErrors = (req, res, error) => {
]) ])
.end(); .end();
case ValidationError: case ValidationError:
return res.status(400).json(req.validationErrors()).end(); return res
.status(400)
.json(req.validationErrors())
.end();
default: default:
logger.error('Server failed executing request', error); logger.error('Server failed executing request', error);
return res.status(500).end(); return res.status(500).end();
@ -41,7 +44,10 @@ const handleErrors = (req, res, error) => {
}; };
const strategiesSchema = joi.object().keys({ const strategiesSchema = joi.object().keys({
name: joi.string().regex(/^[a-zA-Z0-9\\.\\-]{3,100}$/).required(), name: joi
.string()
.regex(/^[a-zA-Z0-9\\.\\-]{3,100}$/)
.required(),
parameters: joi.object(), parameters: joi.object(),
}); });

View File

@ -3,10 +3,16 @@
const joi = require('joi'); const joi = require('joi');
const strategySchema = joi.object().keys({ const strategySchema = joi.object().keys({
name: joi.string().regex(/^[a-zA-Z0-9\\.\\-]{3,100}$/).required(), name: joi
.string()
.regex(/^[a-zA-Z0-9\\.\\-]{3,100}$/)
.required(),
editable: joi.boolean().default(true), editable: joi.boolean().default(true),
description: joi.string(), description: joi.string(),
parameters: joi.array().required().items( parameters: joi
.array()
.required()
.items(
joi.object().keys({ joi.object().keys({
name: joi.string().required(), name: joi.string().required(),
type: joi.string().required(), type: joi.string().required(),

View File

@ -26,7 +26,10 @@ const handleError = (req, res, error) => {
]) ])
.end(); .end();
case 'ValidationError': case 'ValidationError':
return res.status(400).json(error).end(); return res
.status(400)
.json(error)
.end();
default: default:
logger.error('Could perfom operation', error); logger.error('Could perfom operation', error);
return res.status(500).end(); return res.status(500).end();

View File

@ -2,15 +2,32 @@
const joi = require('joi'); const joi = require('joi');
const countSchema = joi.object().options({ stripUnknown: true }).keys({ const countSchema = joi
yes: joi.number().required().min(0).default(0), .object()
no: joi.number().required().min(0).default(0), .options({ stripUnknown: true })
.keys({
yes: joi
.number()
.required()
.min(0)
.default(0),
no: joi
.number()
.required()
.min(0)
.default(0),
}); });
const clientMetricsSchema = joi.object().options({ stripUnknown: true }).keys({ const clientMetricsSchema = joi
.object()
.options({ stripUnknown: true })
.keys({
appName: joi.string().required(), appName: joi.string().required(),
instanceId: joi.string().required(), instanceId: joi.string().required(),
bucket: joi.object().required().keys({ bucket: joi
.object()
.required()
.keys({
start: joi.date().required(), start: joi.date().required(),
stop: joi.date().required(), stop: joi.date().required(),
toggles: joi.object().pattern(/.*/, countSchema), toggles: joi.object().pattern(/.*/, countSchema),

View File

@ -2,11 +2,17 @@
const joi = require('joi'); const joi = require('joi');
const clientRegisterSchema = joi.object().options({ stripUnknown: true }).keys({ const clientRegisterSchema = joi
.object()
.options({ stripUnknown: true })
.keys({
appName: joi.string().required(), appName: joi.string().required(),
instanceId: joi.string().required(), instanceId: joi.string().required(),
sdkVersion: joi.string().optional(), sdkVersion: joi.string().optional(),
strategies: joi.array().required().items(joi.string(), joi.any().strip()), strategies: joi
.array()
.required()
.items(joi.string(), joi.any().strip()),
started: joi.date().required(), started: joi.date().required(),
interval: joi.number().required(), interval: joi.number().required(),
}); });

View File

@ -29,7 +29,10 @@ test('should give 500 when db is failing', t => {
db.select = () => ({ db.select = () => ({
from: () => Promise.reject(new Error('db error')), from: () => Promise.reject(new Error('db error')),
}); });
return request.get('/health').expect(500).expect(res => { return request
.get('/health')
.expect(500)
.expect(res => {
t.true(res.status === 500); t.true(res.status === 500);
t.true(res.body.health === 'BAD'); t.true(res.body.health === 'BAD');
}); });
@ -44,7 +47,10 @@ test('should give 200 when db is not failing', t => {
test('should give health=GOOD when db is not failing', t => { test('should give health=GOOD when db is not failing', t => {
t.plan(2); t.plan(2);
const { request } = getSetup(); const { request } = getSetup();
return request.get('/health').expect(200).expect(res => { return request
.get('/health')
.expect(200)
.expect(res => {
t.true(res.status === 200); t.true(res.status === 200);
t.true(res.body.health === 'GOOD'); t.true(res.body.health === 'GOOD');
}); });

9950
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -53,5 +53,8 @@ test.serial(
test.serial('must set name when reviving toggle', async t => { test.serial('must set name when reviving toggle', async t => {
t.plan(0); t.plan(0);
const { request, destroy } = await setupApp('archive_serial'); const { request, destroy } = await setupApp('archive_serial');
return request.post('/api/admin/archive/revive/').expect(404).then(destroy); return request
.post('/api/admin/archive/revive/')
.expect(404)
.then(destroy);
}); });