"use strict";

var assert = require("assert");

var SolidBucket = require("../index");

var _require = require("./utils"),
  resolveUniversalApiWorkflow = _require.resolveUniversalApiWorkflow,
  simulateObjectCorruptionWorkflow = _require.simulateObjectCorruptionWorkflow,
  rejectMissingParametersWorkflow = _require.rejectMissingParametersWorkflow,
  rejectUniversalApiWorkflow = _require.rejectUniversalApiWorkflow;

var username = process.env.RACKSPACE_USERNAME;
var apiKey = process.env.RACKSPACE_APIKEY;

describe("Rackspace Cloud Storage", function() {
  this.timeout(15000);

  describe("Universal API", function() {
    it("should test the happy path", function() {
      var bucketName =
        String(
          Math.floor(Math.random() * 200000000) *
            Math.floor(Math.random() * 200000000)
        ) + "tests";
      var filePath = "lib/test/testdata/binary.bin";
      var filenameTxt = "generated-txt.txt";

      var provider = new SolidBucket("rackspace", {
        username: username,
        apiKey: apiKey
      });

      resolveUniversalApiWorkflow(provider, bucketName, filePath, filenameTxt);
    });

    it("should test against missing parameters", function() {
      var bucketName = "";
      var filename = "";

      var provider = new SolidBucket("rackspace", {
        username: username,
        apiKey: apiKey
      });

      rejectMissingParametersWorkflow(provider, bucketName, filename);
    });

    it("should test against missing auth options", function() {
      assert.throws(function() {
        new SolidBucket("rackspace", {
          username: "",
          apiKey: ""
        });
      }, Error);
    });

    it("should test object upload corruptions", function() {
      var bucketName =
        String(
          Math.floor(Math.random() * 200000000) *
            Math.floor(Math.random() * 200000000)
        ) + "tests";
      var filename = "generated-during-tests.txt";

      var provider = new SolidBucket("rackspace", {
        username: username,
        apiKey: apiKey
      });

      simulateObjectCorruptionWorkflow(provider, bucketName, filename);
    });

    it("should test the provider rejections", function() {
      var bucketName = "backup";
      var filename = "generated-during-tests.txt";

      var provider = new SolidBucket("rackspace", {
        username: username,
        apiKey: apiKey
      });
      rejectUniversalApiWorkflow(provider, bucketName, filename);
    });
  });
});
