1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-10 01:16:39 +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');
test.cb('should emit expire', t => {
const clock = lolex.install();
const list = new TTLList({
interval: 20,
expireAmount: 10,
@ -15,10 +16,12 @@ test.cb('should emit expire', t => {
list.on('expire', entry => {
list.destroy();
t.true(entry.n === 1);
console.log('here');
t.end();
});
list.add({ n: 1 });
clock.tick(21);
});
test.cb('should slice off list', t => {

View File

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

View File

@ -20,9 +20,12 @@ class StrategyStore {
this._updateStrategy(event.data)
);
eventStore.on(STRATEGY_DELETED, event => {
db(TABLE).where('name', event.data.name).del().catch(err => {
logger.error('Could not delete strategy, error was: ', err);
});
db(TABLE)
.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) => {
switch (error.constructor) {
case ValidationError:
return res.status(400).json(req.validationErrors()).end();
return res
.status(400)
.json(req.validationErrors())
.end();
default:
logger.error('Server failed executing request', error);
return res.status(500).end();

View File

@ -33,7 +33,10 @@ const handleErrors = (req, res, error) => {
])
.end();
case ValidationError:
return res.status(400).json(req.validationErrors()).end();
return res
.status(400)
.json(req.validationErrors())
.end();
default:
logger.error('Server failed executing request', error);
return res.status(500).end();
@ -41,7 +44,10 @@ const handleErrors = (req, res, error) => {
};
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(),
});

View File

@ -3,17 +3,23 @@
const joi = require('joi');
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),
description: joi.string(),
parameters: joi.array().required().items(
joi.object().keys({
name: joi.string().required(),
type: joi.string().required(),
description: joi.string().allow(''),
required: joi.boolean(),
})
),
parameters: joi
.array()
.required()
.items(
joi.object().keys({
name: joi.string().required(),
type: joi.string().required(),
description: joi.string().allow(''),
required: joi.boolean(),
})
),
});
module.exports = strategySchema;

View File

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

View File

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

View File

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

View File

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