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

View File

@ -12,26 +12,27 @@
(mount/start (mount/start
#'commiteth.config/env #'commiteth.config/env
#'commiteth.db.core/*db*) #'commiteth.db.core/*db*)
(migrations/migrate ["migrate"] (select-keys env [:jdbc-database-url])) (migrations/migrate ["migrate"]
{:database-url (env :jdbc-database-url)})
(f))) (f)))
(deftest test-users (deftest test-users
(jdbc/with-db-transaction [t-conn *db*] (jdbc/with-db-transaction [t-conn *db*]
(jdbc/db-set-rollback-only! t-conn) (jdbc/db-set-rollback-only! t-conn)
(is (= 1 (db/create-user! (is (not (nil? (db/create-user!
t-conn t-conn
{:id "1" {:id 1
:login "torvalds" :login "torvalds"
:name "Linus Torvalds" :name "Linus Torvalds"
:email nil :email nil
:token "not null" :token "not null"
:address "address" :address "address"
:created nil}))) :created nil}))))
(is (= {:id "1" (is (= {:id 1
:login "torvalds" :login "torvalds"
:name "Linus Torvalds" :name "Linus Torvalds"
:email nil :email nil
:token "not null" :token "not null"
:address "address" :address "address"
:created nil} :created nil}
(db/get-user t-conn {:login "torvalds"}))))) (db/get-user t-conn {:id 1})))))