@@ -353,6 +353,49 @@ describe('S3Adapter tests', () => {
353353 expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'https://myBucket.s3.amazonaws.com/foo/bar/test.png' ) ;
354354 } ) ;
355355 } ) ;
356+ describe ( 'getFileLocation' , ( ) => {
357+ const testConfig = {
358+ mount : 'http://my.server.com/parse' ,
359+ applicationId : 'xxxx' ,
360+ } ;
361+ let options ;
362+
363+ beforeEach ( ( ) => {
364+ options = {
365+ directAccess : true ,
366+ bucketPrefix : 'foo/bar/' ,
367+ baseUrl : ( fileconfig , filename ) => {
368+ if ( filename . length > 12 ) {
369+ return 'http://example.com/files' ;
370+ }
371+ return 'http://example.com/files' ;
372+ } ,
373+ } ;
374+ } ) ;
375+
376+ it ( 'should get using the baseUrl' , ( ) => {
377+ const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'myBucket' , options ) ;
378+ expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/foo/bar/test.png' ) ;
379+ } ) ;
380+
381+ it ( 'should get direct to baseUrl' , ( ) => {
382+ options . baseUrlDirect = true ;
383+ const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'myBucket' , options ) ;
384+ expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/test.png' ) ;
385+ } ) ;
386+
387+ it ( 'should get without directAccess' , ( ) => {
388+ options . directAccess = false ;
389+ const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'myBucket' , options ) ;
390+ expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://my.server.com/parse/files/xxxx/test.png' ) ;
391+ } ) ;
392+
393+ it ( 'should go directly to amazon' , ( ) => {
394+ delete options . baseUrl ;
395+ const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'myBucket' , options ) ;
396+ expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'https://myBucket.s3.amazonaws.com/foo/bar/test.png' ) ;
397+ } ) ;
398+ } ) ;
356399
357400 describe ( 'validateFilename' , ( ) => {
358401 let options ;
0 commit comments