From e897a158ae437e89d4a48645d6b334828016041d Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Thu, 2 Apr 2015 21:30:07 -0400 Subject: [PATCH] Splitting up tests --- .jshintrc | 30 -- .npmignore | 1 - .travis.yml | 1 + test/auth_test.js | 331 +++++++++++++++++ test/{tenso_test.js => behavior_test.js} | 431 ----------------------- test/renderers_test.js | 140 ++++++++ 6 files changed, 472 insertions(+), 462 deletions(-) delete mode 100644 .jshintrc create mode 100644 test/auth_test.js rename test/{tenso_test.js => behavior_test.js} (53%) create mode 100644 test/renderers_test.js diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 3fc4041f..00000000 --- a/.jshintrc +++ /dev/null @@ -1,30 +0,0 @@ -{ - "smarttabs": true, - "latedef": true, - "undef": true, - "unused": true, - "proto": true, - "supernew": true, - "quotmark": "double", - "curly": true, - "newcap": true, - "noarg": true, - "noempty": false, - "nonew": true, - "quotmark": "double", - "regexp": false, - "trailing": true, - "boss": true, - "eqnull": true, - "expr": true, - "browser": true, - "loopfunc": true, - "evil": true, - "globals": { - "console": true, - "module": true, - "process": true, - "require": true, - "__dirname": true - } -} \ No newline at end of file diff --git a/.npmignore b/.npmignore index 3141eba8..a6afb8be 100644 --- a/.npmignore +++ b/.npmignore @@ -7,7 +7,6 @@ /sass/ .git .gitignore -.jshintrc .travis.yml docstrap.json Gruntfile.js diff --git a/.travis.yml b/.travis.yml index b04a1b4e..923aae64 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: node_js node_js: + - "0.10" - "0.12" - "iojs" \ No newline at end of file diff --git a/test/auth_test.js b/test/auth_test.js new file mode 100644 index 00000000..356173a8 --- /dev/null +++ b/test/auth_test.js @@ -0,0 +1,331 @@ +var hippie = require( "hippie" ), + tenso = require( "../lib/tenso" ), + routes = require( "./routes.js" ), + array = require( "keigai" ).util.array, + csrf = 'x-csrf-token'; + +function persistCookies ( opts, next ) { + opts.jar = true; + next( opts ); +} + +function api ( port, not_json ) { + var obj = hippie().base( "http://localhost:" + port ).use( persistCookies ); + + return not_json ? obj : obj.expectHeader( "Content-Type", "application/json" ).json(); +} + +function get_token ( port, fn, url ) { + return api( port ).get( url || "/login" ).end( fn ); +} + +process.setMaxListeners(0); + +describe( "Permissions (CSRF disabled)", function () { + var port = 8001; + + tenso( { port: port, routes: routes, logs: { level: "error" }, security: { csrf: false } } ); + + it( "GET / - returns an array of endpoints", function ( done ) { + api( port ) + .get( "/" ) + .expectStatus( 200 ) + .expectHeader( "allow", "GET, HEAD, OPTIONS" ) + .expectValue( "data.link", [ { + uri: "http://localhost:" + port + "/items", + rel: "item" + }, { uri: "http://localhost:" + port + "/things", rel: "item" } ] ) + .expectValue( "data.result", [ "/items", "/things" ] ) + .expectValue( "error", null ) + .expectValue( "status", 200 ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "GET /invalid - returns a 'not found' error", function ( done ) { + api( port ) + .get( "/invalid" ) + .expectStatus( 404 ) + .expectValue( "data", null ) + .expectValue( "error", "Not Found" ) + .expectValue( "status", 404 ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "DELETE / - returns a 'method not allowed' error", function ( done ) { + api( port ) + .del( "/" ) + .expectStatus( 405 ) + .expectValue( "data", null ) + .expectValue( "error", "Method Not Allowed" ) + .expectValue( "status", 405 ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "POST / - returns a 'method not allowed' error", function ( done ) { + api( port ) + .post( "/" ) + .expectStatus( 405 ) + .expectValue( "data", null ) + .expectValue( "error", "Method Not Allowed" ) + .expectValue( "status", 405 ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "PUT / - returns a 'method not allowed' error", function ( done ) { + api( port ) + .put( "/" ) + .expectStatus( 405 ) + .expectValue( "data", null ) + .expectValue( "error", "Method Not Allowed" ) + .expectValue( "status", 405 ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "PATCH / - returns a 'method not allowed' error", function ( done ) { + api( port ) + .patch( "/" ) + .expectStatus( 405 ) + .expectValue( "data", null ) + .expectValue( "error", "Method Not Allowed" ) + .expectValue( "status", 405 ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); +} ); + +describe( "Basic Auth", function () { + var port = 8004; + + tenso( { + port: port, + routes: routes, + logs: { level: "error" }, + auth: { basic: { enabled: true, list: [ "test:123" ] }, protect: [ "/uuid" ] } + } ); + + it( "GET / - returns links", function ( done ) { + api( port ) + .get( "/" ) + .expectStatus( 200 ) + .expectValue( "data.link", [ { + uri: "http://localhost:" + port + "/items", + rel: "item" + }, { uri: "http://localhost:" + port + "/things", rel: "item" } ] ) + .expectValue( "data.result", [ "/items", "/things" ] ) + .expectValue( "error", null ) + .expectValue( "status", 200 ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "GET /uuid - returns a uuid (authorized)", function ( done ) { + api( port ) + .auth( 'test', '123' ) + .get( "/uuid" ) + .expectStatus( 200 ) + .expectValue( "data.link", [ { uri: "http://localhost:" + port, rel: "collection" } ] ) + .expectValue( "error", null ) + .expectValue( "status", 200 ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "GET /uuid - returns an 'unauthorized' error", function ( done ) { + api( port, true ) + .get( "/uuid" ) + .expectStatus( 401 ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); +} ); + +describe( "OAuth2 Token Bearer", function () { + var port = 8005; + + tenso( { + port: port, + routes: routes, + logs: { level: "error" }, + auth: { bearer: { enabled: true, tokens: [ "abc-123" ] }, protect: [ "/" ] } + } ); + + it( "GET / - returns an array of endpoints (authorized)", function ( done ) { + api( port ) + .header( 'Authorization', 'Bearer abc-123' ) + .get( "/" ) + .expectStatus( 200 ) + .expectValue( "data.link", [ { + uri: "http://localhost:" + port + "/items", + rel: "item" + }, { uri: "http://localhost:" + port + "/things", rel: "item" } ] ) + .expectValue( "data.result", [ "/items", "/things" ] ) + .expectValue( "error", null ) + .expectValue( "status", 200 ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "GET / - returns an 'unauthorized' error", function ( done ) { + api( port, true ) + .get( "/" ) + .expectStatus( 401 ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); +} ); + +describe( "Local", function () { + var port = 8006; + + tenso( { + port: port, + routes: require( "./routes.js" ), + logs: { + level: "error", + dtrace: true, + stderr: true + }, + auth: { + local: { + enabled: true, + auth: function ( username, password, callback ) { + if ( username === "test" && password === 123 ) { + callback( null, { username: username, password: password } ); + } + else { + callback( true, null ); + } + } + }, + protect: [ "/uuid" ] + } + } ); + + it( "GET /uuid (invalid) - returns an 'unauthorized' error", function ( done ) { + api( port, true ) + .get( "/uuid" ) + .expectStatus( 302 ) + .expectHeader( "Location", "/login" ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "GET /login - returns an authentication message", function ( done ) { + api( port ) + .get( "/login" ) + .expectStatus( 200 ) + .expectValue( "data.link", [ { uri: "http://localhost:" + port, rel: "collection" } ] ) + .expectValue( "data.result", { instruction: "POST 'username' & 'password' to authenticate" } ) + .expectValue( "error", null ) + .expectValue( "status", 200 ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "POST /login (invalid / no CSRF token) - returns an 'unauthorized' error", function ( done ) { + api( port ) + .post( "/login" ) + .form() + .send( { username: "test", password: 1232 } ) + .expectStatus( 403 ) + .expectValue( "data", null ) + .expectValue( "error", "CSRF token mismatch" ) + .expectValue( "status", 403 ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "POST /login (invalid) - returns an 'unauthorized' error", function ( done ) { + get_token( port, function ( err, res ) { + var token; + + if ( err ) throw err; + + token = res.headers[ csrf ]; + + api( port, true ) + .header( csrf, token ) + .post( "/login" ) + .form() + .send( { username: "test", password: 1232 } ) + .json() + .expectStatus( 401 ) + .expectValue( "data", null ) + .expectValue( "error", "Unauthorized" ) + .expectValue( "status", 401 ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + } ); + + // needs to reuse the session cookie header for identification + it( "POST /login - redirects to a predetermined URI", function ( done ) { + get_token( port, function ( err, res ) { + var token; + + if ( err ) throw err; + + token = res.headers[ csrf ]; + + api( port, true ) + .header( csrf, token ) + .post( "/login" ) + .form() + .send( { username: "test", password: 123 } ) + .expectStatus( 302 ) + .expectHeader( "Location", "/" ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + } ); + + it( "GET /uuid (session) - returns a version 4 uuid", function ( done ) { + api( port ) + .get( "/uuid" ) + .expectStatus( 200 ) + .expectValue( "data.link", [ { uri: "http://localhost:" + port, rel: "collection" } ] ) + .expectValue( "error", null ) + .expectValue( "status", 200 ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); +} ); \ No newline at end of file diff --git a/test/tenso_test.js b/test/behavior_test.js similarity index 53% rename from test/tenso_test.js rename to test/behavior_test.js index fc94357a..31b315cb 100644 --- a/test/tenso_test.js +++ b/test/behavior_test.js @@ -21,95 +21,6 @@ function get_token ( port, fn, url ) { process.setMaxListeners(0); -describe( "Permissions (CSRF disabled)", function () { - var port = 8001; - - tenso( { port: port, routes: routes, logs: { level: "error" }, security: { csrf: false } } ); - - it( "GET / - returns an array of endpoints", function ( done ) { - api( port ) - .get( "/" ) - .expectStatus( 200 ) - .expectHeader( "allow", "GET, HEAD, OPTIONS" ) - .expectValue( "data.link", [ { - uri: "http://localhost:" + port + "/items", - rel: "item" - }, { uri: "http://localhost:" + port + "/things", rel: "item" } ] ) - .expectValue( "data.result", [ "/items", "/things" ] ) - .expectValue( "error", null ) - .expectValue( "status", 200 ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "GET /invalid - returns a 'not found' error", function ( done ) { - api( port ) - .get( "/invalid" ) - .expectStatus( 404 ) - .expectValue( "data", null ) - .expectValue( "error", "Not Found" ) - .expectValue( "status", 404 ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "DELETE / - returns a 'method not allowed' error", function ( done ) { - api( port ) - .del( "/" ) - .expectStatus( 405 ) - .expectValue( "data", null ) - .expectValue( "error", "Method Not Allowed" ) - .expectValue( "status", 405 ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "POST / - returns a 'method not allowed' error", function ( done ) { - api( port ) - .post( "/" ) - .expectStatus( 405 ) - .expectValue( "data", null ) - .expectValue( "error", "Method Not Allowed" ) - .expectValue( "status", 405 ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "PUT / - returns a 'method not allowed' error", function ( done ) { - api( port ) - .put( "/" ) - .expectStatus( 405 ) - .expectValue( "data", null ) - .expectValue( "error", "Method Not Allowed" ) - .expectValue( "status", 405 ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "PATCH / - returns a 'method not allowed' error", function ( done ) { - api( port ) - .patch( "/" ) - .expectStatus( 405 ) - .expectValue( "data", null ) - .expectValue( "error", "Method Not Allowed" ) - .expectValue( "status", 405 ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); -} ); - describe( "Pagination", function () { var port = 8002; @@ -336,226 +247,6 @@ describe( "Hypermedia", function () { } ); } ); -describe( "Basic Auth", function () { - var port = 8004; - - tenso( { - port: port, - routes: routes, - logs: { level: "error" }, - auth: { basic: { enabled: true, list: [ "test:123" ] }, protect: [ "/uuid" ] } - } ); - - it( "GET / - returns links", function ( done ) { - api( port ) - .get( "/" ) - .expectStatus( 200 ) - .expectValue( "data.link", [ { - uri: "http://localhost:" + port + "/items", - rel: "item" - }, { uri: "http://localhost:" + port + "/things", rel: "item" } ] ) - .expectValue( "data.result", [ "/items", "/things" ] ) - .expectValue( "error", null ) - .expectValue( "status", 200 ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "GET /uuid - returns a uuid (authorized)", function ( done ) { - api( port ) - .auth( 'test', '123' ) - .get( "/uuid" ) - .expectStatus( 200 ) - .expectValue( "data.link", [ { uri: "http://localhost:" + port, rel: "collection" } ] ) - .expectValue( "error", null ) - .expectValue( "status", 200 ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "GET /uuid - returns an 'unauthorized' error", function ( done ) { - api( port, true ) - .get( "/uuid" ) - .expectStatus( 401 ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); -} ); - -describe( "OAuth2 Token Bearer", function () { - var port = 8005; - - tenso( { - port: port, - routes: routes, - logs: { level: "error" }, - auth: { bearer: { enabled: true, tokens: [ "abc-123" ] }, protect: [ "/" ] } - } ); - - it( "GET / - returns an array of endpoints (authorized)", function ( done ) { - api( port ) - .header( 'Authorization', 'Bearer abc-123' ) - .get( "/" ) - .expectStatus( 200 ) - .expectValue( "data.link", [ { - uri: "http://localhost:" + port + "/items", - rel: "item" - }, { uri: "http://localhost:" + port + "/things", rel: "item" } ] ) - .expectValue( "data.result", [ "/items", "/things" ] ) - .expectValue( "error", null ) - .expectValue( "status", 200 ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "GET / - returns an 'unauthorized' error", function ( done ) { - api( port, true ) - .get( "/" ) - .expectStatus( 401 ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); -} ); - -describe( "Local", function () { - var port = 8006; - - tenso( { - port: port, - routes: require( "./routes.js" ), - logs: { - level: "error", - dtrace: true, - stderr: true - }, - auth: { - local: { - enabled: true, - auth: function ( username, password, callback ) { - if ( username === "test" && password === 123 ) { - callback( null, { username: username, password: password } ); - } - else { - callback( true, null ); - } - } - }, - protect: [ "/uuid" ] - } - } ); - - it( "GET /uuid (invalid) - returns an 'unauthorized' error", function ( done ) { - api( port, true ) - .get( "/uuid" ) - .expectStatus( 302 ) - .expectHeader( "Location", "/login" ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "GET /login - returns an authentication message", function ( done ) { - api( port ) - .get( "/login" ) - .expectStatus( 200 ) - .expectValue( "data.link", [ { uri: "http://localhost:" + port, rel: "collection" } ] ) - .expectValue( "data.result", { instruction: "POST 'username' & 'password' to authenticate" } ) - .expectValue( "error", null ) - .expectValue( "status", 200 ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "POST /login (invalid / no CSRF token) - returns an 'unauthorized' error", function ( done ) { - api( port ) - .post( "/login" ) - .form() - .send( { username: "test", password: 1232 } ) - .expectStatus( 403 ) - .expectValue( "data", null ) - .expectValue( "error", "CSRF token mismatch" ) - .expectValue( "status", 403 ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "POST /login (invalid) - returns an 'unauthorized' error", function ( done ) { - get_token( port, function ( err, res ) { - var token; - - if ( err ) throw err; - - token = res.headers[ csrf ]; - - api( port, true ) - .header( csrf, token ) - .post( "/login" ) - .form() - .send( { username: "test", password: 1232 } ) - .json() - .expectStatus( 401 ) - .expectValue( "data", null ) - .expectValue( "error", "Unauthorized" ) - .expectValue( "status", 401 ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - } ); - - // needs to reuse the session cookie header for identification - it( "POST /login - redirects to a predetermined URI", function ( done ) { - get_token( port, function ( err, res ) { - var token; - - if ( err ) throw err; - - token = res.headers[ csrf ]; - - api( port, true ) - .header( csrf, token ) - .post( "/login" ) - .form() - .send( { username: "test", password: 123 } ) - .expectStatus( 302 ) - .expectHeader( "Location", "/" ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - } ); - - it( "GET /uuid (session) - returns a version 4 uuid", function ( done ) { - api( port ) - .get( "/uuid" ) - .expectStatus( 200 ) - .expectValue( "data.link", [ { uri: "http://localhost:" + port, rel: "collection" } ] ) - .expectValue( "error", null ) - .expectValue( "status", 200 ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); -} ); - describe( "Rate Limiting", function () { var port = 8007; @@ -730,125 +421,3 @@ describe( "Request body max byte size", function () { }, "/test" ); } ); } ); - -describe( "Renderers", function () { - var port = 8010, server; - - server = tenso( { port: port, routes: routes, logs: { level: "error" } } ); - server.renderer( "custom", function ( arg ) { return arg; }, "application/json"); - - it( "GET CSV (header)", function ( done ) { - api( port, true ) - .get( "/" ) - .header( "accept", "text/csv" ) - .expectStatus( 200 ) - .expectHeader( "Content-Type", "text/csv" ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "GET CSV (query string)", function ( done ) { - api( port, true ) - .get( "/?format=csv" ) - .expectStatus( 200 ) - .expectHeader( "Content-Type", "text/csv" ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "GET HTML (header)", function ( done ) { - api( port, true ) - .get( "/" ) - .header( "accept", "text/html" ) - .expectStatus( 200 ) - .expectHeader( "Content-Type", "text/html" ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "GET HTML (query string)", function ( done ) { - api( port, true ) - .get( "/?format=html" ) - .expectStatus( 200 ) - .expectHeader( "Content-Type", "text/html" ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "GET YAML (header)", function ( done ) { - api( port, true ) - .get( "/" ) - .header( "accept", "application/yaml" ) - .expectStatus( 200 ) - .expectHeader( "Content-Type", "application/yaml" ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "GET YAML (query string)", function ( done ) { - api( port, true ) - .get( "/?format=yaml" ) - .expectStatus( 200 ) - .expectHeader( "Content-Type", "application/yaml" ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "GET XML (header)", function ( done ) { - api( port, true ) - .get( "/" ) - .header( "accept", "application/xml" ) - .expectStatus( 200 ) - .expectHeader( "Content-Type", "application/xml" ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "GET XML (query string)", function ( done ) { - api( port, true ) - .get( "/?format=xml" ) - .expectStatus( 200 ) - .expectHeader( "Content-Type", "application/xml" ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "GET Custom (header)", function ( done ) { - api( port, true ) - .get( "/" ) - .header( "accept", "application/custom" ) - .expectStatus( 200 ) - .expectHeader( "Content-Type", "application/json" ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); - - it( "GET Custom (query string)", function ( done ) { - api( port, true ) - .get( "/?format=custom" ) - .expectStatus( 200 ) - .expectHeader( "Content-Type", "application/json" ) - .end( function ( err ) { - if ( err ) throw err; - done(); - } ); - } ); -} ); \ No newline at end of file diff --git a/test/renderers_test.js b/test/renderers_test.js new file mode 100644 index 00000000..49b76571 --- /dev/null +++ b/test/renderers_test.js @@ -0,0 +1,140 @@ +var hippie = require( "hippie" ), + tenso = require( "../lib/tenso" ), + routes = require( "./routes.js" ), + array = require( "keigai" ).util.array, + csrf = 'x-csrf-token'; + +function persistCookies ( opts, next ) { + opts.jar = true; + next( opts ); +} + +function api ( port, not_json ) { + var obj = hippie().base( "http://localhost:" + port ).use( persistCookies ); + + return not_json ? obj : obj.expectHeader( "Content-Type", "application/json" ).json(); +} + +process.setMaxListeners(0); + +describe( "Renderers", function () { + var port = 8010, server; + + server = tenso( { port: port, routes: routes, logs: { level: "error" } } ); + server.renderer( "custom", function ( arg ) { return arg; }, "application/json"); + + it( "GET CSV (header)", function ( done ) { + api( port, true ) + .get( "/" ) + .header( "accept", "text/csv" ) + .expectStatus( 200 ) + .expectHeader( "Content-Type", "text/csv" ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "GET CSV (query string)", function ( done ) { + api( port, true ) + .get( "/?format=csv" ) + .expectStatus( 200 ) + .expectHeader( "Content-Type", "text/csv" ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "GET HTML (header)", function ( done ) { + api( port, true ) + .get( "/" ) + .header( "accept", "text/html" ) + .expectStatus( 200 ) + .expectHeader( "Content-Type", "text/html" ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "GET HTML (query string)", function ( done ) { + api( port, true ) + .get( "/?format=html" ) + .expectStatus( 200 ) + .expectHeader( "Content-Type", "text/html" ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "GET YAML (header)", function ( done ) { + api( port, true ) + .get( "/" ) + .header( "accept", "application/yaml" ) + .expectStatus( 200 ) + .expectHeader( "Content-Type", "application/yaml" ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "GET YAML (query string)", function ( done ) { + api( port, true ) + .get( "/?format=yaml" ) + .expectStatus( 200 ) + .expectHeader( "Content-Type", "application/yaml" ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "GET XML (header)", function ( done ) { + api( port, true ) + .get( "/" ) + .header( "accept", "application/xml" ) + .expectStatus( 200 ) + .expectHeader( "Content-Type", "application/xml" ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "GET XML (query string)", function ( done ) { + api( port, true ) + .get( "/?format=xml" ) + .expectStatus( 200 ) + .expectHeader( "Content-Type", "application/xml" ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "GET Custom (header)", function ( done ) { + api( port, true ) + .get( "/" ) + .header( "accept", "application/custom" ) + .expectStatus( 200 ) + .expectHeader( "Content-Type", "application/json" ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); + + it( "GET Custom (query string)", function ( done ) { + api( port, true ) + .get( "/?format=custom" ) + .expectStatus( 200 ) + .expectHeader( "Content-Type", "application/json" ) + .end( function ( err ) { + if ( err ) throw err; + done(); + } ); + } ); +} );