Skip to content

Commit e28609b

Browse files
committed
feat(core): add missing tests
1 parent 3ab73ed commit e28609b

39 files changed

+1125
-74
lines changed

packages/core/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
"rou3": "0.7.3",
3333
"srvx": "0.8.6"
3434
},
35+
"devDependencies": {
36+
"zod": "4.0.17"
37+
},
3538
"publishConfig": {
3639
"access": "public"
3740
}

packages/core/src/Decorators/Http/Get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class GetDecorator extends BaseDecorator<GetDecoratorOptions> {
3434
* This method constructs the full path for the route, registers the route
3535
* with the Router, and sets up the event handler for the GET request.
3636
*/
37-
public override created(): void {
37+
public override created(): void {
3838
initializeMetadata(this.prototype);
3939
const method = initializeMetadataMethod(this.prototype, this.propertyName);
4040
method.method = 'GET';

packages/core/src/Decorators/Http/Middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BaseMiddleware } from '../../Services/Middleware/BaseMiddleware';
33
import { MetadataTypes } from '../../Types/MetadataTypes';
44
import { initializeMetadata } from '../../Utils/Utils';
55

6-
interface MiddlewareDecoratorParams extends Omit<MetadataTypes.Middleware, 'middleware'> {
6+
interface MiddlewareDecoratorParams extends Omit<MetadataTypes.Middleware, 'middleware' | 'target'> {
77
}
88

99
/**

packages/core/src/Decorators/Http/Session.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

packages/core/src/Services/Metadata/MetadataResolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class MetadataResolver {
1616
* @param {MetadataTypes.ResolveUrlParams} params - The parameters for resolving the URL.
1717
* @return {string} The resolved URL.
1818
*/
19-
public resolveUrl(params: MetadataTypes.ResolveUrlParams): string {
19+
public resolveUrl(params: MetadataTypes.ResolveUrlParams): string {
2020
const { instance, propertyName, path: rawPath } = params;
2121
const metadata = instance.__metadata as MetadataTypes.Ctx;
2222
const basePath = (metadata?.__controller?.path ?? '').replace(/\/$/, '');

packages/core/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export * from './Decorators/Http/Status';
3030
export * from './Decorators/Http/Redirect';
3131
export * from './Decorators/Http/Middleware';
3232
export * from './Decorators/Http/MultipartFormData';
33-
export * from './Decorators/Http/Session';
3433

3534
// Hooks
3635
export * from './Decorators/Hooks/Listen';
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { describe, it, expect, beforeAll } from "vitest";
2+
import { createTestApp } from "../../Utils/App.mock";
3+
import { MockController } from "../../Utils/MockController.mock";
4+
import { initializeMetadata } from "../../../src";
5+
6+
7+
describe('Body Decorator', () => {
8+
9+
beforeAll(async () => {
10+
await createTestApp();
11+
});
12+
13+
14+
it(`should add body to metadata`, () => {
15+
const meta = initializeMetadata(MockController.prototype);
16+
17+
expect(meta.__methods['body']).toBeDefined();
18+
expect(meta.__methods['body'].args[0].type).toBe('body');
19+
expect(meta.__methods['body'].args[0].validate).toBe(false);
20+
expect(meta.__methods['body'].args[0].validationSchema).toBeUndefined();
21+
});
22+
23+
it(`should add body validation to metadata`, () => {
24+
const meta = initializeMetadata(MockController.prototype);
25+
26+
expect(meta.__methods['bodyValidation']).toBeDefined();
27+
expect(meta.__methods['bodyValidation'].args[0].type).toBe('body');
28+
expect(meta.__methods['bodyValidation'].args[0].validate).toBe(true);
29+
expect(meta.__methods['bodyValidation'].args[0].validationSchema).toBeDefined();
30+
});
31+
32+
});
33+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { describe, it, expect, beforeAll } from "vitest";
2+
import { createTestApp } from "../../Utils/App.mock";
3+
import { MockController } from "../../Utils/MockController.mock";
4+
import { initializeMetadata } from "../../../src";
5+
6+
7+
describe('Controller Decorator', () => {
8+
9+
beforeAll(async () => {
10+
await createTestApp();
11+
});
12+
13+
14+
it(`should add body to metadata`, () => {
15+
const meta = initializeMetadata(MockController.prototype);
16+
17+
expect(meta.__controller).toBeDefined();
18+
expect(meta.__controller.path).toBe('/mock');
19+
});
20+
21+
});
22+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { describe, it, expect, beforeAll } from "vitest";
2+
import { createTestApp } from "../../Utils/App.mock";
3+
import { MockController } from "../../Utils/MockController.mock";
4+
import { initializeMetadata } from "../../../src";
5+
6+
7+
describe('Header Decorator', () => {
8+
9+
beforeAll(async () => {
10+
await createTestApp();
11+
});
12+
13+
14+
it(`should add body to metadata`, () => {
15+
const meta = initializeMetadata(MockController.prototype);
16+
17+
expect(meta.__methods['header']).toBeDefined();
18+
expect(meta.__methods['header'].args[0].type).toBe('header');
19+
expect(meta.__methods['header'].args[0].data?.name).toBe('x-test');
20+
});
21+
22+
});
23+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { describe, it, expect, beforeAll } from "vitest";
2+
import { createTestApp } from "../../Utils/App.mock";
3+
import { MockController } from "../../Utils/MockController.mock";
4+
import { initializeMetadata } from "../../../src";
5+
6+
7+
describe('Header Decorator', () => {
8+
9+
beforeAll(async () => {
10+
await createTestApp();
11+
});
12+
13+
14+
it(`should add body to metadata`, () => {
15+
const meta = initializeMetadata(MockController.prototype);
16+
17+
expect(meta.__methods['headers']).toBeDefined();
18+
expect(meta.__methods['headers'].args[0].type).toBe('headers');
19+
});
20+
21+
});
22+

0 commit comments

Comments
 (0)