@microsoft.azure/autorest.testserver
Version:
This project contains a set of OpenAPI definitions and a server implementing the corresponding API. Use this to test compliance of AutoRest generators.
161 lines (153 loc) • 8.45 kB
JavaScript
var express = require('express');
var router = express.Router();
var util = require('util');
var utils = require('../util/utils')
var number = function(coverage, optCoverage) {
router.put('/big/:format/:value', function(req, res, next) {
if (req.params.format === 'float') {
if (req.params.value === '3.402823e+20' && req.body === 3.402823e+20) {
coverage['putFloatBigScientificNotation']++;
res.status(200).end();
} else {
utils.send400(res, next, "Did not like the value provided for big float in the req " + util.inspect(req.body));
}
} else if (req.params.format === 'double') {
if (req.params.value === '2.5976931e+101' && req.body === 2.5976931e+101) {
coverage['putDoubleBigScientificNotation']++;
res.status(200).end();
} else if (req.params.value === '99999999.99' && req.body === 99999999.99) {
coverage['putDoubleBigPositiveDecimal']++;
res.status(200).end();
} else if (req.params.value === '-99999999.99' && req.body === -99999999.99) {
coverage['putDoubleBigNegativeDecimal']++;
res.status(200).end();
} else {
utils.send400(res, next, "Did not like the value provided for big double in the req " + util.inspect(req.body));
}
} else if (req.params.format === 'decimal') {
if (req.params.value === '2.5976931e+101' && req.body === 2.5976931e+101) {
optCoverage['putDecimalBig']++;
res.status(200).end();
} else if (req.params.value === '99999999.99' && req.body === 99999999.99) {
optCoverage['putDecimalBigPositiveDecimal']++;
res.status(200).end();
} else if (req.params.value === '-99999999.99' && req.body === -99999999.99) {
optCoverage['putDecimalBigNegativeDecimal']++;
res.status(200).end();
} else {
utils.send400(res, next, "Did not like the value provided for big decimal in the req " + util.inspect(req.body));
}
} else {
utils.send400(res, next, "Please use either float or double in the req " + util.inspect(req.params.format));
}
});
router.get('/big/:format/:value', function(req, res, next) {
if (req.params.format === 'float') {
if (req.params.value === '3.402823e+20') {
coverage['getFloatBigScientificNotation']++;
res.status(200).type('json').end('3.402823e+20');
} else {
utils.send400(res, next, "Did not like the value provided for big float in the req " + util.inspect(req.params.value));
}
} else if (req.params.format === 'double') {
if (req.params.value === '2.5976931e+101') {
coverage['getDoubleBigScientificNotation']++;
res.status(200).type('json').end('2.5976931e+101');
} else if (req.params.value === '99999999.99') {
coverage['getDoubleBigPositiveDecimal']++;
res.status(200).type('json').end('99999999.99');
} else if (req.params.value === '-99999999.99') {
coverage['getDoubleBigNegativeDecimal']++;
res.status(200).type('json').end('-99999999.99');
} else {
utils.send400(res, next, "Did not understand the value provided for big double in the req " + util.inspect(req.params.value));
}
} else if (req.params.format === 'decimal') {
if (req.params.value === '2.5976931e+101') {
optCoverage['getDecimalBig']++;
res.status(200).type('json').end('2.5976931e+101');
} else if (req.params.value === '99999999.99') {
optCoverage['getDecimalBigPositiveDecimal']++;
res.status(200).type('json').end('99999999.99');
} else if (req.params.value === '-99999999.99') {
optCoverage['getDecimalBigNegativeDecimal']++;
res.status(200).type('json').end('-99999999.99');
} else {
utils.send400(res, next, "Did not understand the value provided for big decimal in the req " + util.inspect(req.params.value));
}
} else {
utils.send400(res, next, "Please use either float or double in the req " + util.inspect(req.params.format));
}
});
router.put('/small/:format/:value', function(req, res, next) {
if (req.params.format === 'float') {
if (req.params.value === '3.402823e-20' && req.body === 3.402823e-20) {
coverage['putFloatSmallScientificNotation']++;
res.status(200).end();
} else {
utils.send400(res, next, "Did not like the value provided for small float in the req " + util.inspect(req.body));
}
} else if (req.params.format === 'double') {
if (req.params.value === '2.5976931e-101' && req.body === 2.5976931e-101) {
coverage['putDoubleSmallScientificNotation']++;
res.status(200).end();
} else {
utils.send400(res, next, "Did not like the value provided for small double in the req " + util.inspect(req.body));
}
} else if (req.params.format === 'decimal') {
if (req.params.value === '2.5976931e-101' && req.body === 2.5976931e-101) {
optCoverage['putDecimalSmall']++;
res.status(200).end();
} else {
utils.send400(res, next, "Did not like the value provided for small decimal in the req " + util.inspect(req.body));
}
} else {
utils.send400(res, next, "Please use either float or double in the req " + util.inspect(req.params.format));
}
});
router.get('/small/:format/:value', function(req, res, next) {
if (req.params.format === 'float') {
if (req.params.value === '3.402823e-20') {
coverage['getFloatSmallScientificNotation']++;
res.status(200).type('json').end('3.402823e-20');
} else {
utils.send400(res, next, "Did not like the value provided for small float in the req " + util.inspect(req.params.value));
}
} else if (req.params.format === 'double') {
if (req.params.value === '2.5976931e-101') {
coverage['getDoubleSmallScientificNotation']++;
res.status(200).type('json').end('2.5976931e-101');
} else {
utils.send400(res, next, "Did not like the value provided for small double in the req " + util.inspect(req.params.value));
}
} else if (req.params.format === 'decimal') {
if (req.params.value === '2.5976931e-101') {
optCoverage['getDecimalSmall']++;
res.status(200).type('json').end('2.5976931e-101');
} else {
utils.send400(res, next, "Did not like the value provided for small decimal in the req " + util.inspect(req.params.value));
}
} else {
utils.send400(res, next, "Please use either float or double in the req " + util.inspect(req.params.format));
}
});
router.get('/:scenario', function(req, res, next) {
if (req.params.scenario === 'null') {
coverage['getNumberNull']++;
res.status(200).end();
} else if (req.params.scenario === 'invalidfloat') {
coverage['getFloatInvalid']++;
res.status(200).type('json').end('2147483656.090096789909j');
} else if (req.params.scenario === 'invaliddouble') {
coverage['getDoubleInvalid']++;
res.status(200).type('json').end('9223372036854775910.980089k');
} else if (req.params.scenario === 'invaliddecimal') {
optCoverage['getDecimalInvalid']++;
res.status(200).type('json').end('9223372036854775910.980089k');
} else {
res.status(400).send('Request path must contain true or false');
}
});
}
number.prototype.router = router;
module.exports = number;