Skip to content

Commit

Permalink
Making content-type checks more robust.
Browse files Browse the repository at this point in the history
Newer versions of express seems to add charset to end.
  • Loading branch information
bbyars committed Jun 12, 2011
1 parent c87069b commit 46dfdfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/test/functional/controlServer.test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var testCase = require('nodeunit').testCase,
exports['GET /'] = testCase({ exports['GET /'] = testCase({
'returns base hypermedia': function (test) { 'returns base hypermedia': function (test) {
http.get(controlServerURL + '/', function (response) { http.get(controlServerURL + '/', function (response) {
test.strictEqual(response.headers['content-type'], 'application/vnd.httpmock+json; charset=utf-8'); test.strictEqual(response.headers['content-type'].indexOf('application/vnd.httpmock+json'), 0);
test.jsonEquals(response.body, { test.jsonEquals(response.body, {
links: [{ links: [{
href: controlServerURL + '/servers', href: controlServerURL + '/servers',
Expand Down
11 changes: 9 additions & 2 deletions server/test/testExtensions.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ var web = {
urlParts = url.parse(spec.url), urlParts = url.parse(spec.url),
path = urlParts.pathname + (urlParts.search || ''), path = urlParts.pathname + (urlParts.search || ''),
client = http.createClient(urlParts.port, urlParts.hostname), client = http.createClient(urlParts.port, urlParts.hostname),
request = client.request(spec.method, path, spec.headers); request = client.request(spec.method, path, spec.headers),
contentType;


request.write(JSON.stringify(spec.body)); request.write(JSON.stringify(spec.body));
request.end(); request.end();
Expand All @@ -52,7 +53,8 @@ var web = {
}); });


response.on('end', function () { response.on('end', function () {
if (response.headers['content-type'] === 'application/vnd.httpmock+json; charset=utf-8') { contentType = response.headers['content-type'];
if (contentType && contentType.indexOf('application/vnd.httpmock+json') === 0) {
response.parsedBody = JSON.parse(response.body); response.parsedBody = JSON.parse(response.body);
} }
spec.callback(response); spec.callback(response);
Expand Down Expand Up @@ -166,6 +168,11 @@ var addCustomAsserts = function (test) {
arguments[1](test, mock); arguments[1](test, mock);
} }
}; };

test.matches = function (actual, expectedRegex, message) {
message = message || 'Expected {0} to match {1}.'.format(actual, expectedRegex);
test.ok(expectedRegex.test(actual), message);
};
}; };


nodeunitTypes.test = function () { nodeunitTypes.test = function () {
Expand Down

0 comments on commit 46dfdfa

Please sign in to comment.