This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
105 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
|
||
var mock = nock(helpers.couch, "doc/insert") | ||
, db = nano.use("doc_insert") | ||
; | ||
|
||
specify("doc_insert:setup", timeout, function (assert) { | ||
nano.db.create("doc_insert", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
}); | ||
}); | ||
|
||
specify("doc_insert:simple", timeout, function (assert) { | ||
db.insert({"foo": "baz"}, "foobaz", function (error, foo) { | ||
assert.equal(error, undefined, "Should have stored foo"); | ||
assert.equal(foo.ok, true, "Response should be ok"); | ||
assert.ok(foo.rev, "Response should have rev"); | ||
}); | ||
}); | ||
|
||
specify("doc_insert:functions", timeout, function (assert) { | ||
db.insert({fn: function () { return true; }, | ||
fn2: "function () { return true; }"}, function (error, fns) { | ||
assert.equal(error, undefined, "Should have stored foo"); | ||
assert.equal(fns.ok, true, "Response should be ok"); | ||
assert.ok(fns.rev, "Response should have rev"); | ||
db.get(fns.id, function (error, fns) { | ||
assert.equal(fns.fn, fns.fn2, "fn matches fn2"); | ||
assert.equal(error, undefined, "Should get foo"); | ||
}); | ||
}); | ||
}); | ||
|
||
specify("doc_insert:streaming", timeout, function (assert) { | ||
var buffer = "" | ||
, foobar = db.insert({"foo": "bar"}) | ||
; | ||
|
||
function runAssertions(error, foobar) { | ||
assert.equal(error, undefined, "Should have stored foobar"); | ||
assert.ok(foobar.ok, "This is ok"); | ||
assert.ok(foobar.rev, "I GOT REVZ"); | ||
} | ||
|
||
foobar.on('data', function(chunk) { buffer += chunk; }); | ||
foobar.on('end', function () { runAssertions(null, JSON.parse(buffer)); }); | ||
foobar.on('error', runAssertions); | ||
}); | ||
|
||
specify("doc_insert:teardown", timeout, function (assert) { | ||
nano.db.destroy("doc_insert", 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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[ | ||
{ "method" : "put" | ||
, "path" : "/doc_insert" | ||
, "status" : 201 | ||
, "response" : "{ \"ok\": true }" | ||
} | ||
, { "method" : "put" | ||
, "status" : 201 | ||
, "path" : "/doc_insert/foobaz" | ||
, "body" : "{\"foo\":\"baz\"}" | ||
, "response" : "{\"ok\":true,\"id\":\"foobaz\",\"rev\":\"1-611488\"}" | ||
} | ||
, { "method" : "post" | ||
, "status" : 201 | ||
, "path" : "/doc_insert" | ||
, "body" : "{\"fn\":\"function () { return true; }\",\"fn2\":\"function () { return true; }\"}" | ||
, "response" : "{\"ok\":true,\"id\":\"123\",\"rev\":\"1-611488\"}" | ||
} | ||
, { "path" : "/doc_insert/123" | ||
, "response" : "{\"fn\":\"function () { return true; }\",\"fn2\":\"function () { return true; }\",\"id\":\"123\",\"rev\":\"1-611488\"}" | ||
} | ||
, { "method" : "post" | ||
, "status" : 201 | ||
, "path" : "/doc_insert" | ||
, "body" : "{\"foo\":\"bar\"}" | ||
, "response" : "{\"ok\":true,\"id\":\"234\",\"rev\":\"1-333231\"}" | ||
} | ||
, { "method" : "delete" | ||
, "path" : "/doc_insert/foobaz?rev=1-611488" | ||
, "response" : "{\"ok\":true}" | ||
} | ||
, { "method" : "delete" | ||
, "path" : "/doc_insert" | ||
, "response" : "{ \"ok\": true }" | ||
} | ||
] |