Navigation Menu

Skip to content

Commit

Permalink
Add cs-index-documents command
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 6, 2012
1 parent c6b117d commit 5174983
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
26 changes: 26 additions & 0 deletions bin/cs-index-documents
@@ -0,0 +1,26 @@
#!/usr/bin/env node

var CLI = require(__dirname + '/../lib/command-line').CommandLineInterface;
var commandLine = new CLI();

commandLine
.usage('--domain-name <domain name> [options]')
.option('-d, --domain-name <domain name>',
'The name of the domain that you are indexing. Required.',
String)
.parse();

commandLine.assertHaveDomainName();
commandLine.assertDomainExists();

commandLine.domain.reindexSync();

console.log('===========================================');
console.log('Indexing documents for domain [' + commandLine.domain.name + ']');
console.log('');
console.log('Now indexing fields:');
console.log('===========================================');
commandLine.domain.indexFields.forEach(function(field) {
console.log(field.name);
});
console.log('===========================================');
84 changes: 84 additions & 0 deletions test/cs-commands.test.js
Expand Up @@ -418,3 +418,87 @@ suite('cs-configure-fields', function() {
});
});
});

suite('cs-index-documents', function() {
setup(commonSetup);
teardown(commonTeardown);

test('reindex', function(done) {
utils
.run('cs-create-domain',
'--domain-name', 'companies',
'--database-path', temporaryDatabase.path)
.run('cs-configure-fields',
'--domain-name', 'companies',
'--name', 'name',
'--type', 'text',
'--database-path', temporaryDatabase.path)
.run('cs-configure-fields',
'--domain-name', 'companies',
'--name', 'age',
'--type', 'uint',
'--database-path', temporaryDatabase.path)
.run('cs-configure-fields',
'--domain-name', 'companies',
'--name', 'product',
'--type', 'literal',
'--database-path', temporaryDatabase.path)
.run('cs-index-documents',
'--domain-name', 'companies',
'--database-path', temporaryDatabase.path)
.next(function(result) {
assert.deepEqual({ code: result.code,
message: result.output.stdout },
{ code: 0,
message: '===========================================\n' +
'Indexing documents for domain [companies]\n' +
'\n' +
'Now indexing fields:\n' +
'===========================================\n' +
'age\n' +
'name\n' +
'product\n' +
'===========================================\n',
result.output.stderr);
done();
})
.error(function(e) {
done(e);
});
});

test('reindex not-existing domain', function(done) {
utils
.run('cs-index-documents',
'--domain-name', 'test',
'--database-path', temporaryDatabase.path)
.next(function(result) {
assert.deepEqual({ code: result.code,
message: result.output.stdout },
{ code: 1,
message: 'You must specify an existing domain name.\n' },
result.output.stderr);
done();
})
.error(function(e) {
done(e);
});
});

test('reindex without domain', function(done) {
utils
.run('cs-index-documents',
'--database-path', temporaryDatabase.path)
.next(function(result) {
assert.deepEqual({ code: result.code,
message: result.output.stdout },
{ code: 1,
message: 'You must specify the domain name.\n' },
result.output.stderr);
done();
})
.error(function(e) {
done(e);
});
});
});

0 comments on commit 5174983

Please sign in to comment.