1
- import { ActionParameterHandler } from " ../src/ActionParameterHandler" ;
2
- import { ActionMetadata , ControllerMetadata , ExpressDriver , ParamMetadata } from " ../src" ;
3
- import { ActionMetadataArgs } from " ../src/metadata/args/ActionMetadataArgs" ;
4
- import { ControllerMetadataArgs } from " ../src/metadata/args/ControllerMetadataArgs" ;
5
- import { ParamType } from " ../src/metadata/types/ParamType" ;
1
+ import { ActionParameterHandler } from ' ../src/ActionParameterHandler' ;
2
+ import { ActionMetadata , ControllerMetadata , ExpressDriver , ParamMetadata } from ' ../src' ;
3
+ import { ActionMetadataArgs } from ' ../src/metadata/args/ActionMetadataArgs' ;
4
+ import { ControllerMetadataArgs } from ' ../src/metadata/args/ControllerMetadataArgs' ;
5
+ import { ParamType } from ' ../src/metadata/types/ParamType' ;
6
6
7
- const expect = require ( " chakram" ) . expect ;
7
+ const expect = require ( ' chakram' ) . expect ;
8
8
9
- describe ( " ActionParameterHandler" , ( ) => {
9
+ describe ( ' ActionParameterHandler' , ( ) => {
10
10
const buildParamMetadata = (
11
- name : string = "id" ,
12
- type : ParamType = " param" ,
13
- isRequired : boolean = false ,
11
+ name : string = 'id' ,
12
+ type : ParamType = ' param' ,
13
+ isRequired : boolean = false
14
14
) : ParamMetadata => {
15
15
const controllerMetadataArgs : ControllerMetadataArgs = {
16
- target : function ( ) {
17
- } ,
18
- route : "" ,
19
- type : "json" ,
16
+ target : function ( ) { } ,
17
+ route : '' ,
18
+ type : 'json' ,
20
19
options : { } ,
21
20
} ;
22
21
const controllerMetadata = new ControllerMetadata ( controllerMetadataArgs ) ;
23
22
const args : ActionMetadataArgs = {
24
- route : "" ,
25
- method : " getProduct" ,
23
+ route : '' ,
24
+ method : ' getProduct' ,
26
25
options : { } ,
27
- target : function ( ) {
28
- } ,
29
- type : "get" ,
26
+ target : function ( ) { } ,
27
+ type : 'get' ,
30
28
appendParams : undefined ,
31
29
} ;
32
30
const actionMetadata = new ActionMetadata ( controllerMetadata , args , { } ) ;
33
31
34
32
return {
35
33
type,
36
34
name,
37
- targetName : " product" ,
35
+ targetName : ' product' ,
38
36
isTargetObject : true ,
39
37
actionMetadata,
40
- target : ( ) => {
41
- } ,
42
- method : "getProduct" ,
43
- object : "getProduct" ,
38
+ target : ( ) => { } ,
39
+ method : 'getProduct' ,
40
+ object : 'getProduct' ,
44
41
extraOptions : undefined ,
45
42
index : 0 ,
46
43
parse : undefined ,
@@ -50,20 +47,19 @@ describe("ActionParameterHandler", () => {
50
47
} ,
51
48
classTransform : undefined ,
52
49
validate : undefined ,
53
- targetType : function ( ) {
54
- } ,
50
+ targetType : function ( ) { } ,
55
51
} ;
56
52
} ;
57
53
58
- it ( " handle - should process string parameters" , async ( ) => {
54
+ it ( ' handle - should process string parameters' , async ( ) => {
59
55
const driver = new ExpressDriver ( ) ;
60
56
const actionParameterHandler = new ActionParameterHandler ( driver ) ;
61
- const param = buildParamMetadata ( " uuid" ) ;
57
+ const param = buildParamMetadata ( ' uuid' ) ;
62
58
63
59
const action = {
64
60
request : {
65
61
params : {
66
- uuid : " 0b5ec98f-e26d-4414-b798-dcd35a5ef859" ,
62
+ uuid : ' 0b5ec98f-e26d-4414-b798-dcd35a5ef859' ,
67
63
} ,
68
64
} ,
69
65
response : { } ,
@@ -74,15 +70,15 @@ describe("ActionParameterHandler", () => {
74
70
expect ( processedValue ) . to . be . eq ( action . request . params . uuid ) ;
75
71
} ) ;
76
72
77
- it ( " handle - should process string parameters, returns empty if a given string is empty" , async ( ) => {
73
+ it ( ' handle - should process string parameters, returns empty if a given string is empty' , async ( ) => {
78
74
const driver = new ExpressDriver ( ) ;
79
75
const actionParameterHandler = new ActionParameterHandler ( driver ) ;
80
- const param = buildParamMetadata ( " uuid" ) ;
76
+ const param = buildParamMetadata ( ' uuid' ) ;
81
77
82
78
const action = {
83
79
request : {
84
80
params : {
85
- uuid : "" ,
81
+ uuid : '' ,
86
82
} ,
87
83
} ,
88
84
response : { } ,
@@ -93,10 +89,10 @@ describe("ActionParameterHandler", () => {
93
89
expect ( processedValue ) . to . be . eq ( action . request . params . uuid ) ;
94
90
} ) ;
95
91
96
- it ( " handle - should process number parameters" , async ( ) => {
92
+ it ( ' handle - should process number parameters' , async ( ) => {
97
93
const driver = new ExpressDriver ( ) ;
98
94
const actionParameterHandler = new ActionParameterHandler ( driver ) ;
99
- const param = buildParamMetadata ( "id" ) ;
95
+ const param = buildParamMetadata ( 'id' ) ;
100
96
101
97
const action = {
102
98
request : {
@@ -112,7 +108,7 @@ describe("ActionParameterHandler", () => {
112
108
expect ( processedValue ) . to . be . eq ( action . request . params . id ) ;
113
109
} ) ;
114
110
115
- it ( " handle - undefined on empty object provided" , async ( ) => {
111
+ it ( ' handle - undefined on empty object provided' , async ( ) => {
116
112
const driver = new ExpressDriver ( ) ;
117
113
const actionParameterHandler = new ActionParameterHandler ( driver ) ;
118
114
const param = buildParamMetadata ( ) ;
@@ -129,10 +125,10 @@ describe("ActionParameterHandler", () => {
129
125
expect ( processedValue ) . to . be . eq ( undefined ) ;
130
126
} ) ;
131
127
132
- it ( " handle - throws error if the parameter is required" , async ( ) => {
128
+ it ( ' handle - throws error if the parameter is required' , async ( ) => {
133
129
const driver = new ExpressDriver ( ) ;
134
130
const actionParameterHandler = new ActionParameterHandler ( driver ) ;
135
- const param = buildParamMetadata ( " uuid" , " param" , true ) ;
131
+ const param = buildParamMetadata ( ' uuid' , ' param' , true ) ;
136
132
137
133
const action = {
138
134
request : { } ,
@@ -146,13 +142,13 @@ describe("ActionParameterHandler", () => {
146
142
error = e ;
147
143
}
148
144
149
- expect ( error . toString ( ) ) . to . be . eq ( ' TypeError: Cannot read property \ 'uuid\ ' of undefined' ) ;
145
+ expect ( error . toString ( ) ) . to . be . eq ( " TypeError: Cannot read property 'uuid' of undefined" ) ;
150
146
} ) ;
151
147
152
- it ( " handle - throws error if the parameter is required, type file provided" , async ( ) => {
148
+ it ( ' handle - throws error if the parameter is required, type file provided' , async ( ) => {
153
149
const driver = new ExpressDriver ( ) ;
154
150
const actionParameterHandler = new ActionParameterHandler ( driver ) ;
155
- const param = buildParamMetadata ( " uuid" , " file" , true ) ;
151
+ const param = buildParamMetadata ( ' uuid' , ' file' , true ) ;
156
152
157
153
const action = {
158
154
request : { } ,
@@ -167,8 +163,7 @@ describe("ActionParameterHandler", () => {
167
163
}
168
164
169
165
expect ( error . httpCode ) . to . be . eq ( 400 ) ;
170
- expect ( error . name ) . to . be . eq ( " ParamRequiredError" ) ;
171
- expect ( error . message ) . to . be . eq ( " Uploaded file \ "uuid\ " is required for request on undefined undefined" ) ;
166
+ expect ( error . name ) . to . be . eq ( ' ParamRequiredError' ) ;
167
+ expect ( error . message ) . to . be . eq ( ' Uploaded file "uuid" is required for request on undefined undefined' ) ;
172
168
} ) ;
173
-
174
169
} ) ;
0 commit comments