Fix first-time sign in issue
* db/create-user! now returns a map with the created data instead of a number, as expected by the client side. * fixed broken test Fixes: #4
This commit is contained in:
parent
e68891a936
commit
1b73412a7b
|
@ -1,20 +1,21 @@
|
|||
-- Users ---------------------------------------------------------------------------
|
||||
|
||||
-- :name create-user! :! :n
|
||||
-- :name create-user! :<! :1
|
||||
-- :doc creates a new user record
|
||||
INSERT INTO users
|
||||
(id, login, name, email, token, address, created)
|
||||
SELECT
|
||||
:id,
|
||||
:login,
|
||||
:name,
|
||||
:email,
|
||||
:token,
|
||||
:address,
|
||||
:created
|
||||
WHERE NOT exists(SELECT 1
|
||||
FROM users
|
||||
WHERE id = :id);
|
||||
SELECT
|
||||
:id,
|
||||
:login,
|
||||
:name,
|
||||
:email,
|
||||
:token,
|
||||
:address,
|
||||
:created
|
||||
WHERE NOT exists(SELECT 1
|
||||
FROM users
|
||||
WHERE id = :id)
|
||||
RETURNING id, login, name, email, token, address, created;
|
||||
|
||||
-- :name update-user! :! :n
|
||||
-- :doc updates an existing user record
|
||||
|
|
|
@ -12,26 +12,27 @@
|
|||
(mount/start
|
||||
#'commiteth.config/env
|
||||
#'commiteth.db.core/*db*)
|
||||
(migrations/migrate ["migrate"] (select-keys env [:jdbc-database-url]))
|
||||
(migrations/migrate ["migrate"]
|
||||
{:database-url (env :jdbc-database-url)})
|
||||
(f)))
|
||||
|
||||
(deftest test-users
|
||||
(jdbc/with-db-transaction [t-conn *db*]
|
||||
(jdbc/db-set-rollback-only! t-conn)
|
||||
(is (= 1 (db/create-user!
|
||||
t-conn
|
||||
{:id "1"
|
||||
:login "torvalds"
|
||||
:name "Linus Torvalds"
|
||||
:email nil
|
||||
:token "not null"
|
||||
:address "address"
|
||||
:created nil})))
|
||||
(is (= {:id "1"
|
||||
(is (not (nil? (db/create-user!
|
||||
t-conn
|
||||
{:id 1
|
||||
:login "torvalds"
|
||||
:name "Linus Torvalds"
|
||||
:email nil
|
||||
:token "not null"
|
||||
:address "address"
|
||||
:created nil}))))
|
||||
(is (= {:id 1
|
||||
:login "torvalds"
|
||||
:name "Linus Torvalds"
|
||||
:email nil
|
||||
:token "not null"
|
||||
:address "address"
|
||||
:created nil}
|
||||
(db/get-user t-conn {:login "torvalds"})))))
|
||||
(db/get-user t-conn {:id 1})))))
|
||||
|
|
Loading…
Reference in New Issue