Skip to content

Commit

Permalink
feat(schema): add tests for deprecated param and prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto Geuke authored and Romakita committed Sep 8, 2022
1 parent ab4c092 commit d94c1db
Showing 1 changed file with 99 additions and 10 deletions.
109 changes: 99 additions & 10 deletions packages/specs/schema/src/decorators/operations/deprecated.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Deprecated, getSpec, OperationPath, SpecTypes} from "@tsed/schema";
import {Deprecated, getSpec, OperationPath, Returns, SpecTypes} from "@tsed/schema";
import {QueryParams} from "@tsed/platform-params";

describe("Deprecated", () => {
it("should store metadata (swagger)", () => {
Expand Down Expand Up @@ -105,18 +106,106 @@ describe("Deprecated", () => {
}
});
});
it("should throw error for unsupported usage", () => {
class Test {
test() {}
it("should store metadata (param)", () => {
class MyController {
@OperationPath("GET", "/")
get(@QueryParams("param") @Deprecated(true) param: string) {}
}

expect(getSpec(MyController)).toEqual({
tags: [
{
name: "MyController"
}
],
paths: {
"/": {
get: {
operationId: "myControllerGet",
parameters: [
{
deprecated: true,
in: "query",
name: "param",
required: false,
schema: {
type: "string"
}
}
],
responses: {
"200": {
description: "Success"
}
},
tags: ["MyController"]
}
}
}
});
});
it("should store metadata (prop)", () => {
class MyModel {
@Deprecated()
myProp: string;
}

let actualError: any;
try {
Deprecated()(Test.prototype, "test", 0);
} catch (er) {
actualError = er;
class MyController {
@OperationPath("GET", "/")
@Returns(200, MyModel)
get(@QueryParams("param") @Deprecated(true) param: string) {}
}

expect(actualError.message).toEqual("Deprecated cannot be used as parameter decorator on Test.test.[0]");
expect(getSpec(MyController)).toEqual({
tags: [
{
name: "MyController"
}
],
paths: {
"/": {
get: {
operationId: "myControllerGet",
parameters: [
{
deprecated: true,
in: "query",
name: "param",
required: false,
schema: {
type: "string"
}
}
],
responses: {
"200": {
description: "Success",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/MyModel"
}
}
}
}
},
tags: ["MyController"]
}
}
},
components: {
schemas: {
MyModel: {
type: "object",
properties: {
myProp: {
type: "string",
deprecated: true
}
}
}
}
}
});
});
});

0 comments on commit d94c1db

Please sign in to comment.