Skip to content

Commit

Permalink
feat: add check for http return codes
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbi08 committed Feb 6, 2024
1 parent 875bb70 commit d9dce11
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
34 changes: 32 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"typescript-ioc": "3.2.2",
"typescript-rest": "3.0.4",
"typescript-rest-ioc": "1.0.1",
"typescript-rest-swagger": "github:sebbi08/typescript-rest-swagger",
"yamljs": "0.3.0"
},
"devDependencies": {
Expand Down Expand Up @@ -101,7 +100,8 @@
"prettier": "^3.1.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.3.2"
"typescript": "^5.3.2",
"typescript-rest-swagger": "github:sebbi08/typescript-rest-swagger"
},
"overrides": {
"typescript-rest": {
Expand Down
22 changes: 13 additions & 9 deletions test/spec.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as ts from "typescript";
import yamljs from "yamljs";

import { MetadataGenerator, SpecGenerator } from "typescript-rest-swagger";
import { Swagger } from "typescript-rest-swagger/dist/swagger/swagger";
import { MetadataGenerator, SpecGenerator, Swagger } from "typescript-rest-swagger";

import tsConfigBase from "../tsconfig.json";

describe("test openapi spec against routes", () => {
Expand Down Expand Up @@ -39,6 +39,8 @@ describe("test openapi spec against routes", () => {

// Paths not defined in the typescript-rest way
const ignorePaths = ["/health", "/Healthcheck", "/Monitoring/Version", "/Monitoring/Requests", "/Monitoring/Support"];
//
const postReturnCodeIgnorePaths = ["/api/v2/Account/Sync", "/api/v2/Attributes/ExecuteIQLQuery", "/api/v2/Attributes/ValidateIQLQuery", "/api/v2/Challenges/Validate"];

manualPaths.forEach((path) => {
if (ignorePaths.includes(path)) {
Expand All @@ -56,13 +58,15 @@ describe("test openapi spec against routes", () => {

expect(generatedMethods, `Path ${path} do not have the same methods`).toStrictEqual(manualMethods);

// Object.keys(manualOpenApiSpec.paths[path]).forEach((method) => {
// const key = method as "get" | "put" | "post" | "delete" | "options" | "head" | "patch";
// const manualResponses = Object.keys(manualOpenApiSpec.paths[path][key]!.responses);
// const expectedResponseCode = key !== "get" ? "201" : "200";
// if (key === "post") debugger;
// // expect(manualResponses, `Path ${path} and method ${method} dose not conain response code ${expectedResponseCode}`).toContainEqual(expectedResponseCode);
// });
if (postReturnCodeIgnorePaths.includes(path)) {
return;
}
Object.keys(manualOpenApiSpec.paths[path]).forEach((method) => {
const key = method as "get" | "put" | "post" | "delete" | "options" | "head" | "patch";
const manualResponses = Object.keys(manualOpenApiSpec.paths[path][key]?.responses ?? {});
const expectedResponseCode = key === "post" ? "201" : "200";
expect(manualResponses, `Path ${path} and method ${method} dose not conain response code ${expectedResponseCode}`).toContainEqual(expectedResponseCode);
});
});
});
});
Expand Down

0 comments on commit d9dce11

Please sign in to comment.