diff --git a/package.json b/package.json index 41addee..b5f1855 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@microsoft.azure/autorest.testserver", - "version": "3.3.23", + "version": "3.3.24", "description": "Autorest test server.", "main": "dist/cli/cli.js", "bin": { diff --git a/src/test-routes/array.ts b/src/test-routes/array.ts index 07a1c9a..b9ac570 100644 --- a/src/test-routes/array.ts +++ b/src/test-routes/array.ts @@ -216,7 +216,7 @@ app.category("vanilla", () => { }); app.put("/array/prim/date-time/valid", "putArrayDateTimeValid", (req) => { - req.expect.bodyEquals(["2000-12-01T00:00:01.000Z", "1980-01-02T00:11:35.000Z", "1492-10-12T10:15:01.000Z"]); + req.expect.coercedBodyEquals(["2000-12-01T00:00:01Z", "1980-01-02T00:11:35Z", "1492-10-12T10:15:01Z"]); return { status: 200 }; }); @@ -243,7 +243,7 @@ app.category("vanilla", () => { }; }); - app.put("/array/prim/date-time-rfc1123/valid", "getDateTimeRfc1123Valid", (req) => { + app.put("/array/prim/date-time-rfc1123/valid", "putArrayDateTimeRfc1123Valid", (req) => { req.expect.bodyEquals([ "Fri, 01 Dec 2000 00:00:01 GMT", "Wed, 02 Jan 1980 00:11:35 GMT", diff --git a/src/test-routes/http-responses.ts b/src/test-routes/http-responses.ts index 4ab68e6..b22b86b 100644 --- a/src/test-routes/http-responses.ts +++ b/src/test-routes/http-responses.ts @@ -137,7 +137,7 @@ app.category("vanilla", () => { "Retry", { 408: ["head"], - 502: ["get"], + 502: ["get", "options"], 500: ["put", "patch"], 503: ["post", "delete"], 504: ["put", "patch"], @@ -315,7 +315,7 @@ app.category("vanilla", () => { //#region Endpoint with response for 202, 204, 400 returning valid payloads app.get("/http/payloads/default/a/response/200/valid", "ResponsesScenarioF200DefaultModel", (req) => { - return { status: 200, body: json({ property: "value" }) }; + return { status: 200, body: json({ statusCode: "200" }) }; }); app.get("/http/payloads/default/a/response/200/none", "ResponsesScenarioF200DefaultNone", (req) => { @@ -354,7 +354,7 @@ app.category("vanilla", () => { }); app.get("/http/payloads/200/a/response/200/valid", "ResponsesScenarioH200MatchingModel", (req) => { - return { status: 200 }; + return { status: 200, body: json({ statusCode: "200" }) }; }); app.get("/http/payloads/200/a/response/200/invalid", "ResponsesScenarioH200MatchingInvalid", (req) => { diff --git a/src/test-routes/paths.ts b/src/test-routes/paths.ts index df2d54a..df6477a 100644 --- a/src/test-routes/paths.ts +++ b/src/test-routes/paths.ts @@ -1,5 +1,6 @@ import { app, ValidationError, json } from "../api"; import { coverageService } from "../services"; +import { coerceDateString } from "../utils"; const Constants = { DEFAULT_SERVER_PORT: "3000", @@ -127,13 +128,17 @@ app.category("vanilla", () => { }; } - const wireParameter = deserializeValue(type as never, req.params.wireParameter); + let wireParameter = deserializeValue(type as never, req.params.wireParameter); if (scenarioConfig === undefined) { return { status: 404, body: json({ message: `Scenario "${scenarioName}" not found for type ${type}` }) }; } - const expectedValue = getScenarioExpectedValue(scenarioName, scenarioConfig); + let expectedValue = getScenarioExpectedValue(scenarioName, scenarioConfig); + if (type === "datetime") { + wireParameter = coerceDateString(wireParameter); + expectedValue = coerceDateString(expectedValue as string); + } if (wireParameter !== expectedValue) { throw new ValidationError("wireParameter path does not match expected value", expectedValue, wireParameter); } diff --git a/src/utils/misc-utils.ts b/src/utils/misc-utils.ts index 2f27b42..66b8908 100644 --- a/src/utils/misc-utils.ts +++ b/src/utils/misc-utils.ts @@ -1 +1,4 @@ export const toPascalCase = (input: string): string => "" + input.charAt(0).toUpperCase() + input.slice(1); + +export const coerceDateString = (date: string): string => + date.replace(/(\d\d\d\d-\d\d-\d\d[Tt]\d\d:\d\d:\d\d)\.\d{3,7}([Zz]|[+-]00:00)/g, "$1Z");