Migrate additional properties to test server v2 route (#355)

This commit is contained in:
Timothee Guerin 2022-02-25 15:51:52 -08:00 коммит произвёл GitHub
Родитель ee2846fd89
Коммит 7dc0c37e73
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 126 добавлений и 149 удалений

Просмотреть файл

@ -6,6 +6,7 @@ root = true
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
# JS/TS files
[*.{js,jsx,ts,tsx}]

1
.vscode/settings.json поставляемый
Просмотреть файл

@ -8,6 +8,7 @@
"**/node_modules": true,
"dist": true
},
"files.eol": "\n",
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
}

Просмотреть файл

@ -1,139 +0,0 @@
var express = require("express");
var router = express.Router();
var util = require("util");
var _ = require("underscore");
var utils = require("../util/utils");
var apTrue = {
id: 1,
name: "Puppy",
birthdate: "2017-12-13T02:29:51Z",
complexProperty: {
color: "Red",
},
};
var apSubclass = {
id: 1,
name: "Lisa",
friendly: true,
birthdate: "2017-12-13T02:29:51Z",
complexProperty: {
color: "Red",
},
};
var apObject = {
id: 2,
name: "Hira",
siblings: [
{
id: 1,
name: "Puppy",
birthdate: "2017-12-13T02:29:51Z",
complexProperty: {
color: "Red",
},
},
],
picture: new Buffer([255, 255, 255, 255, 254]).toString("base64"),
};
var apString = {
id: 3,
name: "Tommy",
color: "red",
weight: "10 kg",
city: "Bombay",
};
var apInProperties = {
id: 4,
name: "Bunny",
additionalProperties: {
height: 5.61,
weight: 599,
footsize: 11.5,
},
};
var apInPropertiesWithAPString = {
"id": 5,
"name": "Funny",
"@odata.location": "westus",
"additionalProperties": {
height: 5.61,
weight: 599,
footsize: 11.5,
},
"color": "red",
"city": "Seattle",
"food": "tikka masala",
};
var additionalProperties = function (coverage) {
router.put("/true", function (req, res, next) {
if (req.body && _.isEqual(utils.coerceDate(req.body), apTrue)) {
coverage["additionalPropertiesTrue"]++;
let resBody = JSON.parse(JSON.stringify(apTrue));
resBody.status = true;
res.status(200).json(resBody);
} else {
utils.send400(res, next, "Did not like additionalProperties req " + util.inspect(req.body));
}
});
router.put("/true-subclass", function (req, res) {
if (req.body && _.isEqual(utils.coerceDate(req.body), apSubclass)) {
coverage["additionalPropertiesSubclass"]++;
let resBody = JSON.parse(JSON.stringify(apSubclass));
resBody.status = true;
res.status(200).json(resBody);
} else {
utils.send400(res, next, "Did not like additionalProperties req " + util.inspect(req.body));
}
});
router.put("/type/object", function (req, res, next) {
if (req.body && _.isEqual(utils.coerceDate(req.body), apObject)) {
coverage["additionalPropertiesTypeObject"]++;
let resBody = JSON.parse(JSON.stringify(apObject));
resBody.status = true;
res.status(200).json(resBody);
} else {
utils.send400(res, next, "Did not like additionalProperties req " + util.inspect(req.body));
}
});
router.put("/type/string", function (req, res, next) {
if (req.body && _.isEqual(utils.coerceDate(req.body), apString)) {
coverage["additionalPropertiesTypeString"]++;
let resBody = JSON.parse(JSON.stringify(apString));
resBody.status = true;
res.status(200).json(resBody);
} else {
utils.send400(res, next, "Did not like additionalProperties req " + util.inspect(req.body));
}
});
router.put("/in/properties", function (req, res, next) {
if (req.body && _.isEqual(req.body, apInProperties)) {
coverage["additionalPropertiesInProperties"]++;
let resBody = JSON.parse(JSON.stringify(apInProperties));
resBody.status = true;
res.status(200).json(resBody);
} else {
utils.send400(res, next, "Did not like additionalProperties req " + util.inspect(req.body));
}
});
router.put("/in/properties/with/additionalProperties/string", function (req, res, next) {
if (req.body && _.isEqual(req.body, apInPropertiesWithAPString)) {
coverage["additionalPropertiesInPropertiesWithAPTypeString"]++;
let resBody = JSON.parse(JSON.stringify(apInPropertiesWithAPString));
resBody.status = true;
res.status(200).json(resBody);
} else {
utils.send400(res, next, "Did not like additionalProperties req " + util.inspect(req.body));
}
});
};
additionalProperties.prototype.router = router;
module.exports = additionalProperties;

Просмотреть файл

