From 6b9ca27c67d043a8737da652bf7915645628db4c Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Fri, 1 Apr 2016 15:58:08 -0400 Subject: add_user test --- src/guff/api/methods.cr | 37 +++++++++++++++++++++++++++++++++++++ src/guff/api/test.cr | 9 +++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) (limited to 'src/guff/api') diff --git a/src/guff/api/methods.cr b/src/guff/api/methods.cr index 8df48d5..970e41f 100644 --- a/src/guff/api/methods.cr +++ b/src/guff/api/methods.cr @@ -366,6 +366,42 @@ module Guff }, }, }, + + "add_user": { + text: "Add new user", + + args: { + "name": { + text: "Name of user", + type: :text, + required: true, + }, + + "active": { + text: "Is this user active?", + type: :bool, + required: false, + }, + + "role": { + text: "Role of user", + type: :text, + required: false, + }, + + "email": { + text: "Email address of user", + type: :text, + required: false, + }, + + "password": { + text: "Password of user", + type: :text, + required: false, + }, + }, + }, } } @@ -375,6 +411,7 @@ module Guff int: /^\d+$/, int_list: /^\d+(?:,\d+)*$/, state: /^(?:draft|posted|deleted)$/, + bool: /^t|f$/, # FIXME: lock these down more json: /.*/, diff --git a/src/guff/api/test.cr b/src/guff/api/test.cr index 3a53bd1..059f670 100644 --- a/src/guff/api/test.cr +++ b/src/guff/api/test.cr @@ -79,7 +79,12 @@ module Guff::API::TestAPI context : HTTP::Server::Context, args : Hash(String, String) ) - user_id = @models.user.add_user(args["name"]) + user_id = @models.user.add_user(args["name"].not_nil!, + active: args["active"]? ? args["active"] == "t" : nil, + role: args["role"]?, + email: args["name"]?, + password: args["password"]?, + ) { "ok": true, "user_id": user_id } end @@ -87,7 +92,7 @@ module Guff::API::TestAPI context : HTTP::Server::Context, args : Hash(String, String) ) - @models.user.update_user(args["user_id"].to_i, + @models.user.update_user(args["user_id"].to_i64, name: args["name"]? ? args["name"] : nil, active: args["active"]? ? args["active"] == "t" : nil, role: args["role"]? ? args["role"] : nil -- cgit v1.2.3