@@ -6,14 +6,18 @@ describe('XmlBodyParser', () => {
6
6
const rules : Member = {
7
7
resultWrapper : 'OperationResult' ,
8
8
shape : {
9
- type : 'string'
9
+ type : 'structure' ,
10
+ required : [ ] ,
11
+ members : {
12
+ Str : { shape : { type : 'string' } }
13
+ }
10
14
}
11
15
}
12
16
const parser = new XmlBodyParser ( jest . fn ( ) ) ;
13
17
it ( 'should wrap the shap with a structure with wrapper name as member name' , ( ) => {
14
- let xml = '<xml><OperationResult>foo</OperationResult></xml>' ;
18
+ let xml = '<xml><OperationResult><Str> foo</Str> </OperationResult></xml>' ;
15
19
expect ( parser . parse ( rules , xml ) ) . toEqual ( {
16
- OperationResult : 'foo'
20
+ Str : 'foo'
17
21
} ) ;
18
22
} )
19
23
} ) ;
@@ -295,6 +299,30 @@ describe('XmlBodyParser', () => {
295
299
} ) ;
296
300
} ) ;
297
301
302
+ it ( 'should parse flattened list with only 1 item' , ( ) => {
303
+ let xml = '<xml><Items>Jack</Items></xml>' ;
304
+ let rules : Member = {
305
+ shape : {
306
+ type : "structure" ,
307
+ required : [ ] ,
308
+ members : {
309
+ Items : {
310
+ shape : {
311
+ type : "list" ,
312
+ member : {
313
+ shape : { type : "string" } ,
314
+ } ,
315
+ flattened : true
316
+ } ,
317
+ }
318
+ }
319
+ }
320
+ }
321
+ expect ( parser . parse ( rules , xml ) ) . toEqual ( {
322
+ Items : [ 'Jack' ]
323
+ } ) ;
324
+ } ) ;
325
+
298
326
it ( 'should parse list with attributes in tags' , ( ) => {
299
327
let xml = '<xml><Item xsi:name="Jon"><Age>20</Age></Item><Item xsi:name="Lee"><Age>18</Age></Item></xml>' ;
300
328
let rules : Member = {
@@ -580,15 +608,15 @@ describe('XmlBodyParser', () => {
580
608
expect ( parser . parse ( rules , xml ) ) . toEqual ( {
581
609
CreatedAt : new Date ( rfcString )
582
610
} ) ;
583
- } )
611
+ } ) ;
584
612
585
613
it ( 'should parse unixTimestamp' , ( ) => {
586
614
let unixTime = 1398796238 ;
587
615
let xml = `<xml><CreatedAt>${ unixTime } </CreatedAt></xml>` ;
588
616
expect ( parser . parse ( rules , xml ) ) . toEqual ( {
589
617
CreatedAt : new Date ( unixTime * 1000 )
590
618
} ) ;
591
- } )
619
+ } ) ;
592
620
} ) ;
593
621
594
622
describe ( 'string' , ( ) => {
@@ -797,20 +825,24 @@ describe('XmlBodyParser', () => {
797
825
it ( 'should extract requestId from non-EC2 response body' , ( ) => {
798
826
let rules : Member = {
799
827
shape : {
800
- type : 'string'
828
+ type : 'structure' ,
829
+ required : [ ] ,
830
+ members : {
831
+ Str : { shape : { type : 'string' } }
832
+ }
801
833
} ,
802
834
resultWrapper : 'QueryResult'
803
835
}
804
836
const xml = `
805
837
<OperationNameResponse>
806
- <QueryResult>foo</QueryResult>
838
+ <QueryResult><Str> foo</Str> </QueryResult>
807
839
<ResponseMetadata>
808
840
<RequestId>request-id</RequestId>
809
841
</ResponseMetadata>
810
842
</OperationNameResponse>
811
843
`
812
844
expect ( parser . parse ( rules , xml ) ) . toEqual ( {
813
- QueryResult : 'foo' ,
845
+ Str : 'foo' ,
814
846
$metadata : {
815
847
requestId : 'request-id'
816
848
}
0 commit comments