@@ -52,7 +52,6 @@ describe("spec plugin - selectors", function(){
5252 } )
5353
5454 describe ( "contentTypeValues" , function ( ) {
55-
5655 it ( "should return { requestContentType, responseContentType } from an operation" , function ( ) {
5756 // Given
5857 let state = fromJS ( {
@@ -77,6 +76,73 @@ describe("spec plugin - selectors", function(){
7776 } )
7877 } )
7978
79+ it ( "should prioritize consumes value first from an operation" , function ( ) {
80+ // Given
81+ let state = fromJS ( {
82+ resolved : {
83+ paths : {
84+ "/one" : {
85+ get : {
86+ "consumes_value" : "one" ,
87+ "parameters" : [ {
88+ "type" : "file"
89+ } ] ,
90+ }
91+ }
92+ }
93+ }
94+ } )
95+
96+ // When
97+ let contentTypes = contentTypeValues ( state , [ "/one" , "get" ] )
98+ // Then
99+ expect ( contentTypes . toJS ( ) . requestContentType ) . toEqual ( "one" )
100+ } )
101+
102+ it ( "should fallback to multipart/form-data if there is no consumes value but there is a file parameter" , function ( ) {
103+ // Given
104+ let state = fromJS ( {
105+ resolved : {
106+ paths : {
107+ "/one" : {
108+ get : {
109+ "parameters" : [ {
110+ "type" : "file"
111+ } ] ,
112+ }
113+ }
114+ }
115+ }
116+ } )
117+
118+ // When
119+ let contentTypes = contentTypeValues ( state , [ "/one" , "get" ] )
120+ // Then
121+ expect ( contentTypes . toJS ( ) . requestContentType ) . toEqual ( "multipart/form-data" )
122+ } )
123+
124+ it ( "should fallback to application/x-www-form-urlencoded if there is no consumes value, no file parameter, but there is a formData parameter" , function ( ) {
125+ // Given
126+ let state = fromJS ( {
127+ resolved : {
128+ paths : {
129+ "/one" : {
130+ get : {
131+ "parameters" : [ {
132+ "type" : "formData"
133+ } ] ,
134+ }
135+ }
136+ }
137+ }
138+ } )
139+
140+ // When
141+ let contentTypes = contentTypeValues ( state , [ "/one" , "get" ] )
142+ // Then
143+ expect ( contentTypes . toJS ( ) . requestContentType ) . toEqual ( "application/x-www-form-urlencoded" )
144+ } )
145+
80146 it ( "should be ok, if no operation found" , function ( ) {
81147 // Given
82148 let state = fromJS ( { } )
0 commit comments