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:
Teemu Patja 2017-01-15 22:26:33 +02:00
parent e68891a936
commit 1b73412a7b
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
2 changed files with 26 additions and 24 deletions

View File

@ -1,10 +1,10 @@
-- 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
SELECT
:id,
:login,
:name,
@ -12,9 +12,10 @@ INSERT INTO users
:token,
:address,
:created
WHERE NOT exists(SELECT 1
WHERE NOT exists(SELECT 1
FROM users
WHERE id = :id);
WHERE id = :id)
RETURNING id, login, name, email, token, address, created;
-- :name update-user! :! :n
-- :doc updates an existing user record

View File

@ -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!
(is (not (nil? (db/create-user!
t-conn
{:id "1"
{:id 1
:login "torvalds"
:name "Linus Torvalds"
:email nil
:token "not null"
:address "address"
:created nil})))
(is (= {:id "1"
: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})))))