Skip to content
Snippets Groups Projects
Unverified Commit 8441ffc2 authored by Chris Truter's avatar Chris Truter Committed by GitHub
Browse files

Don't return nil schema, and test more table fields (#41169)

* Test created_at and schema fields
* Coerce nil schema to empty string
parent 9f5e92e4
No related branches found
No related tags found
No related merge requests found
......@@ -57,6 +57,7 @@
"Get all `Tables` visible to the current user which were created by uploading a file."
[]
(as-> (t2/select Table, :active true, :is_upload true, {:order-by [[:name :asc]]}) tables
(map #(update % :schema str) tables)
(filterv mi/can-read? tables)))
(api/defendpoint GET "/:id"
......
......@@ -2,6 +2,7 @@
"Tests for /api/table endpoints."
(:require
[clojure.test :refer :all]
[java-time.api :as t]
[medley.core :as m]
[metabase.api.table :as api.table]
[metabase.driver :as driver]
......@@ -148,23 +149,27 @@
(deftest list-uploaded-tables-test
(testing "GET /api/table/uploaded"
(testing "These should come back in alphabetical order and include relevant metadata"
(with-tables-as-uploads [:categories :reviews :venues]
(is (= #{{:name (mt/format-name "categories")
:display_name "Categories"
:id (mt/id :categories)
:entity_type "entity/GenericTable"}
{:name (mt/format-name "reviews")
:display_name "Reviews"
:id (mt/id :reviews)
:entity_type "entity/GenericTable"}
{:name (mt/format-name "venues")
:display_name "Venues"
:id (mt/id :venues)
:entity_type "entity/GenericTable"}}
(->> (mt/user-http-request :rasta :get 200 "table/uploaded")
(filter #(= (:db_id %) (mt/id))) ; prevent stray tables from affecting unit test results
(map #(select-keys % [:name :display_name :id :entity_type]))
set)))))))
(with-tables-as-uploads [:categories :reviews]
(t2.with-temp/with-temp [Card {} {:table_id (mt/id :categories)}
Card {} {:table_id (mt/id :reviews)}
Card {} {:table_id (mt/id :reviews)}]
(let [result (mt/user-http-request :rasta :get 200 "table/uploaded")]
;; =? doesn't seem to allow predicates inside maps, inside a set
(is (every? t/offset-date-time? (map :created_at result)))
(is (= #{{:name (mt/format-name "categories")
:display_name "Categories"
:id (mt/id :categories)
:schema "PUBLIC"
:entity_type "entity/GenericTable"}
{:name (mt/format-name "reviews")
:display_name "Reviews"
:id (mt/id :reviews)
:schema "PUBLIC"
:entity_type "entity/GenericTable"}}
(->> result
(filter #(= (:db_id %) (mt/id))) ; prevent stray tables from affecting unit test results
(map #(select-keys % [:name :display_name :id :entity_type :schema :usage_count]))
set)))))))))
(deftest get-table-test
(testing "GET /api/table/:id"
......
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