Skip to content

Commit

Permalink
🐛 switch headers to be lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
germanattanasio committed Oct 14, 2016
1 parent 690c92e commit a7ed099
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
10 changes: 5 additions & 5 deletions personality-insights/v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ PersonalityInsightsV3.URL = 'https://gateway.watsonplatform.net/personality-insi
/**
* @param {Object} params The parameters to call the service
* @param {Object} [params.headers] - The header parameters.
* @param {string} [params.headers.Accept-Language=en] - The desired language of the response: ar (Arabic), en (English), es (Spanish), or ja (Japanese).
* @param {string} [params.headers.Content-Type=text/plain] - The content type of the request: text/plain (the default), text/html, or application/json.
* @param {string} [params.headers.Content-Language=en] - The language of the input text for the request: ar (Arabic), en (English), es (Spanish), or ja (Japanese)
* @param {string} [params.headers.Accept=application/json] - The desired content type of the response: application/json (the default) or text/csv
* @param {string} [params.headers.accept-language=en] - The desired language of the response: ar (Arabic), en (English), es (Spanish), or ja (Japanese).
* @param {string} [params.headers.content-type=text/plain] - The content type of the request: text/plain (the default), text/html, or application/json.
* @param {string} [params.headers.content-language=en] - The language of the input text for the request: ar (Arabic), en (English), es (Spanish), or ja (Japanese)
* @param {string} [params.headers.accept=application/json] - The desired content type of the response: application/json (the default) or text/csv
* @param {string} [params.text] - The text to analyze.
* @param {Object} [params.content_items] - A JSON input (if 'text' not provided).
* @param {boolean} [params.raw_scores=false] - include raw results.
Expand Down Expand Up @@ -84,7 +84,7 @@ PersonalityInsightsV3.prototype.profile = function(_params, callback) { // eslin
body: params.text || pick(params, ['contentItems']),
json: true,
qs: pick(params, ['csv_headers', 'raw_scores', 'consumption_preferences']),
headers: extend({ 'Content-type': content_type, 'Accept-language': 'en' }, params.headers)
headers: extend({ 'content-type': content_type, 'accept-language': 'en' }, params.headers)
},
defaultOptions: this._options
};
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test.personality_insights.v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('personality_insights_v3_integration', function() {
consumption_preferences: true,
csv_headers: true,
headers: {
'Accept': 'text/csv'
'accept': 'text/csv'
}
};
personality_insights.profile(params, done);
Expand Down
34 changes: 17 additions & 17 deletions test/unit/test.personality_insights.v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('personality_insights_v3', function() {
assert.equal(req.uri.href, service.url + service_path + '?version=2016-10-19');
assert.equal(body, '"' + service_request.text + '"');
assert.equal(req.method, 'POST');
assert.equal(req.headers['Content-type'], 'text/plain');
assert.equal(req.headers['content-type'], 'text/plain');
});

it('should generate a valid payload with contentItems', function() {
Expand All @@ -80,8 +80,8 @@ describe('personality_insights_v3', function() {
assert.equal(req.uri.href, service.url + service_path + '?version=2016-10-19');
assert.equal(body, JSON.stringify(payload));
assert.equal(req.method, 'POST');
assert.equal(req.headers['Content-language'], undefined); // service bug: content-language header overrides the language specified in JSON for each content item, so it must not be set
assert.equal(req.headers['Content-type'], 'application/json');
assert.equal(req.headers['content-language'], undefined); // service bug: content-language header overrides the language specified in JSON for each content item, so it must not be set
assert.equal(req.headers['content-type'], 'application/json');
});

it('should generate a valid payload with content_items', function() {
Expand All @@ -91,8 +91,8 @@ describe('personality_insights_v3', function() {
assert.equal(req.uri.href, service.url + service_path + '?version=2016-10-19');
assert.equal(body, JSON.stringify(payload));
assert.equal(req.method, 'POST');
assert.equal(req.headers['Content-language'], undefined); // service bug: content-language header overrides the language specified in JSON for each content item, so it must not be set
assert.equal(req.headers['Content-type'], 'application/json');
assert.equal(req.headers['content-language'], undefined); // service bug: content-language header overrides the language specified in JSON for each content item, so it must not be set
assert.equal(req.headers['content-type'], 'application/json');
});

it('should generate a valid payload with html', function() {
Expand All @@ -102,14 +102,14 @@ describe('personality_insights_v3', function() {
assert.equal(req.uri.href, service.url + service_path + '?version=2016-10-19');
assert.equal(body, JSON.stringify(html_req.text));
assert.equal(req.method, 'POST');
assert.equal(req.headers['Content-type'], 'text/html');
assert.equal(req.headers['content-type'], 'text/html');
});

it('should generate a valid payload with raw_scores, Accept-Language and Contnet-Language', function() {
it('should generate a valid payload with raw_scores, accept-Language and content-language', function() {
var params = extend({ raw_scores: true,
headers: {
'Content-language': 'es',
'Accept-language': 'es'
'content-language': 'es',
'accept-language': 'es'
}
}, payload);

Expand All @@ -118,27 +118,27 @@ describe('personality_insights_v3', function() {
assert.equal(req.uri.href, service.url + service_path + '?version=2016-10-19&raw_scores=true');
assert.equal(body, JSON.stringify(payload));
assert.equal(req.method, 'POST');
assert.equal(req.headers['Content-type'], 'application/json');
assert.equal(req.headers['Content-language'], 'es');
assert.equal(req.headers['Accept-language'], 'es');
assert.equal(req.headers['content-type'], 'application/json');
assert.equal(req.headers['content-language'], 'es');
assert.equal(req.headers['accept-language'], 'es');
});

it('should generate a valid request with { headers: {Accept: "text/csv"}}', function() {
var params = extend({ headers: { Accept: 'text/csv'} }, payload);
var params = extend({ headers: { accept: 'text/csv'} }, payload);
var req = personality_insights.profile(params, noop);
var body = new Buffer(req.body).toString('ascii');
assert.equal(req.uri.href, service.url + service_path + '?version=2016-10-19');
assert.equal(body, JSON.stringify(payload));
assert.equal(req.headers['Accept'], 'text/csv');
assert.equal(req.headers['accept'], 'text/csv');
});

it('should generate a valid request with {headers: {Accept: "text/csv"}, csv_headers: true}', function() {
var params = extend({ headers: {Accept: "text/csv"}, csv_headers: true}, payload);
it('should generate a valid request with {headers: {accept: "text/csv"}, csv_headers: true}', function() {
var params = extend({ headers: {accept: "text/csv"}, csv_headers: true}, payload);
var req = personality_insights.profile(params, noop);
var body = new Buffer(req.body).toString('ascii');
assert.equal(req.uri.href, service.url + service_path + '?version=2016-10-19&csv_headers=true');
assert.equal(body, JSON.stringify(payload));
assert.equal(req.headers['Accept'], 'text/csv');
assert.equal(req.headers['accept'], 'text/csv');
});

it('should format the response', function(done) {
Expand Down

0 comments on commit a7ed099

Please sign in to comment.