Navigation Menu

Skip to content

Commit

Permalink
Add tests for field options specified via the configurations API
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 13, 2012
1 parent 1dc1a0a commit 0ebf012
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/api/2011-02-01/configuration.js
Expand Up @@ -242,21 +242,21 @@ handlers.DefineIndexField = function(context, request, response) {
request.query['LiteralOptions.FacetEnabled'] :
null ;
if (facetEnabled !== null)
field.facetEnabled = facetEnabled;
field.facetEnabled = facetEnabled.toLowerCase() == 'true';

var resultEnabled = fieldType == 'text' ?
request.query['TextOptions.ResultEnabled'] :
fieldType == 'literal' ?
request.query['LiteralOptions.ResultEnabled'] :
null ;
if (resultEnabled !== null)
field.resultEnabled = resultEnabled;
field.resultEnabled = resultEnabled.toLowerCase() == 'true';

var searchEnabled = fieldType == 'literal' ?
request.query['LiteralOptions.SearchEnabled'] :
null ;
if (searchEnabled !== null)
field.searchEnabled = searchEnabled;
field.searchEnabled = searchEnabled.toLowerCase() == 'true';

if (!field.exists()) {
field.type = fieldType;
Expand Down
103 changes: 90 additions & 13 deletions test/api-configuration.test.js
Expand Up @@ -422,7 +422,7 @@ suite('Configuration API', function() {
});
});

test('Get, Action=DefineIndexField (text)', function(done) {
test('Get, Action=DefineIndexField (text, without options)', function(done) {
utils
.get('/?DomainName=companies&Action=CreateDomain&Version=2011-02-01', {
'Host': 'cloudsearch.localhost'
Expand All @@ -440,12 +440,49 @@ suite('Configuration API', function() {
{ statusCode: 200,
body: PATTERN_DefineIndexFieldResponse_Text });
var expectedOptions = {
IndexFieldName: field.name,
IndexFieldType: field.type,
IndexFieldName: 'name',
IndexFieldType: 'text',
TextOptions: {
DefaultValue: {},
FacetEnabled: String(field.facetEnabled),
ResultEnabled: String(field.resultEnabled)
FacetEnabled: false,
ResultEnabled: false
}
};
var options = response.body.DefineIndexFieldResponse.DefineIndexFieldResult.IndexField.Options;
assert.deepEqual(options, expectedOptions);

done();
})
.error(function(error) {
done(error);
});
});

test('Get, Action=DefineIndexField (text, with options)', function(done) {
utils
.get('/?DomainName=companies&Action=CreateDomain&Version=2011-02-01', {
'Host': 'cloudsearch.localhost'
})
.get('/?DomainName=companies&IndexField.IndexFieldName=name&' +
'IndexField.IndexFieldType=text&' +
'TextOptions.FacetEnabled=true&TextOptions.ResultEnabled=true&' +
'Action=DefineIndexField&Version=2011-02-01')
.next(function(response) {
var domain = new Domain('companies', context);
var field = domain.getIndexField('name');
assert.isTrue(field.exists());

response = toParsedResponse(response);
assert.deepEqual(response.pattern,
{ statusCode: 200,
body: PATTERN_DefineIndexFieldResponse_Text });
var expectedOptions = {
IndexFieldName: 'name',
IndexFieldType: 'text',
TextOptions: {
DefaultValue: {},
FacetEnabled: true,
ResultEnabled: true
}
};
var options = response.body.DefineIndexFieldResponse.DefineIndexFieldResult.IndexField.Options;
Expand Down Expand Up @@ -476,8 +513,8 @@ suite('Configuration API', function() {
{ statusCode: 200,
body: PATTERN_DefineIndexFieldResponse_UInt });
var expectedOptions = {
IndexFieldName: field.name,
IndexFieldType: field.type,
IndexFieldName: 'age',
IndexFieldType: 'uint',
UIntOptions: {
DefaultValue: {}
}
Expand All @@ -492,13 +529,53 @@ suite('Configuration API', function() {
});
});

test('Get, Action=DefineIndexField (literal)', function(done) {
test('Get, Action=DefineIndexField (literal, without options)', function(done) {
utils
.get('/?DomainName=companies&Action=CreateDomain&Version=2011-02-01', {
'Host': 'cloudsearch.localhost'
})
.get('/?DomainName=companies&IndexField.IndexFieldName=product&' +
'IndexField.IndexFieldType=literal&' +
'Action=DefineIndexField&Version=2011-02-01')
.next(function(response) {
var domain = new Domain('companies', context);
var field = domain.getIndexField('product');
assert.isTrue(field.exists());

response = toParsedResponse(response);
assert.deepEqual(response.pattern,
{ statusCode: 200,
body: PATTERN_DefineIndexFieldResponse_Literal });
var expectedOptions = {
IndexFieldName: 'product',
IndexFieldType: 'literal',
LiteralOptions: {
DefaultValue: {},
FacetEnabled: false,
ResultEnabled: false,
SearchEnabled: false
}
};
var options = response.body.DefineIndexFieldResponse.DefineIndexFieldResult.IndexField.Options;
assert.deepEqual(options, expectedOptions);

done();
})
.error(function(error) {
done(error);
});
});

test('Get, Action=DefineIndexField (literal, with options)', function(done) {
utils
.get('/?DomainName=companies&Action=CreateDomain&Version=2011-02-01', {
'Host': 'cloudsearch.localhost'
})
.get('/?DomainName=companies&IndexField.IndexFieldName=product&' +
'IndexField.IndexFieldType=literal&' +
'LiteralOptions.SearchEnabled=true&' +
'LiteralOptions.FacetEnabled=true&' +
'LiteralOptions.ResultEnabled=true&' +
'Action=DefineIndexField&Version=2011-02-01')
.next(function(response) {
var domain = new Domain('companies', context);
Expand All @@ -510,13 +587,13 @@ suite('Configuration API', function() {
{ statusCode: 200,
body: PATTERN_DefineIndexFieldResponse_Literal });
var expectedOptions = {
IndexFieldName: field.name,
IndexFieldType: field.type,
IndexFieldName: 'product',
IndexFieldType: 'literal',
LiteralOptions: {
DefaultValue: {},
FacetEnabled: String(field.facetEnabled),
ResultEnabled: String(field.resultEnabled),
SearchEnabled: String(field.searchEnabled)
FacetEnabled: true,
ResultEnabled: true,
SearchEnabled: true
}
};
var options = response.body.DefineIndexFieldResponse.DefineIndexFieldResult.IndexField.Options;
Expand Down

0 comments on commit 0ebf012

Please sign in to comment.