Permalink
Browse files

- Added a .gitignore file that should ignore most non-related nodejs …

…files.

- Created tests for this module.  These tests are meant to be run via Mocha as
  specified in the Makefile.  To run, use 'make test'.
- Updated package.json to include the development dependency for Mocha under
  "devDependencies".
  • Loading branch information...
1 parent 8ede1cf commit 8283febb624bae01ff0e66bf454d236714f1105b James Yuen committed Apr 19, 2013
Showing with 87 additions and 0 deletions.
  1. +20 −0 .gitignore
  2. +13 −0 Makefile
  3. +4 −0 package.json
  4. +50 −0 test/test-connect-acceptoverride.js
View
@@ -0,0 +1,20 @@
+*.seed
+*.log
+*.csv
+*.dat
+*.out
+*.pid
+*.gz
+*.directory*
+*.swo*
+*.swp*
+*.orig*
+*.~*
+*.un~*
+
+pids
+logs
+results
+
+npm-debug.log
+node_modules
View
@@ -0,0 +1,13 @@
+MOCHA_OPTS= --check-leaks
+REPORTER = dot
+
+check: test
+
+test: test-unit test-acceptance
+
+test-unit:
+ @NODE_ENV=test ./node_modules/.bin/mocha \
+ --reporter $(REPORTER) \
+ $(MOCHA_OPTS)
+
+.PHONY: test test-unit test-acceptance benchmark clean
View
@@ -10,6 +10,10 @@
"type": "git",
"url": "git@github.com:olalonde/connect-acceptOverride.git"
},
+ "dependencies":{},
+ "devDependencies": {
+ "mocha": "*"
+ },
"keywords": [
"connect",
"express",
@@ -0,0 +1,50 @@
+var assert = require('assert')
+ , connectAcceptOverride = require('./../index')
+
+describe('Testing that the proper Accept header is being set if a .xml ' +
+ 'or .json extension is given at the end of a url.', function() {
+
+ // Mocking up the request object
+ var getReqObject = function() {
+ var req = {'url': '', 'headers': {'accept':''}};
+ return req;
+ }
+ var defaultURL = 'http://localhost:3000/test';
+
+ it('Should set the Accept header to application/json', function() {
+
+ var req = getReqObject();
+ req.url = defaultURL + '.json';
+
+ connectAcceptOverride()(req, '', function() {});
+ assert.strictEqual(req.headers.accept, 'application/json');
+ })
+
+ it('Should set the Accept header to application/xml', function() {
+
+ var req = getReqObject();
+ req.url = defaultURL + '.xml';
+
+ connectAcceptOverride()(req, '', function() {});
+ assert.strictEqual(req.headers.accept, 'application/xml');
+ })
+
+ it('Should not change the Accept header', function() {
+
+ var req = getReqObject();
+ req.url = defaultURL;
+
+ connectAcceptOverride()(req, '', function() {});
+ assert.strictEqual(req.headers.accept, '');
+ })
+
+ it('Should not change the Accept header (even with weird url where .xml is ' +
+ 'put randomly in the url)', function() {
+
+ var req = getReqObject();
+ req.url = defaultURL + '/asdf.xmlaadsfadfsa';
+
+ connectAcceptOverride()(req, '', function() {});
+ assert.strictEqual(req.headers.accept, '');
+ })
+})

0 comments on commit 8283feb

Please sign in to comment.