Skip to content
Snippets Groups Projects
Commit d0b23b17 authored by Ryan Senior's avatar Ryan Senior
Browse files

Add num-bins test

parent 87ab90ab
Branches
Tags
No related merge requests found
......@@ -6,8 +6,8 @@
[driver :as driver]
[http-client :as http]
[middleware :as middleware]
[util :as u]
[sync-database :as sync-database]]
[sync-database :as sync-database]
[util :as u]]
[metabase.models
[database :refer [Database]]
[field :refer [Field]]
......@@ -23,7 +23,8 @@
[toucan
[db :as db]
[hydrate :as hydrate]]
[toucan.util.test :as tt]))
[toucan.util.test :as tt]
[medley.core :as m]))
(resolve-private-vars metabase.models.table pk-field-id)
(resolve-private-vars metabase.api.table dimension-options-for-response datetime-dimension-indexes numeric-dimension-indexes)
......@@ -509,14 +510,33 @@
(finally
(db/update! Field (id :venues :latitude) :min_value min_value :max_value max_value)))))
(defn- extract-dimension-options
"For the given `FIELD-NAME` find it's dimension_options following
the indexes given in the field"
[response field-name]
(set
(for [dim-index (->> response
:fields
(m/find-first #(= field-name (:name %)))
:dimension_options)
:let [{[_ _ strategy _] :mbql} (get-in response [:dimension_options (keyword dim-index)])]]
strategy)))
;; Lat/Long fields should use bin-width rather than num-bins
(expect
#{"bin-width" "default"}
(let [response ((user->client :rasta) :get 200 (format "table/%d/query_metadata" (id :venues)))
lat-dim-options (-> response
:fields
(nth 2)
:dimension_options)]
(set (for [dim-index lat-dim-options
:let [{[_ _ strategy _] :mbql} (get-in response [:dimension_options (keyword dim-index)])]]
strategy))))
(let [response ((user->client :rasta) :get 200 (format "table/%d/query_metadata" (id :venues)))]
(extract-dimension-options response "LATITUDE")))
;; Number columns without a special type should use "num-bins"
(expect
#{"num-bins" "default"}
(let [{:keys [special_type]} (Field (id :venues :price))]
(try
(db/update! Field (id :venues :price) :special_type nil)
(let [response ((user->client :rasta) :get 200 (format "table/%d/query_metadata" (id :venues)))]
(extract-dimension-options response "PRICE"))
(finally
(db/update! Field (id :venues :price) :special_type special_type)))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment