diff --git a/test/metabase/api/embed_test.clj b/test/metabase/api/embed_test.clj index b86c3890034e522c937961319c390c3b5ea43fe2..3a7540a4e52591de1de8da138d6c6384c34592d6 100644 --- a/test/metabase/api/embed_test.clj +++ b/test/metabase/api/embed_test.clj @@ -516,20 +516,21 @@ ;; should be able to fetch values for a Field referenced by a public Card (expect - {:values [["20th Century Cafe"] - ["25°"] - ["33 Taps"] - ["800 Degrees Neapolitan Pizzeria"] - ["BCD Tofu House"]]} - (with-embedding-enabled-and-temp-card-referencing :venues :name [card] - (-> (http/client :get 200 (field-values-url card (data/id :venues :name))) - (update :values (partial take 5))))) + {:values [["20th Century Cafe"] + ["25°"] + ["33 Taps"] + ["800 Degrees Neapolitan Pizzeria"] + ["BCD Tofu House"]] + :field_id (data/id :venues :name)} + (with-embedding-enabled-and-temp-card-referencing :venues :name [card] + (-> (http/client :get 200 (field-values-url card (data/id :venues :name))) + (update :values (partial take 5))))) ;; but for Fields that are not referenced we should get an Exception (expect - "Not found." - (with-embedding-enabled-and-temp-card-referencing :venues :name [card] - (http/client :get 400 (field-values-url card (data/id :venues :price))))) + "Not found." + (with-embedding-enabled-and-temp-card-referencing :venues :name [card] + (http/client :get 400 (field-values-url card (data/id :venues :price))))) ;; Endpoint should fail if embedding is disabled (expect @@ -569,11 +570,12 @@ ;; should be able to use it when everything is g2g (expect - {:values [["20th Century Cafe"] - ["25°"] - ["33 Taps"] - ["800 Degrees Neapolitan Pizzeria"] - ["BCD Tofu House"]]} + {:values [["20th Century Cafe"] + ["25°"] + ["33 Taps"] + ["800 Degrees Neapolitan Pizzeria"] + ["BCD Tofu House"]] + :field_id (data/id :venues :name)} (with-embedding-enabled-and-temp-dashcard-referencing :venues :name [dashboard] (-> (http/client :get 200 (field-values-url dashboard (data/id :venues :name))) (update :values (partial take 5))))) diff --git a/test/metabase/api/field_test.clj b/test/metabase/api/field_test.clj index 6e2d5f1662ac3f65be70a6300788681e9831abfe..f25b40c3d814aab33eb516b3518b4a1f6f9d7534 100644 --- a/test/metabase/api/field_test.clj +++ b/test/metabase/api/field_test.clj @@ -6,7 +6,7 @@ [field-values :refer [FieldValues]] [table :refer [Table]]] [metabase.test - [data :refer :all] + [data :as data] [util :as tu]] [metabase.test.data.users :refer :all] [ring.util.codec :as codec] @@ -18,7 +18,7 @@ ;; Helper Fns (defn- db-details [] - (tu/match-$ (db) + (tu/match-$ (data/db) {:created_at $ :engine "h2" :caveats nil @@ -38,13 +38,13 @@ ;; ## GET /api/field/:id (expect - (tu/match-$ (Field (id :users :name)) + (tu/match-$ (Field (data/id :users :name)) {:description nil - :table_id (id :users) + :table_id (data/id :users) :raw_column_id $ :fingerprint $ :fingerprint_version $ - :table (tu/match-$ (Table (id :users)) + :table (tu/match-$ (Table (data/id :users)) {:description nil :entity_type nil :visibility_type nil @@ -56,8 +56,8 @@ :updated_at $ :entity_name nil :active true - :id (id :users) - :db_id (id) + :id (data/id :users) + :db_id (data/id) :caveats nil :points_of_interest nil :show_in_getting_started false @@ -71,7 +71,7 @@ :updated_at $ :last_analyzed $ :active true - :id (id :users :name) + :id (data/id :users :name) :visibility_type "normal" :position 0 :preview_display true @@ -83,13 +83,13 @@ :parent_id nil :dimensions [] :name_field nil}) - ((user->client :rasta) :get 200 (format "field/%d" (id :users :name)))) + ((user->client :rasta) :get 200 (format "field/%d" (data/id :users :name)))) ;; ## GET /api/field/:id/summary (expect [["count" 75] ; why doesn't this come back as a dictionary ? ["distincts" 75]] - ((user->client :rasta) :get 200 (format "field/%d/summary" (id :categories :name)))) + ((user->client :rasta) :get 200 (format "field/%d/summary" (data/id :categories :name)))) ;; ## PUT /api/field/:id @@ -157,7 +157,7 @@ (defn- field->field-values "Fetch the `FieldValues` object that corresponds to a given `Field`." [table-kw field-kw] - (FieldValues :field_id (id table-kw field-kw))) + (FieldValues :field_id (data/id table-kw field-kw))) (defn- field-values-id [table-key field-key] (:id (field->field-values table-key field-key))) @@ -165,23 +165,23 @@ ;; ## GET /api/field/:id/values ;; Should return something useful for a field that has special_type :type/Category (expect - {:values [[1] [2] [3] [4]]} + {:values [[1] [2] [3] [4]], :field_id (data/id :venues :price)} (do ;; clear out existing human_readable_values in case they're set (db/update! FieldValues (field-values-id :venues :price) :human_readable_values nil) ;; now update the values via the API - (tu/boolean-ids-and-timestamps ((user->client :rasta) :get 200 (format "field/%d/values" (id :venues :price)))))) + ((user->client :rasta) :get 200 (format "field/%d/values" (data/id :venues :price))))) ;; Should return nothing for a field whose special_type is *not* :type/Category (expect - {:values []} - ((user->client :rasta) :get 200 (format "field/%d/values" (id :venues :id)))) + {:values [], :field_id (data/id :venues :id)} + ((user->client :rasta) :get 200 (format "field/%d/values" (data/id :venues :id)))) ;; Sensisitive fields do not have field values and should return empty (expect - {:values []} - ((user->client :rasta) :get 200 (format "field/%d/values" (id :users :password)))) + {:values [], :field_id (data/id :users :password)} + ((user->client :rasta) :get 200 (format "field/%d/values" (data/id :users :password)))) (def ^:private category-field {:name "Field Test" :base_type :type/Integer :special_type :type/Category}) @@ -189,9 +189,9 @@ ;; Human readable values are optional (expect - [{:values [[5] [6] [7] [8] [9]]} + [{:values [[5] [6] [7] [8] [9]], :field_id true} {:status "success"} - {:values [[1] [2] [3] [4]]}] + {:values [[1] [2] [3] [4]], :field_id true}] (tt/with-temp* [Field [{field-id :id} category-field] FieldValues [{field-value-id :id} {:values (range 5 10), :field_id field-id}]] (mapv tu/boolean-ids-and-timestamps @@ -202,9 +202,9 @@ ;; Existing field values can be updated (with their human readable values) (expect - [{:values [[1] [2] [3] [4]]} + [{:values [[1] [2] [3] [4]], :field_id true} {:status "success"} - {:values [[1 "$"] [2 "$$"] [3 "$$$"] [4 "$$$$"]]}] + {:values [[1 "$"] [2 "$$"] [3 "$$$"] [4 "$$$$"]], :field_id true}] (tt/with-temp* [Field [{field-id :id} category-field] FieldValues [{field-value-id :id} {:values (range 1 5), :field_id field-id}]] (mapv tu/boolean-ids-and-timestamps @@ -215,9 +215,9 @@ ;; Field values are created when not present (expect - [{:values []} + [{:values [], :field_id true} {:status "success"} - {:values [[1 "$"] [2 "$$"] [3 "$$$"] [4 "$$$$"]]}] + {:values [[1 "$"] [2 "$$"] [3 "$$$"] [4 "$$$$"]], :field_id true}] (tt/with-temp* [Field [{field-id :id} category-field]] (mapv tu/boolean-ids-and-timestamps [((user->client :crowberto) :get 200 (format "field/%d/values" field-id)) @@ -227,22 +227,22 @@ ;; Can unset values (expect - [{:values [[1] [2] [3] [4]]} + [{:values [[1] [2] [3] [4]], :field_id true} {:status "success"} - {:values []}] + {:values [], :field_id true}] (tt/with-temp* [Field [{field-id :id} category-field] FieldValues [{field-value-id :id} {:values (range 1 5), :field_id field-id}]] (mapv tu/boolean-ids-and-timestamps [((user->client :crowberto) :get 200 (format "field/%d/values" field-id)) ((user->client :crowberto) :post 200 (format "field/%d/values" field-id) - {:values []}) + {:values [], :field_id true}) ((user->client :crowberto) :get 200 (format "field/%d/values" field-id))]))) ;; Can unset just human readable values (expect - [{:values [[1 "$"] [2 "$$"] [3 "$$$"] [4 "$$$$"]]} + [{:values [[1 "$"] [2 "$$"] [3 "$$$"] [4 "$$$$"]], :field_id true} {:status "success"} - {:values [[1] [2] [3] [4]]}] + {:values [[1] [2] [3] [4]], :field_id true}] (tt/with-temp* [Field [{field-id :id} category-field] FieldValues [{field-value-id :id} {:values (range 1 5), :field_id field-id :human_readable_values ["$" "$$" "$$$" "$$$$"]}]] @@ -258,8 +258,8 @@ (tt/with-temp* [Field [{field-id :id} {:name "Field Test" :base_type :type/Integer :special_type :type/Category}]] ((user->client :crowberto) :post 400 (format "field/%d/values" field-id) {:values [[1 "$"] [2 "$$"] [3] [4]]}))) - -;; ## PUT /api/field/:id/dimension +, :field_id true +;; ## PUT /api/field/:id/dimensio, :field_id truen (defn- dimension-for-field [field-id] (-> (Field :id field-id) @@ -306,13 +306,13 @@ ;; test that we can do basic field update work, including unsetting some fields such as special-type (expect [[] - {:id true - :created_at true - :updated_at true - :type :external - :name "some dimension name" + {:id true + :created_at true + :updated_at true + :type :external + :name "some dimension name" :human_readable_field_id true - :field_id true}] + :field_id true}] (tt/with-temp* [Field [{field-id-1 :id} {:name "Field Test 1"}] Field [{field-id-2 :id} {:name "Field Test 2"}]] (let [before-creation (dimension-for-field field-id-1) @@ -326,8 +326,8 @@ clojure.lang.ExceptionInfo (tt/with-temp* [Field [{field-id-1 :id} {:name "Field Test 1"}]] (create-dimension-via-API! field-id-1 {:name "some dimension name", :type "external"}))) - -;; Non-admin users can't update dimensions +, :field_id true +;; Non-admin users can't update dimension, :field_id trues (expect "You don't have permissions to do that." (tt/with-temp* [Field [{field-id :id} {:name "Field Test 1"}]] diff --git a/test/metabase/api/public_test.clj b/test/metabase/api/public_test.clj index 11b40a2db18c6a2f21840ece065f59b76129ae4f..9db314ba78d3ae304c049e64e07e883a854fb830 100644 --- a/test/metabase/api/public_test.clj +++ b/test/metabase/api/public_test.clj @@ -504,22 +504,24 @@ ;; We should be able to get values for a Field referenced by a Card (expect - {:values [["20th Century Cafe"] - ["25°"] - ["33 Taps"] - ["800 Degrees Neapolitan Pizzeria"] - ["BCD Tofu House"]]} + {:values [["20th Century Cafe"] + ["25°"] + ["33 Taps"] + ["800 Degrees Neapolitan Pizzeria"] + ["BCD Tofu House"]] + :field_id (data/id :venues :name)} (tt/with-temp Card [card (mbql-card-referencing :venues :name)] (-> (public-api/card-and-field-id->values (u/get-id card) (data/id :venues :name)) (update :values (partial take 5))))) ;; SQL param field references should work just as well as MBQL field referenced (expect - {:values [["20th Century Cafe"] - ["25°"] - ["33 Taps"] - ["800 Degrees Neapolitan Pizzeria"] - ["BCD Tofu House"]]} + {:values [["20th Century Cafe"] + ["25°"] + ["33 Taps"] + ["800 Degrees Neapolitan Pizzeria"] + ["BCD Tofu House"]] + :field_id (data/id :venues :name)} (tt/with-temp Card [card (sql-card-referencing-venue-name)] (-> (public-api/card-and-field-id->values (u/get-id card) (data/id :venues :name)) (update :values (partial take 5))))) @@ -557,14 +559,15 @@ ;; should be able to fetch values for a Field referenced by a public Card (expect - {:values [["20th Century Cafe"] - ["25°"] - ["33 Taps"] - ["800 Degrees Neapolitan Pizzeria"] - ["BCD Tofu House"]]} - (with-sharing-enabled-and-temp-card-referencing :venues :name [card] - (-> (http/client :get 200 (field-values-url card (data/id :venues :name))) - (update :values (partial take 5))))) + {:values [["20th Century Cafe"] + ["25°"] + ["33 Taps"] + ["800 Degrees Neapolitan Pizzeria"] + ["BCD Tofu House"]] + :field_id (data/id :venues :name)} + (with-sharing-enabled-and-temp-card-referencing :venues :name [card] + (-> (http/client :get 200 (field-values-url card (data/id :venues :name))) + (update :values (partial take 5))))) ;; but for Fields that are not referenced we should get an Exception (expect @@ -603,11 +606,12 @@ ;; should be able to use it when everything is g2g (expect - {:values [["20th Century Cafe"] - ["25°"] - ["33 Taps"] - ["800 Degrees Neapolitan Pizzeria"] - ["BCD Tofu House"]]} + {:values [["20th Century Cafe"] + ["25°"] + ["33 Taps"] + ["800 Degrees Neapolitan Pizzeria"] + ["BCD Tofu House"]] + :field_id (data/id :venues :name)} (with-sharing-enabled-and-temp-dashcard-referencing :venues :name [dashboard] (-> (http/client :get 200 (field-values-url dashboard (data/id :venues :name))) (update :values (partial take 5)))))