@ -1,6 +1,6 @@
{
"name": "@microsoft.azure/autorest.testserver",
"version": "3.3.6",
"version": "3.3.7",
"description": "Autorest test server.",
"main": "dist/cli/cli.js",
"bin": {
@ -18,7 +18,7 @@
"dev": "npm run watch",
"start": "npm run build && node ./dist/cli/cli.js",
"start:prod": "node ./dist/cli/cli.js",
"start:dev": "concurrently \"npm run watch\" \"nodemon ./dist/cli/cli.js\"",
"start:dev": "nodemon ./dist/cli/cli.js",
"stop": "node ./dist/cli/cli.js stop",
"fix": "eslint . --fix --ext .ts",
"lint": "eslint ./src --ext .ts --max-warnings=0",

Просмотреть файл

@ -13,7 +13,6 @@ const legacyRoutePath = `${ProjectRoot}/legacy/routes`;
const requireLegacy = (filename: string) => require(`${legacyRoutePath}/${filename}`);
const additionalProperties = requireLegacy("additionalProperties.js");
const array = requireLegacy("array");
const parameterGrouping = requireLegacy("azureParameterGrouping.js");
const azureSpecial = requireLegacy("azureSpecials");
@ -82,12 +81,6 @@ export const registerLegacyRoutes = (app: MockApiServer | Router): void => {
});
const coverage = proxyCoverage("vanilla", {
additionalPropertiesTrue: 0,
additionalPropertiesSubclass: 0,
additionalPropertiesTypeObject: 0,
additionalPropertiesTypeString: 0,
additionalPropertiesInProperties: 0,
additionalPropertiesInPropertiesWithAPTypeString: 0,
getArrayNull: 0,
getArrayEmpty: 0,
putArrayEmpty: 0,
@ -494,7 +487,6 @@ export const registerLegacyRoutes = (app: MockApiServer | Router): void => {
app.use("/customUri", new customUri(coverage).router);
app.use("/extensibleEnums", new extensibleEnums(coverage).router);
app.use("/errorStatusCodes", new errorStatusCodes(coverage, optionalCoverage).router);
app.use("/additionalProperties", new additionalProperties(coverage).router);
app.use("/mediatypes", new mediatypes(coverage).router);
app.use("/xml", new xml(coverage).router);
app.use("/multiapi", new multiapi(optionalCoverage).router);

Просмотреть файл

@ -0,0 +1,122 @@
import { app, json } from "../api";
app.category("azure", () => {
app.put("/additionalProperties/true", "additionalPropertiesTrue", (req) => {
const expectedBody = {
id: 1,
name: "Puppy",
birthdate: "2017-12-13T02:29:51Z",
complexProperty: {
color: "Red",
},
};
req.expect.bodyEquals(expectedBody);
return {
status: 200,
body: json({ ...expectedBody, status: true }),
};
});
app.put("/additionalProperties/true-subclass", "additionalPropertiesSubclass", (req) => {
const expectedBody = {
id: 1,
name: "Lisa",
friendly: true,
birthdate: "2017-12-13T02:29:51Z",
complexProperty: {
color: "Red",
},
};
req.expect.bodyEquals(expectedBody);
return {
status: 200,
body: json({ ...expectedBody, status: true }),
};
});
app.put("/additionalProperties/type/object", "additionalPropertiesTypeObject", (req) => {
const expectedBody = {
id: 2,
name: "Hira",
siblings: [
{
id: 1,
name: "Puppy",
birthdate: "2017-12-13T02:29:51Z",
complexProperty: {
color: "Red",
},
},
],
picture: new Buffer([255, 255, 255, 255, 254]).toString("base64"),
};
req.expect.bodyEquals(expectedBody);
return {
status: 200,
body: json({ ...expectedBody, status: true }),
};
});
app.put("/additionalProperties/type/string", "additionalPropertiesTypeString", (req) => {
const expectedBody = {
id: 3,
name: "Tommy",
color: "red",
weight: "10 kg",
city: "Bombay",
};
req.expect.bodyEquals(expectedBody);
return {
status: 200,
body: json({ ...expectedBody, status: true }),
};
});
app.put("/additionalProperties/in/properties", "additionalPropertiesInProperties", (req) => {
const expectedBody = {
id: 4,
name: "Bunny",
additionalProperties: {
height: 5.61,
weight: 599,
footsize: 11.5,
},
};
req.expect.bodyEquals(expectedBody);
return {
status: 200,
body: json({ ...expectedBody, status: true }),
};
});
app.put(
"/in/properties/with/additionalProperties/string",
"additionalPropertiesInPropertiesWithAPTypeString",
(req) => {
const expectedBody = {
"id": 5,
"name": "Funny",
"@odata.location": "westus",
"additionalProperties": {
height: 5.61,
weight: 599,
footsize: 11.5,
},
"color": "red",
"city": "Seattle",
"food": "tikka masala",
};
req.expect.bodyEquals(expectedBody);
return {
status: 200,
body: json({ ...expectedBody, status: true }),
};
},
);
});