/**!
 *
 * Copyright (c) 2015-2016 Cisco Systems, Inc. See LICENSE file.
 * @private
 */

import '../..';

import {assert} from '@ciscospark/test-helper-chai';
import CiscoSpark from '@ciscospark/spark-core';
import fh from '@ciscospark/test-helper-file';
import testUsers from '@ciscospark/test-helper-test-users';


describe(`plugin-support`, function() {
  this.timeout(20000);

  let spark;

  let sampleTextOne = `sample-text-one.txt`;

  before(() => Promise.all([
    fh.fetch(sampleTextOne)
  ])
    .then((res) => {
      [
        sampleTextOne
      ] = res;
    }));

  describe(`#submitLogs()`, () => {
    describe(`when the current user is not authorized`, () => {
      before(() => testUsers.create({count: 1})
        .then((users) => {
          spark = new CiscoSpark({
            credentials: {
              authorization: users[0].token
            }
          });

          return spark.device.register();
        }));

      it(`uploads logs`, () => spark.support.submitLogs({}, sampleTextOne)
        .then((body) => {
          assert.isDefined(body);
          assert.property(body, `url`);
          assert.property(body, `userId`);
          assert.equal(body.userId, spark.device.userId);
        }));
    });

    describe(`when the current user is not authorized`, () => {
      it(`uploads logs`, () => {
        spark = new CiscoSpark({});
        return spark.support.submitLogs({}, sampleTextOne)
          .then((body) => {
            assert.isDefined(body);
            assert.property(body, `url`);
            assert.property(body, `userId`);
          });
      });
    });
  });

});

@@ -366,17 +366,17 @@
 timeout(
-2
+6
 0000);%0A%0A
@@ -440,24 +440,42 @@
 ;%0A%0A  before(
+%60fetch fixtures%60, 
 () =%3E Promis
@@ -658,36 +658,32 @@
 current user is 
-not 
 authorized%60, () 

increase the timeout for the log upload test due to extreme latency in downstream provider