Skip to content

Commit 5e92cea

Browse files
jbl428imdudu1
andcommitted
feat: add http interface decorator
Co-authored-by: imdudu1 <[email protected]>
1 parent 8ca7f4f commit 5e92cea

File tree

9 files changed

+57
-1
lines changed

9 files changed

+57
-1
lines changed

.eslintrc.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ extends:
55
- standard-with-typescript
66
- plugin:@typescript-eslint/recommended
77
- plugin:prettier/recommended
8-
overrides: [ ]
8+
overrides:
9+
- files: [ 'vitest.config.ts', 'global.vitest.ts' ]
10+
parser: '@typescript-eslint/parser'
11+
parserOptions:
12+
project: 'tsconfig.spec.json'
913
parserOptions:
1014
project: 'tsconfig.json'
1115
ecmaVersion: latest

global.vitest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "reflect-metadata";

lib/decorators/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const HTTP_INTERFACE_METADATA = Symbol("HTTP_INTERFACE_METADATA");
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { describe, test, expect } from "vitest";
2+
import { HTTP_INTERFACE_METADATA } from "./constants";
3+
import { HttpInterface } from "./http-interface.decorator";
4+
5+
describe("HttpInterface", () => {
6+
test("should set default url metadata", () => {
7+
// given
8+
@HttpInterface()
9+
class TestService {}
10+
11+
// when
12+
const result = Reflect.getMetadata(HTTP_INTERFACE_METADATA, TestService);
13+
14+
// then
15+
expect(result).toBe("");
16+
});
17+
18+
test("should set provided url metadata", () => {
19+
// given
20+
@HttpInterface("/api/v1/sample")
21+
class TestService {}
22+
23+
// when
24+
const result = Reflect.getMetadata(HTTP_INTERFACE_METADATA, TestService);
25+
26+
// then
27+
expect(result).toBe("/api/v1/sample");
28+
});
29+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { HTTP_INTERFACE_METADATA } from "./constants";
2+
3+
export function HttpInterface(url = ""): ClassDecorator {
4+
return (target) => {
5+
Reflect.defineMetadata(HTTP_INTERFACE_METADATA, url, target);
6+
};
7+
}

lib/decorators/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./http-interface.decorator";
2+
export * from "./constants";

lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * from "./decorators";
12
export * from "./http-interface.module";

tsconfig.spec.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["vitest.config.ts", "global.vitest.ts"],
4+
}

vitest.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
setupFiles: "./global.vitest.ts",
6+
},
7+
});

0 commit comments

Comments
 (0)