Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict'
const Joi = require('@hapi/joi')
const { colorScale } = require('../color-formatters')
const { BaseJsonService } = require('..')
const colorFormatter = colorScale([99, 99.5, 100])
const rowSchema = Joi.object().keys({
uptime: Joi.number()
.precision(3)
.min(0)
.max(100),
})
const schema = Joi.array()
.items(rowSchema)
.min(1)
/*
* this is the checkUuid for the NodePing.com (as used on the [example page](https://nodeping.com/reporting.html#results))
*/
const sampleCheckUuid = 'jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei'
// TODO: support for custom # of days
// TODO: support for custom color thresholds
test('uses optional path prefix as path if no path exists', () => {
const { error } = Joi.number().validate({ invalid: 'invalid' })
expect(joiValidationErrorConverter(error, 'test')).toEqual(
new ValidationError('test must be a number')
)
})
it('uses original value before schema conversion', async () => {
const server = Hapi.server();
server.route({
method: 'GET',
path: '/{seq}',
handler: (request) => (request.orig.params.seq + 1),
options: {
validate: {
params: {
seq: Joi.number()
}
}
}
});
const res = await server.inject('/10');
expect(res.statusCode).to.equal(200);
expect(res.result).to.equal('101');
});
'use strict'
const Joi = require('@hapi/joi')
const t = (module.exports = require('../tester').createServiceTester())
t.create('language count')
.get('/badges/shields.json')
.expectBadge({
label: 'languages',
message: Joi.number()
.integer()
.positive(),
})
t.create('language count (empty repo)')
.get('/pyvesb/emptyrepo.json')
.expectBadge({ label: 'languages', message: '0' })
t.create('language count (repo not found)')
.get('/badges/helmets.json')
.expectBadge({ label: 'languages', message: 'repo not found' })
true
)
function isLegacyVersion({ sonarVersion }) {
sonarVersion = parseFloat(sonarVersion)
return !!sonarVersion && sonarVersion < 5.4
}
function getLabel({ metric }) {
return metric ? metric.replace(/_/g, ' ') : undefined
}
const sonarVersionSchema = Joi.alternatives(
Joi.string()
.regex(/[0-9.]+/)
.optional(),
Joi.number().optional()
)
const queryParamSchema = Joi.object({
sonarVersion: sonarVersionSchema,
server: optionalUrl.required(),
}).required()
const queryParamWithFormatSchema = Joi.object({
sonarVersion: sonarVersionSchema,
server: optionalUrl.required(),
format: Joi.string()
.allow('short', 'long')
.optional(),
}).required()
const keywords = ['sonarcloud', 'sonarqube']
}
}
},
{
method: 'GET',
path: '/v1/properties/number',
config: {
handler: defaultHandler,
description: 'Number properties',
tags: ['api'],
validate: {
query: {
a: Joi.number()
.min(5)
.description('min'),
b: Joi.number()
.max(10)
.description('max'),
c: Joi.number()
.greater(20)
.description('greater'),
d: Joi.number()
.less(20)
.description('less'),
e: Joi.number()
.multiple(2)
.description('multiple'),
f: Joi.number()
.precision(2)
.description('precision'),
g: Joi.number()
.positive()
const validate = value => {
Joi.assert(value, Joi.any().invalid(Infinity, -Infinity), new TypeError(`Value is not a finite number: ${value}`))
Joi.assert(value, Joi.number().required(), new TypeError(`Value is not a number: ${value}`))
const parsed = parseFloat(value)
Joi.assert(parsed, Joi.number().positive(), new TypeError(`Value is not a positive number: ${parsed}`))
Joi.assert(parsed, Joi.number().greater(0), new TypeError(`Value is not greater than 0: ${parsed}`))
return parsed
}
description: 'Update sum',
notes: ['Update a sum in our data store'],
plugins: {
'hapi-swagger': {
payloadType: 'form'
}
},
tags: ['api'],
validate: {
params: {
id: Joi.string()
.required()
.description('the id of the sum in the store')
},
payload: {
a: Joi.number()
.required()
.description('the first number'),
b: Joi.number()
.required()
.description('the second number'),
operator: Joi.string()
.required()
.default('+')
.valid(['+', '-', '/', '*'])
.description('the opertator i.e. + - / or *'),
equals: Joi.number()
.required()
.description('the result of the sum')
username: joi.string().required(),
password: joi.string().required(),
}),
}),
},
log: logJoi,
extensions: joi.object(),
metrics: {
topic: joi.string().required(),
},
server: {
healthChecks: joi.object({
allowFrom: joi.array().items(joi.string()).default([]),
}).required(),
host: joi.string().required(),
port: joi.number().default(8900),
},
redis: {
host: joi.string().default('localhost'),
port: joi.number().default(6379),
name: joi.string().default('backbeat'),
password: joi.string().default('').allow(''),
sentinels: joi.alternatives([joi.string(), joi.array().items(
joi.object({
host: joi.string().required(),
port: joi.number().required(),
}))]
),
sentinelPassword: joi.string().default('').allow(''),
},
localCache: {
host: joi.string().default('localhost'),
'use strict'
const Joi = require('@hapi/joi')
const { BaseJsonService } = require('..')
const schema = Joi.object({
total_amount: Joi.number()
.min(0)
.required(),
}).required()
module.exports = class Beerpay extends BaseJsonService {
static get category() {
return 'funding'
}
static get route() {
return {
base: 'beerpay',
pattern: ':user/:project',
}
}