Permalink
Browse files

Adding test for opts.headers option

  • Loading branch information...
1 parent 77bc6ff commit bfcfbb51713e5107e11ab7c88faf3930d03e3aca @streunerlein streunerlein committed May 29, 2012
Showing with 77 additions and 0 deletions.
  1. +29 −0 tests/fixtures/opts/headers.json
  2. +48 −0 tests/opts/headers.js
@@ -0,0 +1,29 @@
+[
+ { "method" : "put"
+ , "path" : "/opts_headers"
+ , "status" : 201
+ , "response" : "{ \"ok\": true }"
+ }
+, { "method" : "put"
+ , "path" : "/opts_headers/new/att"
+ , "body" : "\"Hello\""
+ , "status" : 201
+ , "response" : "{\"ok\":true,\"id\":\"new\",\"rev\":\"1-5142a2\"}"
+ }
+, { "path" : "/opts_headers/new/att"
+ , "status" : 304
+ , "response" : ""
+ , "reqHeaders" : {
+ "If-None-Match": "1-5142a2e74e1ec33e6e5b621418210283"
+ }
+ }
+, { "path" : "/opts_headers/new/att"
+ , "status" : 200
+ , "response" : "\"Hello\""
+ }
+, { "method" : "delete"
+ , "path" : "/opts_headers"
+ , "status" : 200
+ , "response" : "{ \"ok\": true }"
+ }
+]
View
@@ -0,0 +1,48 @@
+
+var specify = require('specify')
+ , helpers = require('../helpers')
+ , timeout = helpers.timeout
+ , nano = helpers.nano
+ , nock = helpers.nock
+ ;
+
+var mock = nock(helpers.couch, "opts/headers")
+ , db = nano.use("opts_headers")
+ ;
+
+
+specify("opts_headers:setup", timeout, function (assert) {
+ nano.db.create("opts_headers", function (err) {
+ assert.equal(err, undefined, "Failed to create database");
+ });
+});
+
+specify("opts_headers:test", timeout, function (assert) {
+ db.attachment.insert("new", "att", "Hello", "text/plain",
+ function(error, hello) {
+ assert.equal(error, undefined, "Should store hello");
+ assert.equal(hello.ok, true, "Response should be ok");
+ assert.ok(hello.rev, "Should have a revision number");
+ nano.request({
+ db: "opts_headers",
+ doc: "new",
+ att: "att",
+ headers: {
+ "If-None-Match": "\"1-5142a2e74e1ec33e6e5b621418210283\""
+ }
+ },
+ function (error, helloWorld, rh) {
+ assert.equal(error, undefined, "Should get the hello");
+ assert.equal(rh["status-code"], 304, "status is 'not modified'");
+ });
+ });
+});
+
+specify("opts_headers:teardown", timeout, function (assert) {
+ nano.db.destroy("opts_headers", function (err) {
+ assert.equal(err, undefined, "Failed to destroy database");
+ assert.ok(mock.isDone(), "Some mocks didn't run");
+ });
+});
+
+specify.run(process.argv.slice(2));

0 comments on commit bfcfbb5

Please sign in to comment.