@@ -50,120 +50,107 @@ describe('ActionParameterHandler', () => {
5050 targetType : function ( ) { } ,
5151 } ;
5252 } ;
53-
54- it ( 'handle - should process string parameters' , async ( ) => {
55- const driver = new ExpressDriver ( ) ;
56- const actionParameterHandler = new ActionParameterHandler ( driver ) ;
57- const param = buildParamMetadata ( 'uuid' ) ;
58-
59- const action = {
60- request : {
61- params : {
62- uuid : '0b5ec98f-e26d-4414-b798-dcd35a5ef859' ,
53+ const driver = new ExpressDriver ( ) ;
54+ const actionParameterHandler = new ActionParameterHandler ( driver ) ;
55+
56+ describe ( 'positive' , ( ) => {
57+ it ( 'handle - should process string parameters' , async ( ) => {
58+ const param = buildParamMetadata ( 'uuid' ) ;
59+ const action = {
60+ request : {
61+ params : {
62+ uuid : '0b5ec98f-e26d-4414-b798-dcd35a5ef859' ,
63+ } ,
6364 } ,
64- } ,
65- response : { } ,
66- } ;
65+ response : { } ,
66+ } ;
6767
68- const processedValue = await actionParameterHandler . handle ( action , param ) ;
68+ const processedValue = await actionParameterHandler . handle ( action , param ) ;
6969
70- expect ( processedValue ) . to . be . eq ( action . request . params . uuid ) ;
71- } ) ;
72-
73- it ( 'handle - should process string parameters, returns empty if a given string is empty' , async ( ) => {
74- const driver = new ExpressDriver ( ) ;
75- const actionParameterHandler = new ActionParameterHandler ( driver ) ;
76- const param = buildParamMetadata ( 'uuid' ) ;
70+ expect ( processedValue ) . to . be . eq ( action . request . params . uuid ) ;
71+ } ) ;
7772
78- const action = {
79- request : {
80- params : {
81- uuid : '' ,
73+ it ( 'handle - should process string parameters, returns empty if a given string is empty' , async ( ) => {
74+ const param = buildParamMetadata ( 'uuid' ) ;
75+ const action = {
76+ request : {
77+ params : {
78+ uuid : '' ,
79+ } ,
8280 } ,
83- } ,
84- response : { } ,
85- } ;
86-
87- const processedValue = await actionParameterHandler . handle ( action , param ) ;
81+ response : { } ,
82+ } ;
8883
89- expect ( processedValue ) . to . be . eq ( action . request . params . uuid ) ;
90- } ) ;
84+ const processedValue = await actionParameterHandler . handle ( action , param ) ;
9185
92- it ( 'handle - should process number parameters' , async ( ) => {
93- const driver = new ExpressDriver ( ) ;
94- const actionParameterHandler = new ActionParameterHandler ( driver ) ;
95- const param = buildParamMetadata ( 'id' ) ;
86+ expect ( processedValue ) . to . be . eq ( action . request . params . uuid ) ;
87+ } ) ;
9688
97- const action = {
98- request : {
99- params : {
100- id : 10000 ,
89+ it ( 'handle - should process number parameters' , async ( ) => {
90+ const param = buildParamMetadata ( 'id' ) ;
91+ const action = {
92+ request : {
93+ params : {
94+ id : 10000 ,
95+ } ,
10196 } ,
102- } ,
103- response : { } ,
104- } ;
105-
106- const processedValue = await actionParameterHandler . handle ( action , param ) ;
107-
108- expect ( processedValue ) . to . be . eq ( action . request . params . id ) ;
109- } ) ;
110-
111- it ( 'handle - undefined on empty object provided' , async ( ) => {
112- const driver = new ExpressDriver ( ) ;
113- const actionParameterHandler = new ActionParameterHandler ( driver ) ;
114- const param = buildParamMetadata ( ) ;
97+ response : { } ,
98+ } ;
11599
116- const action = {
117- request : {
118- params : { } ,
119- } ,
120- response : { } ,
121- } ;
122-
123- const processedValue = await actionParameterHandler . handle ( action , param ) ;
124-
125- expect ( processedValue ) . to . be . eq ( undefined ) ;
126- } ) ;
100+ const processedValue = await actionParameterHandler . handle ( action , param ) ;
127101
128- it ( 'handle - throws error if the parameter is required' , async ( ) => {
129- const driver = new ExpressDriver ( ) ;
130- const actionParameterHandler = new ActionParameterHandler ( driver ) ;
131- const param = buildParamMetadata ( 'uuid' , 'param' , true ) ;
102+ expect ( processedValue ) . to . be . eq ( action . request . params . id ) ;
103+ } ) ;
132104
133- const action = {
134- request : { } ,
135- response : { } ,
136- } ;
137- let error ;
105+ it ( 'handle - undefined on empty object provided' , async ( ) => {
106+ const param = buildParamMetadata ( ) ;
107+ const action = {
108+ request : {
109+ params : { } ,
110+ } ,
111+ response : { } ,
112+ } ;
138113
139- try {
140- await actionParameterHandler . handle ( action , param ) ;
141- } catch ( e ) {
142- error = e ;
143- }
114+ const processedValue = await actionParameterHandler . handle ( action , param ) ;
144115
145- expect ( error . toString ( ) ) . to . be . eq ( "TypeError: Cannot read property 'uuid' of undefined" ) ;
116+ expect ( processedValue ) . to . be . eq ( undefined ) ;
117+ } ) ;
146118 } ) ;
147-
148- it ( 'handle - throws error if the parameter is required, type file provided' , async ( ) => {
149- const driver = new ExpressDriver ( ) ;
150- const actionParameterHandler = new ActionParameterHandler ( driver ) ;
151- const param = buildParamMetadata ( 'uuid' , 'file' , true ) ;
152-
153- const action = {
154- request : { } ,
155- response : { } ,
156- } ;
157- let error ;
158-
159- try {
160- await actionParameterHandler . handle ( action , param ) ;
161- } catch ( e ) {
162- error = e ;
163- }
164-
165- expect ( error . httpCode ) . to . be . eq ( 400 ) ;
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' ) ;
119+ describe ( 'negative' , ( ) => {
120+ it ( 'handle - throws error if the parameter is required' , async ( ) => {
121+ const param = buildParamMetadata ( 'uuid' , 'param' , true ) ;
122+ const action = {
123+ request : { } ,
124+ response : { } ,
125+ } ;
126+ let error ;
127+
128+ try {
129+ await actionParameterHandler . handle ( action , param ) ;
130+ } catch ( e ) {
131+ error = e ;
132+ }
133+
134+ expect ( error . toString ( ) ) . to . be . eq ( "TypeError: Cannot read property 'uuid' of undefined" ) ;
135+ } ) ;
136+
137+ it ( 'handle - throws error if the parameter is required, type file provided' , async ( ) => {
138+ const param = buildParamMetadata ( 'uuid' , 'file' , true ) ;
139+ const action = {
140+ request : { } ,
141+ response : { } ,
142+ } ;
143+ let error ;
144+
145+ try {
146+ await actionParameterHandler . handle ( action , param ) ;
147+ } catch ( e ) {
148+ error = e ;
149+ }
150+
151+ expect ( error . httpCode ) . to . be . eq ( 400 ) ;
152+ expect ( error . name ) . to . be . eq ( 'ParamRequiredError' ) ;
153+ expect ( error . message ) . to . be . eq ( 'Uploaded file "uuid" is required for request on undefined undefined' ) ;
154+ } ) ;
168155 } ) ;
169156} ) ;
0 commit comments