diff options
author | Carlos Tadeu Panato Junior <ctadeu@gmail.com> | 2017-05-10 13:46:52 +0200 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-05-10 07:46:52 -0400 |
commit | 7a927c03e4cfe8f14d254219ec54f76c2349598e (patch) | |
tree | dac5419cd126fc2ed53029b4fb886855286601fd /model/client4.go | |
parent | 16581ae431ffeae97db18eb8672232505a7ce3c0 (diff) | |
download | chat-7a927c03e4cfe8f14d254219ec54f76c2349598e.tar.gz chat-7a927c03e4cfe8f14d254219ec54f76c2349598e.tar.bz2 chat-7a927c03e4cfe8f14d254219ec54f76c2349598e.zip |
Add tests for CreateUserWithInviteId and CreateUserWithHash (#6363)
Diffstat (limited to 'model/client4.go')
-rw-r--r-- | model/client4.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/model/client4.go b/model/client4.go index 91c5b2b5f..2e11d98b1 100644 --- a/model/client4.go +++ b/model/client4.go @@ -451,6 +451,40 @@ func (c *Client4) CreateUser(user *User) (*User, *Response) { } } +// CreateUserWithHash creates a user in the system based on the provided user struct and hash created. +func (c *Client4) CreateUserWithHash(user *User, hash, data string) (*User, *Response) { + var query string + if hash != "" && data != "" { + query = fmt.Sprintf("?d=%v&h=%v", url.QueryEscape(data), hash) + } else { + err := NewAppError("MissingHashOrData", "api.user.create_user.missing_hash_or_data.app_error", nil, "", http.StatusBadRequest) + return nil, &Response{StatusCode: err.StatusCode, Error: err} + } + if r, err := c.DoApiPost(c.GetUsersRoute()+query, user.ToJson()); err != nil { + return nil, &Response{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return UserFromJson(r.Body), BuildResponse(r) + } +} + +// CreateUserWithInviteId creates a user in the system based on the provided invited id. +func (c *Client4) CreateUserWithInviteId(user *User, inviteId string) (*User, *Response) { + var query string + if inviteId != "" { + query = fmt.Sprintf("?iid=%v", url.QueryEscape(inviteId)) + } else { + err := NewAppError("MissingInviteId", "api.user.create_user.missing_invite_id.app_error", nil, "", http.StatusBadRequest) + return nil, &Response{StatusCode: err.StatusCode, Error: err} + } + if r, err := c.DoApiPost(c.GetUsersRoute()+query, user.ToJson()); err != nil { + return nil, &Response{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return UserFromJson(r.Body), BuildResponse(r) + } +} + // GetMe returns the logged in user. func (c *Client4) GetMe(etag string) (*User, *Response) { if r, err := c.DoApiGet(c.GetUserRoute(ME), etag); err != nil { |