diff --git a/test/metabase/api/field_test.clj b/test/metabase/api/field_test.clj index d297dc77f0a50df073bc3e71690f83ed311532fc..f2a7a5a7ed38e1b159faff34d319a376f678f5aa 100644 --- a/test/metabase/api/field_test.clj +++ b/test/metabase/api/field_test.clj @@ -95,6 +95,41 @@ :fk_target_field_id nil}) ((user->client :crowberto) :put 200 (format "field/%d" (id :venues :latitude)) {:special_type :fk})) + +;; when we set the special-type from :fk to something else, make sure fk_target_field_id is set to nil +(expect + [true + nil] + (tu/with-temp Database [{database-id :id} {:name "Field Test" + :engine :yeehaw + :details {} + :is_sample false}] + (tu/with-temp Table [{table-id :id} {:name "Field Test" + :db_id database-id + :active true}] + (tu/with-temp Field [{field-id1 :id} {:table_id table-id + :name "Target Field" + :base_type :TextField + :field_type :info + :special_type :id + :active true + :preview_display true + :position 1}] + (tu/with-temp Field [{field-id :id} {:table_id table-id + :name "Field Test" + :base_type :TextField + :field_type :info + :special_type :fk + :fk_target_field_id field-id1 + :active true + :preview_display true + :position 1}] + (let [original-val (boolean (db/sel :one :field [Field :fk_target_field_id] :id field-id))] + ;; unset the :fk special-type + ((user->client :crowberto) :put 200 (format "field/%d" field-id) {:special_type :name}) + [original-val + (db/sel :one :field [Field :fk_target_field_id] :id field-id)])))))) + (expect ["Invalid Request." nil]