This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[tests] doc update;
- Loading branch information
Showing
2 changed files
with
54 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,39 @@ | ||
var ensure = require('ensure') | ||
, nock = require('nock') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("doc_up") | ||
, tests = exports | ||
, couch | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
|
||
couch = nock(cfg.url) | ||
.put('/' + db_name('a')) | ||
.reply(201, "{\"ok\":true}\n", | ||
{ server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)', | ||
location: cfg.url + '/' + db_name('a'), | ||
date: 'Fri, 02 Dec 2011 19:38:03 GMT', | ||
'content-type': 'application/json', | ||
'content-length': '12', | ||
'cache-control': 'must-revalidate' }) | ||
.put('/' + db_name('a') + '/foo', {"foo": "bar"}) | ||
.reply(201, "{\"ok\": true,\"id\": \"foo\",\"rev\": \"1-4c6114c65e295552ab1019e2b046b10e\"}\n", | ||
{ server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)', | ||
location: cfg.url + '/' + db_name('a') + '/foo', | ||
etag: '"1-4c6114c65e295552ab1019e2b046b10e"', | ||
date: 'Fri, 02 Dec 2011 19:38:04 GMT', | ||
'content-type': 'application/json', | ||
'content-length': '66', | ||
'cache-control': 'must-revalidate' }) | ||
.put('/' + db_name('a') + '/foo', | ||
{ "_rev": "1-4c6114c65e295552ab1019e2b046b10e" | ||
, "foo": "baz" | ||
}) | ||
.reply(201, "{\"ok\": true,\"id\": \"foo\",\"rev\": \"2-cfcd6781f13994bde69a1c3320bfdadb\"}\n", | ||
{ server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)', | ||
location: cfg.url + '/' + db_name('a') + '/foo', | ||
etag: '"2-cfcd6781f13994bde69a1c3320bfdadb"', | ||
date: 'Fri, 02 Dec 2011 19:38:04 GMT', | ||
'content-type': 'application/json', | ||
'content-length': '66', | ||
'cache-control': 'must-revalidate' }); | ||
|
||
function db(i) { return nano.use(db_name(i)); } | ||
var mock = nock(helpers.couch, "doc/update") | ||
, db = nano.use("doc_update") | ||
, rev | ||
; | ||
|
||
tests.update_doc = function (callback) { | ||
nano.db.create(db_name('a'), function () { | ||
db('a').insert({foo: "bar"}, "foo", function (_,b) { | ||
db('a').insert({"_rev": b.rev, foo: "baz"}, "foo", callback); | ||
specify("doc_update:setup", timeout, function (assert) { | ||
nano.db.create("doc_update", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
db.insert({"foo": "baz"}, "foobar", 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"); | ||
rev = foo.rev; | ||
}); | ||
}); | ||
}; | ||
}); | ||
|
||
tests.update_doc_ok = function (e,b) { | ||
this.t.notOk(e, 'I got err free status'); | ||
this.t.equal(b.id, "foo", 'My filename is foo'); | ||
this.t.ok(b.ok, 'I am now ok'); | ||
this.t.ok(b.rev, 'I got rev'); | ||
this.t.ok(couch.isDone(), 'Nock is done'); | ||
}; | ||
specify("doc_update:test", timeout, function (assert) { | ||
db.insert({foo: "bar", "_rev": rev}, "foobar", function (error, response) { | ||
assert.equal(error, undefined, "Should have deleted foo"); | ||
assert.equal(response.ok, true, "Response should be ok"); | ||
}); | ||
}); | ||
|
||
specify("doc_update:teardown", timeout, function (assert) { | ||
nano.db.destroy("doc_update", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
|
||
ensure(__filename,tests,module,process.argv[2]); | ||
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,22 @@ | ||
[ | ||
{ "method" : "put" | ||
, "path" : "/doc_update" | ||
, "status" : 201 | ||
, "response" : "{ \"ok\": true }" | ||
} | ||
, { "method" : "put" | ||
, "status" : 201 | ||
, "path" : "/doc_update/foobar" | ||
, "body" : "{\"foo\":\"baz\"}" | ||
, "response" : "{\"ok\":true,\"id\":\"foobar\",\"rev\":\"1-611488\"}" | ||
} | ||
, { "method" : "put" | ||
, "path" : "/doc_update/foobar" | ||
, "response" : "{\"ok\":true,\"id\":\"foobar\",\"rev\":\"2-2ff408\"}" | ||
, "body" : "{\"foo\":\"bar\",\"_rev\":\"1-611488\"}" | ||
} | ||
, { "method" : "delete" | ||
, "path" : "/doc_update" | ||
, "response" : "{ \"ok\": true }" | ||
} | ||
] |