Permalink
Browse files

Users.update,getById,deletebyId.

  • Loading branch information...
1 parent 95d2328 commit 9c4d15ba6f297c72f875854eefb91fcf185a6c27 @robey committed Apr 12, 2013
Showing with 45 additions and 0 deletions.
  1. +6 −0 src/fauna/fauna_client.coffee
  2. +39 −0 test/test_users.coffee
@@ -211,6 +211,12 @@ class FaunaClient
@rest("post", "users", data)
getByEmail: requirePublisher asObject (email) -> @rest("get", "users/email/#{escape(email)}")
getByUniqueId: requirePublisher asObject (uniqueId) -> @rest("get", "users/unique_id/#{uniqueId}")
+ update: requireTokenOrPublisher asObject (user) ->
+ data = @schema.deflate(user)
+ for key in [ "email", "unique_id", "password" ] then if user[key]? then data[key] = user[key]
+ @rest("put", "#{user._fauna.id}", data)
+ getById: requireTokenOrPublisher asObject assertNamespace("users") (id) -> @rest("get", "#{id}")
+ deleteById: requireTokenOrPublisher assertNamespace("users") (id) -> @rest("delete", "#{id}")
list: requirePublisher (params) -> @eventSets.get("users", params)
# wrapper to allow easy testing of the decorators
View
@@ -57,6 +57,45 @@ describe "FaunaClient.users", ->
users.length.should.eql(1)
users[0].unique_id.should.eql("taran186")
+ it "update", futureTest ->
+ class User extends fauna.Class
+ @native()
+ @field "zipcode"
+ f = new fauna.FaunaClient()
+ f.addPrototypes User
+ f.setPublisherKey("qqq")
+ user = f.unpack(JSON.parse(data2))
+ user.zipcode = 94043
+ r = -> f.users.update(user)
+ withSuccessfulRequest(data2, r).then ([ resp, requests ]) ->
+ requests.length.should.eql(1)
+ requests[0].method.should.eql "PUT"
+ requests[0].url.should.match(/\/users\/30159234491482113/)
+ requests[0].body.should.match(/"unique_id":"taran186"/)
+ requests[0].body.should.match(/"zipcode":94043/)
+ resp._fauna.id.should.eql("users/30159234491482113")
+
+ it "getById", futureTest ->
+ f = new fauna.FaunaClient()
+ f.setPublisherKey("c")
+ r = -> f.users.getById("users/30159234491482113")
+ withSuccessfulRequest(data2, r).then ([ resp, requests ]) ->
+ requests.length.should.eql(1)
+ requests[0].method.should.eql "GET"
+ requests[0].url.should.match(/\/users\/30159234491482113/)
+ resp._fauna.id.should.eql("users/30159234491482113")
+
+ it "deleteById", futureTest ->
+ f = new fauna.FaunaClient()
+ f.setPublisherKey("c")
+ r = -> f.users.deleteById("users/30159234491482113")
+ handler = (options) -> [ null, 204, null ]
+ fauna.Rest.withRequestHandler(handler, r).then ([ resp, requests ]) ->
+ requests.length.should.eql(1)
+ requests[0].method.should.eql "DELETE"
+ requests[0].url.should.match(/\/users\/30159234491482113/)
+
+
data1 = """
{
"resource" : {

0 comments on commit 9c4d15b

Please sign in to comment.