@@ -13,6 +13,7 @@ import {
1313 toGetObjectRequest2 ,
1414 getObjectFromS3AsStream ,
1515 headS3Object ,
16+ getObjectFromS3AsByteArray ,
1617} from '../../../src/queries/s3' ;
1718
1819import Connector from '../../../src/connectors/s3' ;
@@ -54,6 +55,63 @@ describe('queries/s3.js', () => {
5455 . done ( done ) ;
5556 } ) ;
5657
58+ it ( 'should get object as byte array' , ( done ) => {
59+ const hello = new Uint8Array ( [ 104 , 101 , 108 , 108 , 111 ] ) ;
60+ const stub = sinon . stub ( Connector . prototype , 'getObjectAsByteArray' ) . resolves ( {
61+ Body : hello ,
62+ } ) ;
63+
64+ const uows = [ {
65+ getRequest : {
66+ Key : 'k1' ,
67+ } ,
68+ } ] ;
69+
70+ _ ( uows )
71+ . through ( getObjectFromS3AsByteArray ( ) )
72+ . collect ( )
73+ . tap ( ( collected ) => {
74+ // console.log(JSON.stringify(collected, null, 2));
75+
76+ expect ( stub ) . to . have . been . calledWith ( {
77+ Key : 'k1' ,
78+ } ) ;
79+
80+ expect ( collected . length ) . to . equal ( 1 ) ;
81+ expect ( collected [ 0 ] ) . to . deep . equal ( {
82+ getRequest : {
83+ Key : 'k1' ,
84+ } ,
85+ getResponse : {
86+ Body : hello ,
87+ } ,
88+ } ) ;
89+ } )
90+ . done ( done ) ;
91+ } ) ;
92+ it ( 'should get object as byte array - missing get request field' , ( done ) => {
93+ const hello = new Uint8Array ( [ 104 , 101 , 108 , 108 , 111 ] ) ;
94+ const stub = sinon . stub ( Connector . prototype , 'getObjectAsByteArray' ) . resolves ( {
95+ Body : hello ,
96+ } ) ;
97+
98+ const uows = [ {
99+ // missing get request
100+ } ] ;
101+
102+ _ ( uows )
103+ . through ( getObjectFromS3AsByteArray ( ) )
104+ . collect ( )
105+ . tap ( ( collected ) => {
106+ // console.log(JSON.stringify(collected, null, 2));
107+
108+ expect ( stub ) . to . have . not . been . called ;
109+ expect ( collected . length ) . to . equal ( 1 ) ;
110+ expect ( collected [ 0 ] ) . to . deep . equal ( { } ) ;
111+ } )
112+ . done ( done ) ;
113+ } ) ;
114+
57115 it ( 'should get and split object' , ( done ) => {
58116 sinon . stub ( Connector . prototype , 'getObject' ) . resolves ( GET_RESPONSE ) ;
59117
0 commit comments