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 60cc76919e
commit afce955ff3
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,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

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!
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})))))