11'use strict' ;
2- let filesAdapterTests = require ( 'parse-server-conformance-tests' ) . files ;
32
4- let S3Adapter = require ( '../index.js' ) ;
5- let optionsFromArguments = require ( '../lib/optionsFromArguments' ) ;
3+ const config = require ( 'config' ) ;
4+ const filesAdapterTests = require ( 'parse-server-conformance-tests' ) . files ;
5+ const S3Adapter = require ( '../index.js' ) ;
6+ const optionsFromArguments = require ( '../lib/optionsFromArguments' ) ;
67
7- describe ( 'S3Adapter tests' , ( ) => {
8+ describe ( 'S3Adapter tests' , ( ) => {
9+ beforeEach ( ( ) => {
10+ delete process . env . S3_BUCKET ;
11+ delete process . env . S3_REGION ;
12+ } ) ;
813
914 it ( 'should throw when not initialized properly' , ( ) => {
1015 expect ( ( ) => {
1116 var s3 = new S3Adapter ( ) ;
12- } ) . toThrow ( new Error ( 'Failed to configure S3Adapter. Arguments don\'t make sense' ) ) ;
17+ } ) . toThrow ( "S3Adapter requires option 'bucket' or env. variable S3_BUCKET" ) ;
1318
1419 expect ( ( ) => {
1520 var s3 = new S3Adapter ( 'accessKey' , 'secretKey' , { } ) ;
@@ -34,6 +39,57 @@ describe('S3Adapter tests', () => {
3439 } ) . not . toThrow ( )
3540 } ) ;
3641
42+ it ( 'should accept environment for required' , ( ) => {
43+ const TEST_BUCKET = 'testBucket' ;
44+ process . env . S3_BUCKET = TEST_BUCKET ;
45+ const s3 = new S3Adapter ( ) ;
46+ expect ( s3 . _bucket ) . toBe ( TEST_BUCKET ) ;
47+ } ) ;
48+
49+ describe ( 'configured with immutable values' , ( ) => {
50+ describe ( 'not initialized properly' , ( ) => {
51+ it ( 'should fail with two string arguments' , ( ) => {
52+ expect ( ( ) => {
53+ var s3 = new S3Adapter ( config . get ( 'accessKey' ) , config . get ( 'secretKey' ) , { } ) ;
54+ } ) . toThrow ( new Error ( 'Failed to configure S3Adapter. Arguments don\'t make sense' ) ) ;
55+ } ) ;
56+
57+ it ( 'should fail when passed an object without a bucket' , ( ) => {
58+ expect ( ( ) => {
59+ var s3 = new S3Adapter ( config . get ( 'insufficientOptions' ) ) ;
60+ } ) . toThrow ( "S3Adapter requires option 'bucket' or env. variable S3_BUCKET" )
61+ } ) ;
62+ } ) ;
63+
64+
65+ describe ( 'should not throw when initialized properly' , ( ) => {
66+ it ( 'should accept a string bucket' , ( ) => {
67+ expect ( ( ) => {
68+ var s3 = new S3Adapter ( config . get ( 'bucket' ) ) ;
69+ } ) . not . toThrow ( )
70+ } ) ;
71+
72+ it ( 'should accept an object with a bucket' , ( ) => {
73+ expect ( ( ) => {
74+ var s3 = new S3Adapter ( config . get ( 'objectWithBucket' ) ) ;
75+ } ) . not . toThrow ( )
76+ } ) ;
77+
78+ it ( 'should accept a second argument of object with a params object with a bucket' , ( ) => {
79+ expect ( ( ) => {
80+ var s3 = new S3Adapter ( config . get ( 'emptyObject' ) , config . get ( 'paramsObjectWBucket' ) ) ;
81+ } ) . not . toThrow ( )
82+ } ) ;
83+
84+ it ( 'should accept environment over default' , ( ) => {
85+ const TEST_REGION = 'test' ;
86+ process . env . S3_REGION = TEST_REGION ;
87+ const s3 = new S3Adapter ( config . get ( 'bucket' ) ) ;
88+ expect ( s3 . _region ) . toBe ( TEST_REGION ) ;
89+ } ) ;
90+ } ) ;
91+ } ) ;
92+
3793 describe ( 'to find the right arg in the right place' , ( ) => {
3894 it ( 'should accept just bucket as first string arg' , ( ) => {
3995 var args = [ 'bucket' ] ;
0 commit comments