2014-08-01 00:05:30 +08:00
|
|
|
var tap = require("tap")
|
2012-07-14 02:40:38 +08:00
|
|
|
|
2014-08-01 00:05:30 +08:00
|
|
|
var server = require("./lib/server.js")
|
|
|
|
var common = require("./lib/common.js")
|
|
|
|
var client = common.freshClient()
|
2012-07-14 02:40:38 +08:00
|
|
|
|
2014-09-17 06:38:50 +08:00
|
|
|
var password = "%1234@asdf%"
|
2012-07-14 02:40:38 +08:00
|
|
|
, username = "username"
|
2014-08-01 00:05:30 +08:00
|
|
|
, email = "i@izs.me"
|
|
|
|
, userdata = {
|
|
|
|
name: username,
|
|
|
|
email: email,
|
|
|
|
_id: "org.couchdb.user:username",
|
|
|
|
type: "user",
|
|
|
|
roles: [],
|
|
|
|
date: "2012-06-07T04:11:21.591Z" }
|
|
|
|
, SD = require("string_decoder").StringDecoder
|
|
|
|
, decoder = new SD()
|
2012-07-14 02:40:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
tap.test("update a user acct", function (t) {
|
|
|
|
server.expect("PUT", "/-/user/org.couchdb.user:username", function (req, res) {
|
|
|
|
t.equal(req.method, "PUT")
|
|
|
|
res.statusCode = 409
|
|
|
|
res.json({error: "conflict"})
|
|
|
|
})
|
|
|
|
|
2014-02-17 12:43:16 +08:00
|
|
|
server.expect("GET", "/-/user/org.couchdb.user:username?write=true", function (req, res) {
|
2012-07-14 02:40:38 +08:00
|
|
|
t.equal(req.method, "GET")
|
|
|
|
res.json(userdata)
|
|
|
|
})
|
|
|
|
|
|
|
|
server.expect("PUT", "/-/user/org.couchdb.user:username/-rev/" + userdata._rev, function (req, res) {
|
|
|
|
t.equal(req.method, "PUT")
|
|
|
|
|
|
|
|
var b = ""
|
|
|
|
req.on("data", function (d) {
|
|
|
|
b += decoder.write(d)
|
|
|
|
})
|
|
|
|
|
|
|
|
req.on("end", function () {
|
|
|
|
var o = JSON.parse(b)
|
2014-03-20 00:25:40 +08:00
|
|
|
userdata.password = password
|
2012-07-14 02:40:38 +08:00
|
|
|
userdata.date = o.date
|
|
|
|
t.deepEqual(o, userdata)
|
|
|
|
|
|
|
|
res.statusCode = 201
|
|
|
|
res.json({created:true})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2014-08-01 00:05:30 +08:00
|
|
|
client.adduser("http://localhost:1337/", username, password, email, function (er, data) {
|
2012-07-14 02:40:38 +08:00
|
|
|
if (er) throw er
|
|
|
|
t.deepEqual(data, { created: true })
|
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
})
|