var utils = require('./test-utils');
var assert = require('chai').assert;

var Domain = require('../lib/database/domain').Domain;

var context;
var temporaryDatabase;

function commonSetup() {
  temporaryDatabase = utils.createTemporaryDatabase();
  context = temporaryDatabase.get();
}

function commonTeardown() {
  context = undefined;
  temporaryDatabase.clear();
  temporaryDatabase.teardown();
  temporaryDatabase = undefined;
}

suite('cs-create-domain', function() {
  setup(commonSetup);
  teardown(commonTeardown);

  test('create', function(done) {
    utils
      .run('cs-create-domain',
           '--domain-name', 'test',
           '--database-path', temporaryDatabase.path)
      .next(function(result) {
        assert.equal(result.code, 0);
        assert.include(result.output.stdout,
                       'Domain endpoints are currently being created.');

        context.reopen();
        var domain = new Domain('test', context);
        assert.isTrue(domain.exists());

        done();
      });
  });
});

@@ -985,24 +985,1147 @@
 exists());%0A%0A
+        done();%0A      %7D);%0A  %7D);%0A%0A  test('create again', function(done) %7B%0A    utils%0A      .run('cs-create-domain',%0A           '--domain-name', 'test',%0A           '--database-path', temporaryDatabase.path)%0A      .run('cs-create-domain',%0A           '--domain-name', 'test',%0A           '--database-path', temporaryDatabase.path)%0A      .next(function(result) %7B%0A        assert.equal(result.code, 1);%0A        assert.include(result.output.stdout,%0A                       'The domain %5Btest%5D already exists.');%0A%0A        context.reopen();%0A        var domains = Domain.getAll(context).map(function(domain) %7B%0A              return domain.name;%0A            %7D);%0A        assert.deepEqual(domains, %5B'test'%5D);%0A%0A        done();%0A      %7D);%0A  %7D);%0A%0A  test('missing domain name', function(done) %7B%0A    utils%0A      .run('cs-create-domain',%0A           '--database-path', temporaryDatabase.path)%0A      .next(function(result) %7B%0A        assert.equal(result.code, 1);%0A        assert.include(result.output.stdout,%0A                       'You must specify the domain name.');%0A%0A        context.reopen();%0A        assert.deepEqual(Domain.getAll(context), %5B%5D);%0A%0A
         done

Add tests for invalid use of cs-create-domain command