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,9 +20,12 @@ 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)
logger.error('Could not delete strategy, error was: ', err); .where('name', event.data.name)
}); .del()
.catch(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,17 +3,23 @@
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
joi.object().keys({ .array()
name: joi.string().required(), .required()
type: joi.string().required(), .items(
description: joi.string().allow(''), joi.object().keys({
required: joi.boolean(), name: joi.string().required(),
}) type: joi.string().required(),
), description: joi.string().allow(''),
required: joi.boolean(),
})
),
}); });
module.exports = strategySchema; module.exports = strategySchema;

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,19 +2,36 @@
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
appName: joi.string().required(), .object()
instanceId: joi.string().required(), .options({ stripUnknown: true })
bucket: joi.object().required().keys({ .keys({
start: joi.date().required(), appName: joi.string().required(),
stop: joi.date().required(), instanceId: joi.string().required(),
toggles: joi.object().pattern(/.*/, countSchema), bucket: joi
}), .object()
}); .required()
.keys({
start: joi.date().required(),
stop: joi.date().required(),
toggles: joi.object().pattern(/.*/, countSchema),
}),
});
module.exports = { clientMetricsSchema }; module.exports = { clientMetricsSchema };

View File

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

View File

@ -29,10 +29,13 @@ 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
t.true(res.status === 500); .get('/health')
t.true(res.body.health === 'BAD'); .expect(500)
}); .expect(res => {
t.true(res.status === 500);
t.true(res.body.health === 'BAD');
});
}); });
test('should give 200 when db is not failing', t => { test('should give 200 when db is not failing', t => {
@ -44,8 +47,11 @@ 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
t.true(res.status === 200); .get('/health')
t.true(res.body.health === 'GOOD'); .expect(200)
}); .expect(res => {
t.true(res.status === 200);
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);
}); });