Skip to content

Commit fab6074

Browse files
committed
Add HTTP method PATH
1 parent 968db77 commit fab6074

5 files changed

Lines changed: 37 additions & 1 deletion

File tree

src/common/enums/request-method.enum.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ export enum RequestMethod {
33
POST,
44
PUT,
55
DELETE,
6+
PATCH,
67
ALL,
78
}

src/common/test/utils/route-params.decorator.spec.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'reflect-metadata';
22
import { expect } from 'chai';
33
import { RequestMethod } from '../../enums/request-method.enum';
4-
import { Get, Post, Delete, All, Put } from '../../index';
4+
import { Get, Post, Delete, All, Put, Patch } from '../../index';
55

66
describe('@Get', () => {
77
const requestPath = 'test';
@@ -156,4 +156,35 @@ describe('@Put', () => {
156156
expect(path).to.be.eql('/');
157157
});
158158

159+
});
160+
161+
describe('@Patch', () => {
162+
const requestPath = 'test';
163+
const requestProps = {
164+
path: requestPath,
165+
method: RequestMethod.PATCH,
166+
};
167+
168+
it('should enhance class with expected request metadata', () => {
169+
class Test {
170+
@Patch(requestPath)
171+
public static test() {}
172+
}
173+
174+
const path = Reflect.getMetadata('path', Test.test);
175+
const method = Reflect.getMetadata('method', Test.test);
176+
177+
expect(method).to.be.eql(requestProps.method);
178+
expect(path).to.be.eql(requestPath);
179+
});
180+
181+
it('should set path on "/" by default', () => {
182+
class Test {
183+
@Patch()
184+
public static test() {}
185+
}
186+
const path = Reflect.getMetadata('path', Test.test);
187+
expect(path).to.be.eql('/');
188+
});
189+
159190
});

src/common/utils/decorators/request-mapping.decorator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ export const Post = createMappingDecorator(RequestMethod.POST);
3030
export const Get = createMappingDecorator(RequestMethod.GET);
3131
export const Delete = createMappingDecorator(RequestMethod.DELETE);
3232
export const Put = createMappingDecorator(RequestMethod.PUT);
33+
export const Patch = createMappingDecorator(RequestMethod.PATCH);
3334
export const All = createMappingDecorator(RequestMethod.ALL);
3435

src/core/helpers/router-method-factory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export class RouterMethodFactory {
77
case RequestMethod.ALL: return target.all;
88
case RequestMethod.DELETE: return target.delete;
99
case RequestMethod.PUT: return target.put;
10+
case RequestMethod.PATCH: return target.patch;
1011
default: {
1112
return target.get;
1213
}

src/core/test/helpers/router-method-factory.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('RouterMethodFactory', () => {
1010
all: () => {},
1111
delete: () => {},
1212
put: () => {},
13+
patch: () => {},
1314
};
1415
beforeEach(() => {
1516
factory = new RouterMethodFactory();
@@ -21,5 +22,6 @@ describe('RouterMethodFactory', () => {
2122
expect(factory.get(target, RequestMethod.ALL)).to.equal(target.all);
2223
expect(factory.get(target, RequestMethod.PUT)).to.equal(target.put);
2324
expect(factory.get(target, RequestMethod.GET)).to.equal(target.get);
25+
expect(factory.get(target, RequestMethod.PATCH)).to.equal(target.patch);
2426
});
2527
});

0 commit comments

Comments
 (0)