const {assert} = require ('chai');
const {Uploader} = require ('../src/uploader');

describe ('Setup file upload test', function () {
  let source = undefined;
  let uploader = undefined;

  const objectParams = {ContentType: 'text/csv'};

  before (function (done) {
    source = new Buffer ('key;value\ntest;1\nexample;2\n');

    uploader = new Uploader ({
      accessKey: 'test-accessKey',
      secretKey: 'test-secretKey',
      bucket: 'test-bucket',
      objectName: 'testfile1',
      objectParams,
      stream: source,
      debug: true,
    });
    return done ();
  });

  it ('I have set accessKey', () =>
    assert.equal (
      uploader.upload.service.config.credentials.accessKeyId,
      'test-accessKey'
    ));

  it ('I have set bucket', () =>
    assert.equal (uploader.objectParams.Bucket, 'test-bucket'));

  it ('I have set key', () =>
    assert.equal (uploader.objectParams.Key, 'testfile1'));

  it ('I have set ContentType', () =>
    assert.equal (uploader.objectParams.ContentType, 'text/csv'));

  it ('I have set debug', () => assert.ok (uploader.debug));

  describe ('Creating a second uploader', function () {
    let uploader2 = undefined;

    before (() => {
      return (uploader2 = new Uploader ({
        bucket: 'test-bucket-2',
        stream: new Buffer ('...\n'),
        objectParams,
      }));
    });

    it ('I have set bucket', () =>
      assert.equal (uploader2.objectParams.Bucket, 'test-bucket-2'));

    it ('I have not unset original bucket', () =>
      assert.equal (uploader.objectParams.Bucket, 'test-bucket'));
  });
});

@@ -1,21 +1,23 @@
 const %7B
+ 
 assert
+ 
 %7D = requ
@@ -19,17 +19,16 @@
  require
- 
 ('chai')
@@ -36,24 +36,25 @@
 %0Aconst %7B
+ 
 Uploader
 %7D = requ
@@ -45,16 +45,17 @@
 Uploader
+ 
 %7D = requ
@@ -57,17 +57,16 @@
  require
- 
 ('../src
@@ -87,17 +87,16 @@
 describe
- 
 ('Setup 
@@ -118,25 +118,24 @@
 t', function
- 
 () %7B%0A  let s
@@ -206,16 +206,17 @@
 rams = %7B
+ 
 ContentT
@@ -230,16 +230,17 @@
 ext/csv'
+ 
 %7D;%0A%0A  be
@@ -243,17 +243,16 @@
   before
- 
 (functio
@@ -252,17 +252,16 @@
 function
- 
 (done) %7B
@@ -273,28 +273,28 @@
 source =
- new
  Buffer
- 
+.from
 ('key;va
@@ -341,33 +341,32 @@
 r = new Uploader
- 
 (%7B%0A      accessK
@@ -566,17 +566,16 @@
 urn done
- 
 ();%0A  %7D)
@@ -573,33 +573,32 @@
 e();%0A  %7D);%0A%0A  it
- 
 ('I have set acc
@@ -628,17 +628,16 @@
 rt.equal
- 
 (%0A      
@@ -714,16 +714,17 @@
 cessKey'
+,
 %0A    ));
@@ -721,33 +721,32 @@
 ',%0A    ));%0A%0A  it
- 
 ('I have set buc
@@ -765,33 +765,32 @@
     assert.equal
- 
 (uploader.object
@@ -818,33 +818,32 @@
 bucket'));%0A%0A  it
- 
 ('I have set key
@@ -859,33 +859,32 @@
     assert.equal
- 
 (uploader.object
@@ -907,33 +907,32 @@
 tfile1'));%0A%0A  it
- 
 ('I have set Con
@@ -956,33 +956,32 @@
     assert.equal
- 
 (uploader.object
@@ -1015,25 +1015,24 @@
 sv'));%0A%0A  it
- 
 ('I have set
@@ -1055,17 +1055,16 @@
 ssert.ok
- 
 (uploade
@@ -1085,17 +1085,16 @@
 describe
- 
 ('Creati
@@ -1124,17 +1124,16 @@
 function
- 
 () %7B%0A   
@@ -1171,17 +1171,16 @@
   before
- 
 (() =%3E %7B
@@ -1218,17 +1218,16 @@
 Uploader
- 
 (%7B%0A     
@@ -1273,20 +1273,20 @@
 eam:
- new
  Buffer
- 
+.from
 ('..
@@ -1332,33 +1332,32 @@
 %0A    %7D);%0A%0A    it
- 
 ('I have set buc
@@ -1378,33 +1378,32 @@
     assert.equal
- 
 (uploader2.objec
@@ -1444,17 +1444,16 @@
 %0A%0A    it
- 
 ('I have
@@ -1505,17 +1505,16 @@
 rt.equal
- 
 (uploade

remove deprecated new Buffer