Navigation Menu

Skip to content

Commit

Permalink
Add gcs-configure-default-search-field command
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 22, 2012
1 parent ce02ccd commit c3e5c9a
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 0 deletions.
33 changes: 33 additions & 0 deletions bin/gcs-configure-default-search-field
@@ -0,0 +1,33 @@
#!/usr/bin/env node

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

commandLine
.option('-d, --domain-name <domain name>',
'The name of the domain that you are configuring. Required.',
String)
.option('--name <field name>',
'The name of the field you want to set as the default search field. ' +
'It becomes blank if you omit this option',
String)
.parse();

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

var field = commandLine.domain.getIndexField(commandLine.options.name);
if (field) {
console.log('Setting "%s" as the default search field of "%s"...',
field.name,
commandLine.domain.name);
} else if (commandLine.options.name) {
console.log('"%s" is not a field of "%s".');
return process.exit(1);
} else {
console.log('Resetting the default search field of "%s"...',
commandLine.domain.name);
}
commandLine.domain.defaultSearchField = field;
console.log('Done.');
112 changes: 112 additions & 0 deletions test/gcs-commands.test.js
Expand Up @@ -701,6 +701,118 @@ suite('gcs-configure-text-options', function() {
});
});

suite('gcs-configure-default-search-field', function() {
setup(commonSetup);
teardown(commonTeardown);

test('set to an existing field', function() {
var domain = new Domain('companies', context).createSync();
domain.getIndexField('name').setType('text').createSync();
utils
.run('gcs-configure-default-search-field',
'--domain-name', 'companies',
'--name', 'name',
'--database-path', temporaryDatabase.path)
.next(function(result) {
assert.deepEqual({ code: result.code,
message: result.output.stdout },
{ code: 0,
message: 'Setting "name" as the default search ' +
'field of "companies"...' +
'Done.\n' },
result.output.stderr);
assert.equal(domain.defaultSearchField.name, 'name');
done();
})
.error(function(e) {
done(e);
});
});

test('set to a missing field', function() {
var domain = new Domain('companies', context).createSync();
domain.getIndexField('name').setType('text').createSync();
utils
.run('gcs-configure-default-search-field',
'--domain-name', 'companies',
'--name', 'name',
'--database-path', temporaryDatabase.path)
.run('gcs-configure-default-search-field',
'--domain-name', 'companies',
'--name', 'address',
'--database-path', temporaryDatabase.path)
.next(function(result) {
assert.deepEqual({ code: result.code,
message: result.output.stdout },
{ code: 1,
message: '"name" as not a field of "companies".\n' },
result.output.stderr);
assert.equal(domain.defaultSearchField.name, 'name');
done();
})
.error(function(e) {
done(e);
});
});

test('set to blank', function() {
var domain = new Domain('companies', context).createSync();
domain.getIndexField('name').setType('text').createSync();
utils
.run('gcs-configure-default-search-field',
'--domain-name', 'companies',
'--name', 'name',
'--database-path', temporaryDatabase.path)
.run('gcs-configure-default-search-field',
'--domain-name', 'companies',
'--name', '',
'--database-path', temporaryDatabase.path)
.next(function(result) {
assert.deepEqual({ code: result.code,
message: result.output.stdout },
{ code: 0,
message: 'Resetting the default search field of ' +
'"companies"...' +
'Done.\n' },
result.output.stderr);
assert.isTrue(domain.defaultSearchField === null,
domain.defaultSearchField);
done();
})
.error(function(e) {
done(e);
});
});

test('set to blank (omitted "name" option)', function() {
var domain = new Domain('companies', context).createSync();
domain.getIndexField('name').setType('text').createSync();
utils
.run('gcs-configure-default-search-field',
'--domain-name', 'companies',
'--name', 'name',
'--database-path', temporaryDatabase.path)
.run('gcs-configure-default-search-field',
'--domain-name', 'companies',
'--database-path', temporaryDatabase.path)
.next(function(result) {
assert.deepEqual({ code: result.code,
message: result.output.stdout },
{ code: 0,
message: 'Resetting the default search field of ' +
'"companies"...' +
'Done.\n' },
result.output.stderr);
assert.isTrue(domain.defaultSearchField === null,
domain.defaultSearchField);
done();
})
.error(function(e) {
done(e);
});
});
});

suite('gcs-index-documents', function() {
setup(commonSetup);
teardown(commonTeardown);
Expand Down

0 comments on commit c3e5c9a

Please sign in to comment.