Skip to content
Snippets Groups Projects
Commit 636a2c95 authored by Cam Saül's avatar Cam Saül
Browse files

Fix unarchiving a card :cry:

parent 2505d94a
No related branches found
No related tags found
No related merge requests found
......@@ -173,7 +173,7 @@
(defendpoint PUT "/:id"
"Update a `Card`."
[id :as {{:keys [dataset_query description display name public_perms visualization_settings archived]} :body}]
[id :as {{:keys [dataset_query description display name public_perms visualization_settings archived], :as body} :body}]
{name NonEmptyString
public_perms PublicPerms
display NonEmptyString
......
......@@ -91,8 +91,8 @@
(when-not tst
(throw (invalid-param-exception (str field-name) message)))))
(defmacro checkp-with
"Check (TEST-FN VALUE), or throw an exception with STATUS-CODE (default is 400).
(defn checkp-with
"Check (F VALUE), or throw an exception with STATUS-CODE (default is 400).
SYMB is passed in order to give the user a relevant error message about which parameter was bad.
Returns VALUE upon success.
......@@ -100,20 +100,18 @@
(checkp-with (partial? contains? {:all :mine}) f :all)
-> :all
(checkp-with (partial? contains {:all :mine}) f :bad)
-> ExceptionInfo: Invalid value ':bad' for 'f': test failed: (partial? contains? {:all :mine}
-> ExceptionInfo: Invalid value ':bad' for 'f': test failed: (partial? contains?) {:all :mine}
You may optionally pass a MESSAGE to append to the exception upon failure;
this will be used in place of the \"test failed: ...\" message.
MESSAGE may be either a string or a pair like `[status-code message]`."
([test-fn symb value message]
([f symb value]
(checkp-with f symb value (str "test failed: " f)))
([f symb value message]
{:pre [(symbol? symb)]}
`(let [message# ~message
value# ~value]
(checkp (~test-fn value#) ~symb (format "Invalid value '%s' for '%s': %s" (str value#) ~symb message#))
value#))
([test-fn symb value]
`(checkp-with ~test-fn ~symb ~value ~(str "test failed: " test-fn))))
(checkp (f value) symb (format "Invalid value '%s' for '%s': %s" (str value) symb message))
value))
(defn checkp-contains?
"Check that the VALUE of parameter SYMB is in VALID-VALUES, or throw a 400.
......@@ -279,7 +277,7 @@
(defn ~fn-name ~@(when docstr [docstr]) [~symbol-binding ~value-binding]
{:pre [(symbol? ~symbol-binding)]}
~(if nillable?
`(when ~value-binding
`(when-not (nil? ~value-binding)
~@body)
`(do
~@body)))
......
......@@ -192,14 +192,21 @@
(sel :one :field [Card :name] :id card-id))]))
;; TODO - can we update a card's `archived` status?
(defmacro ^:private with-temp-card {:style/indent 1} [binding & body]
`(with-temp Card ~binding
~@body))
;; Can we update a Card's archived status?
(defn- x []
(with-temp-card [{:keys [id]}]
(let [archived? (fn [] (:archived (Card id)))
set-archived! (fn [archived]
((user->client :rasta) :put 200 (str "card/" id) {:archived archived})
(archived?))]
[(archived?)
(set-archived! true)
(set-archived! false)])))
;; ## DELETE /api/card/:id
;; Check that we can delete a card
......@@ -258,7 +265,6 @@
;;; POST /api/card/:id/labels
;; Check that we can update card labels
(expect-with-temp [Card [{card-id :id}]
Label [{label-1-id :id} {:name "Toucan-Friendly"}]
Label [{label-2-id :id} {:name "Toucan-Unfriendly"}]]
......
......@@ -118,3 +118,11 @@
(defendpoint GET "/:id" [id]
{id Required}
(->404 (sel :one Card :id id)))))
;;; ------------------------------------------------------------ ANNOTATION TESTS ------------------------------------------------------------
(expect true (annotation:Boolean 'archived true))
(expect false (annotation:Boolean 'archived false))
(expect nil (annotation:Boolean 'archived nil))
(expect clojure.lang.ExceptionInfo (annotation:Boolean 'archived 1))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment