@@ -23,6 +23,7 @@ describe('S3Adapter tests', () => {
2323 } , options ) ) ;
2424 } else {
2525 const bucket = 'FAKE_BUCKET' ;
26+ const region = 'us-east-1' ;
2627
2728 s3 = new S3Adapter ( 'FAKE_ACCESS_KEY' , 'FAKE_SECRET_KEY' , bucket , options ) ;
2829
@@ -36,7 +37,7 @@ describe('S3Adapter tests', () => {
3637 objects [ Key ] = Body ;
3738
3839 return Promise . resolve ( {
39- Location : `https://${ bucket } .s3.amazonaws.com/${ Key } ` ,
40+ Location : `https://${ bucket } .s3.${ region } . amazonaws.com/${ Key } ` ,
4041 } ) ;
4142 }
4243 if ( command instanceof DeleteObjectCommand ) {
@@ -317,7 +318,7 @@ describe('S3Adapter tests', () => {
317318 } ) ;
318319 } ) ;
319320
320- describe ( 'getFileLocation' , ( ) => {
321+ describe ( 'getFileLocation with directAccess ' , ( ) => {
321322 const testConfig = {
322323 mount : 'http://my.server.com/parse' ,
323324 applicationId : 'xxxx' ,
@@ -332,30 +333,30 @@ describe('S3Adapter tests', () => {
332333 } ;
333334 } ) ;
334335
335- it ( 'should get using the baseUrl' , ( ) => {
336+ it ( 'should get using the baseUrl' , async ( ) => {
336337 const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
337- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/foo/bar/test.png' ) ;
338+ expect ( await s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/foo/bar/test.png' ) ;
338339 } ) ;
339340
340- it ( 'should get direct to baseUrl' , ( ) => {
341+ it ( 'should get direct to baseUrl' , async ( ) => {
341342 options . baseUrlDirect = true ;
342343 const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
343- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/test.png' ) ;
344+ expect ( await s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/test.png' ) ;
344345 } ) ;
345346
346- it ( 'should get without directAccess' , ( ) => {
347+ it ( 'should get without directAccess' , async ( ) => {
347348 options . directAccess = false ;
348349 const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
349- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://my.server.com/parse/files/xxxx/test.png' ) ;
350+ expect ( await s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://my.server.com/parse/files/xxxx/test.png' ) ;
350351 } ) ;
351352
352- it ( 'should go directly to amazon' , ( ) => {
353+ it ( 'should go directly to amazon' , async ( ) => {
353354 delete options . baseUrl ;
354355 const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
355- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'https://my-bucket.s3.amazonaws.com/foo/bar/test.png' ) ;
356+ expect ( await s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'https://my-bucket.s3.amazonaws.com/foo/bar/test.png' ) ;
356357 } ) ;
357358 } ) ;
358- describe ( 'getFileLocation' , ( ) => {
359+ describe ( 'getFileLocation with baseUrl ' , ( ) => {
359360 const testConfig = {
360361 mount : 'http://my.server.com/parse' ,
361362 applicationId : 'xxxx' ,
@@ -375,30 +376,30 @@ describe('S3Adapter tests', () => {
375376 } ;
376377 } ) ;
377378
378- it ( 'should get using the baseUrl' , ( ) => {
379+ it ( 'should get using the baseUrl' , async ( ) => {
379380 const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
380- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/foo/bar/test.png' ) ;
381+ expect ( await s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/foo/bar/test.png' ) ;
381382 } ) ;
382383
383- it ( 'should get direct to baseUrl' , ( ) => {
384+ it ( 'should get direct to baseUrl' , async ( ) => {
384385 options . baseUrlDirect = true ;
385386 const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
386- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/test.png' ) ;
387+ expect ( await s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/test.png' ) ;
387388 } ) ;
388389
389- it ( 'should get without directAccess' , ( ) => {
390+ it ( 'should get without directAccess' , async ( ) => {
390391 options . directAccess = false ;
391392 const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
392- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://my.server.com/parse/files/xxxx/test.png' ) ;
393+ expect ( await s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://my.server.com/parse/files/xxxx/test.png' ) ;
393394 } ) ;
394395
395- it ( 'should go directly to amazon' , ( ) => {
396+ it ( 'should go directly to amazon' , async ( ) => {
396397 delete options . baseUrl ;
397398 const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
398- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'https://my-bucket.s3.amazonaws.com/foo/bar/test.png' ) ;
399+ expect ( await s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'https://my-bucket.s3.amazonaws.com/foo/bar/test.png' ) ;
399400 } ) ;
400401 } ) ;
401- describe ( 'getFileLocation' , ( ) => {
402+ describe ( 'getFileLocation with presignedUrl ' , ( ) => {
402403 const testConfig = {
403404 mount : 'http://my.server.com/parse' ,
404405 applicationId : 'xxxx' ,
@@ -414,29 +415,29 @@ describe('S3Adapter tests', () => {
414415 } ;
415416 } ) ;
416417
417- it ( 'should get using the baseUrl' , ( ) => {
418+ it ( 'should get using the baseUrl' , async ( ) => {
418419 const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
419- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/foo/bar/test.png' ) ;
420+ expect ( await s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/foo/bar/test.png' ) ;
420421 } ) ;
421422
422- it ( 'when use presigned URL should use S3 \'getObject\' operation' , ( ) => {
423+ it ( 'when use presigned URL should use S3 \'getObject\' operation' , async ( ) => {
423424 options . presignedUrl = true ;
424425 const s3 = makeS3Adapter ( options ) ;
425426
426427 let getSignedUrlCommand = '' ;
427- s3 . getSignedUrlSync = ( _ , command ) => {
428+ s3 . getFileSignedUrl = ( _ , command ) => {
428429 getSignedUrlCommand = command ;
429430 }
430431
431- s3 . getFileLocation ( testConfig , 'test.png' ) ;
432+ await s3 . getFileLocation ( testConfig , 'test.png' ) ;
432433 expect ( getSignedUrlCommand ) . toBeInstanceOf ( GetObjectCommand ) ;
433434 } ) ;
434435
435- it ( 'should get using the baseUrl and amazon using presigned URL' , ( ) => {
436+ it ( 'should get using the baseUrl and amazon using presigned URL' , async ( ) => {
436437 options . presignedUrl = true ;
437438 const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
438439
439- const fileLocation = s3 . getFileLocation ( testConfig , 'test.png' ) ;
440+ const fileLocation = await s3 . getFileLocation ( testConfig , 'test.png' ) ;
440441 expect ( fileLocation ) . toMatch ( / ^ h t t p : \/ \/ e x a m p l e .c o m \/ f i l e s \/ f o o \/ b a r \/ t e s t .p n g \? / ) ;
441442 expect ( fileLocation ) . toMatch ( / X - A m z - C r e d e n t i a l = a c c e s s K e y % 2 F \d { 8 } % 2 F \w { 2 } - \w { 1 , 9 } - \d % 2 F s 3 % 2 F a w s 4 _ r e q u e s t / ) ;
442443 expect ( fileLocation ) . toMatch ( / X - A m z - D a t e = \d { 8 } T \d { 6 } Z / ) ;
@@ -446,30 +447,30 @@ describe('S3Adapter tests', () => {
446447 expect ( fileLocation ) . toContain ( 'X-Amz-SignedHeaders=host' ) ;
447448 } ) ;
448449
449- it ( 'should get direct to baseUrl' , ( ) => {
450+ it ( 'should get direct to baseUrl' , async ( ) => {
450451 options . baseUrlDirect = true ;
451452 const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
452- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/test.png' ) ;
453+ expect ( await s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/test.png' ) ;
453454 } ) ;
454455
455- it ( 'should get without directAccess' , ( ) => {
456+ it ( 'should get without directAccess' , async ( ) => {
456457 options . directAccess = false ;
457458 const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
458- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://my.server.com/parse/files/xxxx/test.png' ) ;
459+ expect ( await s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://my.server.com/parse/files/xxxx/test.png' ) ;
459460 } ) ;
460461
461- it ( 'should go directly to amazon' , ( ) => {
462+ it ( 'should go directly to amazon' , async ( ) => {
462463 delete options . baseUrl ;
463464 const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
464- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'https://my-bucket.s3.amazonaws.com/foo/bar/test.png' ) ;
465+ expect ( await s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'https://my-bucket.s3.amazonaws.com/foo/bar/test.png' ) ;
465466 } ) ;
466467
467- it ( 'should go directly to amazon using presigned URL' , ( ) => {
468+ it ( 'should go directly to amazon using presigned URL' , async ( ) => {
468469 delete options . baseUrl ;
469470 options . presignedUrl = true ;
470471 const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
471472
472- const fileLocation = s3 . getFileLocation ( testConfig , 'test.png' ) ;
473+ const fileLocation = await s3 . getFileLocation ( testConfig , 'test.png' ) ;
473474 expect ( fileLocation ) . toMatch ( / ^ h t t p s : \/ \/ m y - b u c k e t .s 3 .u s - e a s t - 1 .a m a z o n a w s .c o m \/ f o o \/ b a r \/ t e s t .p n g \? / ) ;
474475 expect ( fileLocation ) . toMatch ( / X - A m z - C r e d e n t i a l = a c c e s s K e y % 2 F \d { 8 } % 2 F u s - e a s t - 1 % 2 F s 3 % 2 F a w s 4 _ r e q u e s t / ) ;
475476 expect ( fileLocation ) . toMatch ( / X - A m z - D a t e = \d { 8 } T \d { 6 } Z / ) ;
0 commit comments