Skip to content
Snippets Groups Projects
Unverified Commit a2c1714b authored by Ngoc Khuat's avatar Ngoc Khuat Committed by GitHub
Browse files

Fix failed to copy dashboard with parameters (#23719)

* fix failed to copy dashboard with parameters

* add gh issue to the test description
parent 818a0ad0
No related branches found
No related tags found
No related merge requests found
......@@ -333,7 +333,9 @@
We're not using [metabase.mbql.schema/Parameter] here because this Parameter is meant to be used for
Parameters we store on dashboard/card, and it has some difference with Parameter in MBQL."
(with-api-error-message {:id NonBlankString
:type NonBlankString
:type (s/conditional
string? NonBlankString
keyword? s/Keyword)
;; Allow blank name and slug #15279
(s/optional-key :name) s/Str
(s/optional-key :slug) s/Str
......
......@@ -673,18 +673,32 @@
(deftest copy-dashboard-cards-test
(testing "POST /api/dashboard/:id/copy"
(testing "Ensure dashboard cards are copied"
(mt/with-temp* [Dashboard [{dashboard-id :id} {:name "Test Dashboard"}]
(testing "Ensure dashboard cards and parameters are copied (#23685)"
(mt/with-temp* [Dashboard [{dashboard-id :id} {:name "Test Dashboard"
:parameters [{:name "Category ID"
:slug "category_id"
:id "_CATEGORY_ID_"
:type :category}]}]
Card [{card-id :id}]
Card [{card-id2 :id}]
DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id, :card_id card-id}]
DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id, :card_id card-id2}]]
DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id,
:card_id card-id
:parameter_mappings [{:parameter_id "random-id"
:card_id card-id
:target [:dimension [:field (mt/id :venues :name) nil]]}]}]
DashboardCard [{dashcard-id-2 :id} {:dashboard_id dashboard-id, :card_id card-id2}]]
(let [copy-id (u/the-id (mt/user-http-request :rasta :post 200 (format "dashboard/%d/copy" dashboard-id)))]
(try
(is (= 2
(count (db/select-ids DashboardCard, :dashboard_id copy-id))))
(finally
(db/delete! Dashboard :id copy-id))))))))
(is (= [{:name "Category ID" :slug "category_id" :id "_CATEGORY_ID_" :type :category}]
(db/select-one-field :parameters Dashboard :id copy-id)))
(is (= [{:parameter_id "random-id"
:card_id card-id
:target [:dimension [:field (mt/id :venues :name) nil]]}]
(db/select-one-field :parameter_mappings DashboardCard :id dashcard-id)))
(finally
(db/delete! Dashboard :id copy-id))))))))
(deftest copy-dashboard-into-correct-collection-test
(testing "POST /api/dashboard/:id/copy"
......
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