@@ -23,11 +23,16 @@ describe('buildRequest - openapi 2.0', () => {
2323 parameters : {
2424 'formData.hhlContent:sort' : 'id' ,
2525 'formData.hhlContent:order' : 'desc' ,
26- 'formData.email[]' : [ "person1" , "person2" ] // eslint-disable-line quotes
26+ 'formData.email[]' : [ "person1" , "person2" ] , // eslint-disable-line quotes
27+ 'formData.none[]' : [ 'foo' , 'bar' ] ,
28+ 'formData.csv[]' : [ 'foo' , 'bar' ] ,
29+ 'formData.tsv[]' : [ 'foo' , 'bar' ] ,
30+ 'formData.ssv[]' : [ 'foo' , 'bar' ] ,
31+ 'formData.pipes[]' : [ 'foo' , 'bar' ] ,
2732 }
2833 } )
2934
30- test ( 'should return FormData entry list and entry item entries (in order) ' , ( ) => {
35+ test ( 'should return appropriate response media type ' , ( ) => {
3136 expect ( req ) . toMatchObject ( {
3237 method : 'POST' ,
3338 url : '/api/v1/land/content/ViewOfAuthOwner' ,
@@ -36,14 +41,50 @@ describe('buildRequest - openapi 2.0', () => {
3641 'Content-Type' : 'multipart/form-data'
3742 } ,
3843 } )
44+ } )
45+
46+ test ( 'should build request body as FormData' , ( ) => {
3947 const validateFormDataInstance = req . body instanceof FormData
4048 expect ( validateFormDataInstance ) . toEqual ( true )
49+ } )
50+
51+ test ( 'should return "collectionFormat: multi" as FormData entry list and entry item entries (in order)' , ( ) => {
4152 const itemEntries = req . body . getAll ( 'email[]' )
4253 expect ( itemEntries . length ) . toEqual ( 2 )
4354 expect ( itemEntries [ 0 ] ) . toEqual ( 'person1' )
4455 expect ( itemEntries [ 1 ] ) . toEqual ( 'person2' )
4556 } )
4657
58+ test ( 'should return "collectionFormat: none" as single FormData entry in csv format' , ( ) => {
59+ const itemEntriesNone = req . body . getAll ( 'none[]' )
60+ expect ( itemEntriesNone . length ) . toEqual ( 1 )
61+ expect ( itemEntriesNone [ 0 ] ) . toEqual ( 'foo,bar' )
62+ } )
63+
64+ test ( 'should return "collectionFormat: csv" as single FormData entry in csv format' , ( ) => {
65+ const itemEntriesCsv = req . body . getAll ( 'csv[]' )
66+ expect ( itemEntriesCsv . length ) . toEqual ( 1 )
67+ expect ( itemEntriesCsv [ 0 ] ) . toEqual ( 'foo,bar' )
68+ } )
69+
70+ test ( 'should return "collectionFormat: tsv" as single FormData entry in tsv format' , ( ) => {
71+ const itemEntriesTsv = req . body . getAll ( 'tsv[]' )
72+ expect ( itemEntriesTsv . length ) . toEqual ( 1 )
73+ expect ( itemEntriesTsv [ 0 ] ) . toEqual ( 'foo%09bar' )
74+ } )
75+
76+ test ( 'should return "collectionFormat: ssv" as single FormData entry in ssv format' , ( ) => {
77+ const itemEntriesSsv = req . body . getAll ( 'ssv[]' )
78+ expect ( itemEntriesSsv . length ) . toEqual ( 1 )
79+ expect ( itemEntriesSsv [ 0 ] ) . toEqual ( 'foo%20bar' )
80+ } )
81+
82+ test ( 'should return "collectionFormat: pipes" as single FormData entry in pipes format' , ( ) => {
83+ const itemEntriesPipes = req . body . getAll ( 'pipes[]' )
84+ expect ( itemEntriesPipes . length ) . toEqual ( 1 )
85+ expect ( itemEntriesPipes [ 0 ] ) . toEqual ( 'foo|bar' )
86+ } )
87+
4788 /**
4889 * Dev test only: assumes local server exists for POST
4990 * Expect server response format: { message: 'ok', data: returnData }
@@ -113,7 +154,7 @@ describe('buildRequest - openapi 3.0', () => {
113154 }
114155 } )
115156
116- test ( 'should return FormData entry list and item entries (in order) ' , ( ) => {
157+ test ( 'should return appropriate response media type ' , ( ) => {
117158 expect ( req ) . toMatchObject ( {
118159 method : 'POST' ,
119160 url : '/api/v1/land/content/ViewOfAuthOwner' ,
@@ -122,13 +163,20 @@ describe('buildRequest - openapi 3.0', () => {
122163 'Content-Type' : 'multipart/form-data'
123164 } ,
124165 } )
166+ } )
167+
168+ test ( 'should build request body as FormData' , ( ) => {
125169 const validateFormDataInstance = req . body instanceof FormData
126170 expect ( validateFormDataInstance ) . toEqual ( true )
171+ } )
172+
173+ test ( 'should return FormData entry list and item entries (in order)' , ( ) => {
127174 const itemEntries = req . body . getAll ( 'email[]' )
128175 expect ( itemEntries . length ) . toEqual ( 2 )
129176 expect ( itemEntries [ 0 ] ) . toEqual ( 'person1' )
130177 expect ( itemEntries [ 1 ] ) . toEqual ( 'person2' )
131178 } )
179+
132180 /**
133181 * Dev test only: assumes local server exists for POST
134182 * Expect server response format: { message: 'ok', data: returnData }
0 commit comments