'use strict';

var helpers = require('../helpers');

var async = require('async');
var uuid = require('uuid');

/**
 * This fixture creates an Express application which has express-stormpath
 * integrated. It does not pass any special options to the express-stormpath
 * init function. This fixture is meant to represent the pure default state of
 * the library when it does not receive any special configuration.
 *
 * The only parameter that this fixture constructor takes is a Stormpath
 * application reference, as we need to know which Stormpath application to use
 * for the initialization of the library. It is assumed that API Keys for
 * Stormpath are already in the environment.
 *
 * @param {object} stormpathApplication
 */
function SubdomainMultiTenancyFixture() {
  this.client = helpers.createClient();
  this.expressApp = null;
  this.organization = {
    name: uuid.v4(),
    nameKey: uuid.v4()
  };
  this.account = helpers.newUser();

  this.config = {
    web: {
      domainName: 'localhost.com',
      multiTenancy: {
        enabled: true
      }
    }
  };
}

SubdomainMultiTenancyFixture.prototype.before = function before(done) {
  var self = this;

  async.parallel({
    application: function (next) {
      helpers.createApplication(self.client, next);
    },
    organization: function (next) {
      self.client.createOrganization(self.organization, {createDirectory: true}, next);
    }
  }, function (err, resources) {

    if (err) {
      return done(err);
    }

    self.organization = resources.organization;
    self.config.application = resources.application;

    async.parallel({
      account: function (next) {
        self.organization.createAccount(self.account, next);
      },
      mapping: function (next) {
        resources.application.createAccountStoreMapping({accountStore: self.organization}, next);
      }
    }, function (err) {
      if (err) {
        return done(err);
      }

      self.expressApp = helpers.createStormpathExpressApp(self.config);
      done();
    });
  });
};

SubdomainMultiTenancyFixture.prototype.after = function after(done) {
  helpers.destroyApplication(this.config.application, done);
};

module.exports = SubdomainMultiTenancyFixture;
@@ -138,17 +138,18 @@
 es a
-n Express
+ Stormpath
  app
@@ -161,576 +161,154 @@
 ion 
-which has express-stormpath%0A * integrated. It does not pass any special options to the express-stormpath%0A * init function. This fixture is meant to represent the pure default state of%0A * the library when it does not receive any special configuration.%0A *%0A * The only parameter that this fixture constructor takes is a Stormpath%0A * application reference, as we need to know which Stormpath application to use%0A * for the initialization of the library. It is assumed that API Keys for%0A * Stormpath are already in the environment.%0A *%0A * @param %7Bobject%7D stormpathApplic
+that has an organization mapped%0A * to it.  It also creates an account in that organization, for testing%0A * authenticatio against the organiz
 ation
+.
 %0A */

fix description of fixture