Skip to content

Commit

Permalink
feat(schema): add test for unsupported decorator types
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 d94c1db commit 56f3452
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions packages/specs/schema/src/decorators/operations/deprecated.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Deprecated, getSpec, OperationPath, Returns, SpecTypes} from "@tsed/schema";
import {QueryParams} from "@tsed/platform-params";
import {catchError} from "@tsed/core";

describe("Deprecated", () => {
it("should store metadata (swagger)", () => {
Expand Down Expand Up @@ -208,4 +209,14 @@ describe("Deprecated", () => {
}
});
});
it("should throw an error when the decorator is as static func decorator", () => {
const error = catchError(() => {
class Model {
@Deprecated(true)
static myStaticFunc() {}
}
});

expect(error?.message).toEqual("Deprecated cannot be used as method.static decorator on Model.myStaticFunc");
});
});
4 changes: 2 additions & 2 deletions packages/specs/schema/src/decorators/operations/deprecated.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {decorateMethodsOf, DecoratorTypes, UnsupportedDecoratorType} from "@tsed/core";
import {decorateMethodsOf, decoratorTypeOf, DecoratorTypes, UnsupportedDecoratorType} from "@tsed/core";
import {JsonEntityFn} from "../common/jsonEntityFn";
import {JsonPropertyStore} from "../../domain/JsonPropertyStore";
import {JsonParameterStore} from "../../domain/JsonParameterStore";
Expand Down Expand Up @@ -27,7 +27,7 @@ import {JsonParameterStore} from "../../domain/JsonParameterStore";
*/
export function Deprecated(deprecated: boolean = true) {
return JsonEntityFn((store, args) => {
switch (store.decoratorType) {
switch (decoratorTypeOf(args)) {
case DecoratorTypes.METHOD:
store.operation!.deprecated(deprecated);
break;
Expand Down

0 comments on commit 56f3452

Please sign in to comment.