@@ -106,7 +106,7 @@ test.serial(`processImage fails without a name`, async (t) => {
106106 t . deepEqual ( err , error ) ;
107107} ) ;
108108
109- test . serial ( `processImage processes an image` , async ( t ) => {
109+ test . serial ( `processImage processes an image with Node 6 arguments ` , async ( t ) => {
110110 const event = {
111111 data : {
112112 bucket : bucketName ,
@@ -123,6 +123,21 @@ test.serial(`processImage processes an image`, async (t) => {
123123 t . deepEqual ( console . log . getCall ( 3 ) . args , [ `File ${ event . data . name } processed.` ] ) ;
124124} ) ;
125125
126+ test . serial ( `processImage processes an image with Node 8 arguments` , async ( t ) => {
127+ const data = {
128+ bucket : bucketName ,
129+ name : filename
130+ } ;
131+ const sample = getSample ( ) ;
132+
133+ await sample . program . processImage ( data ) ;
134+ t . is ( console . log . callCount , 4 ) ;
135+ t . deepEqual ( console . log . getCall ( 0 ) . args , [ `Looking for text in image ${ filename } ` ] ) ;
136+ t . deepEqual ( console . log . getCall ( 1 ) . args , [ `Extracted text from image (${ text . length } chars)` ] ) ;
137+ t . deepEqual ( console . log . getCall ( 2 ) . args , [ `Detected language "ja" for ${ filename } ` ] ) ;
138+ t . deepEqual ( console . log . getCall ( 3 ) . args , [ `File ${ data . name } processed.` ] ) ;
139+ } ) ;
140+
126141test . serial ( `translateText fails without text` , async ( t ) => {
127142 const error = new Error ( `Text not provided. Make sure you have a "text" property in your request` ) ;
128143 const event = {
@@ -157,7 +172,7 @@ test.serial(`translateText fails without a lang`, async (t) => {
157172 t . deepEqual ( err , error ) ;
158173} ) ;
159174
160- test . serial ( `translateText translates and publishes text` , async ( t ) => {
175+ test . serial ( `translateText translates and publishes text with Node 6 arguments ` , async ( t ) => {
161176 const event = {
162177 data : {
163178 data : Buffer . from (
@@ -179,6 +194,26 @@ test.serial(`translateText translates and publishes text`, async (t) => {
179194 t . deepEqual ( console . log . secondCall . args , [ `Text translated to ${ lang } ` ] ) ;
180195} ) ;
181196
197+ test . serial ( `translateText translates and publishes text with Node 8 arguments` , async ( t ) => {
198+ const data = {
199+ data : Buffer . from (
200+ JSON . stringify ( {
201+ text,
202+ filename,
203+ lang
204+ } )
205+ ) . toString ( `base64` )
206+ } ;
207+ const sample = getSample ( ) ;
208+
209+ sample . mocks . translate . translate . returns ( Promise . resolve ( [ translation ] ) ) ;
210+
211+ await sample . program . translateText ( data ) ;
212+ t . is ( console . log . callCount , 2 ) ;
213+ t . deepEqual ( console . log . firstCall . args , [ `Translating text into ${ lang } ` ] ) ;
214+ t . deepEqual ( console . log . secondCall . args , [ `Text translated to ${ lang } ` ] ) ;
215+ } ) ;
216+
182217test . serial ( `saveResult fails without text` , async ( t ) => {
183218 const error = new Error ( `Text not provided. Make sure you have a "text" property in your request` ) ;
184219 const event = {
@@ -215,7 +250,7 @@ test.serial(`saveResult fails without a lang`, async (t) => {
215250 t . deepEqual ( err , error ) ;
216251} ) ;
217252
218- test . serial ( `saveResult translates and publishes text` , async ( t ) => {
253+ test . serial ( `saveResult translates and publishes text with Node 6 arguments ` , async ( t ) => {
219254 const event = {
220255 data : {
221256 data : Buffer . from ( JSON . stringify ( { text, filename, lang } ) ) . toString ( `base64` )
@@ -230,6 +265,19 @@ test.serial(`saveResult translates and publishes text`, async (t) => {
230265 t . deepEqual ( console . log . getCall ( 2 ) . args , [ `File saved.` ] ) ;
231266} ) ;
232267
268+ test . serial ( `saveResult translates and publishes text with Node 8 arguments` , async ( t ) => {
269+ const data = {
270+ data : Buffer . from ( JSON . stringify ( { text, filename, lang } ) ) . toString ( `base64` )
271+ } ;
272+ const sample = getSample ( ) ;
273+
274+ await sample . program . saveResult ( data ) ;
275+ t . is ( console . log . callCount , 3 ) ;
276+ t . deepEqual ( console . log . getCall ( 0 ) . args , [ `Received request to save file ${ filename } ` ] ) ;
277+ t . deepEqual ( console . log . getCall ( 1 ) . args , [ `Saving result to ${ filename } _to_${ lang } .txt in bucket ${ sample . mocks . config . RESULT_BUCKET } ` ] ) ;
278+ t . deepEqual ( console . log . getCall ( 2 ) . args , [ `File saved.` ] ) ;
279+ } ) ;
280+
233281test . serial ( `saveResult translates and publishes text with dot in filename` , async ( t ) => {
234282 const event = {
235283 data : {
0 commit comments