The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
fix actions tests (#62347)
John Swanson134a0c464dc7
diff --git a/test/metabase/driver/mysql_test.clj b/test/metabase/driver/mysql_test.cljindex f72bc239221..1d5d330ba5f 100644--- a/test/metabase/driver/mysql_test.clj+++ b/test/metabase/driver/mysql_test.clj@@ -592,58 +592,58 @@;; API tests are in [[metabase.actions.api-test]](deftest ^:parallel actions-maybe-parse-sql-error-test(testing "violate not null constraint"- (is (= {:type :metabase.actions.error/violate-not-null-constraint- :message "F1 must have values."- :errors {"f1" "You must provide a value."}}- (sql-jdbc.actions/maybe-parse-sql-error- :mysql actions.error/violate-not-null-constraint nil nil- "Column 'f1' cannot be null")))))+ (is (=? {:type :metabase.actions.error/violate-not-null-constraint+ :message "F1 must have values."+ :errors {"f1" "You must provide a value."}}+ (sql-jdbc.actions/maybe-parse-sql-error+ :mysql actions.error/violate-not-null-constraint nil nil+ "Column 'f1' cannot be null")))))(deftest actions-maybe-parse-sql-error-test-2(testing "violate unique constraint"(with-redefs [mysql.actions/constraint->column-names (constantly ["PRIMARY"])]- (is (= {:type :metabase.actions.error/violate-unique-constraint,- :message "Primary already exists.",- :errors {"PRIMARY" "This Primary value already exists."}}- (sql-jdbc.actions/maybe-parse-sql-error- :mysql actions.error/violate-unique-constraint nil nil- "(conn=10) Duplicate entry 'ID' for key 'string_pk.PRIMARY'"))))))+ (is (=? {:type :metabase.actions.error/violate-unique-constraint,+ :message "Primary already exists.",+ :errors {"PRIMARY" "This Primary value already exists."}}+ (sql-jdbc.actions/maybe-parse-sql-error+ :mysql actions.error/violate-unique-constraint nil nil+ "(conn=10) Duplicate entry 'ID' for key 'string_pk.PRIMARY'"))))))(deftest ^:parallel actions-maybe-parse-sql-error-test-3(testing "incorrect type"- (is (= {:type :metabase.actions.error/incorrect-value-type,- :message "Some of your values aren’t of the correct type for the database."- :errors {"id" "This value should be of type Integer."}}- (sql-jdbc.actions/maybe-parse-sql-error- :mysql actions.error/incorrect-value-type nil nil- "(conn=183) Incorrect integer value: 'STRING' for column `table`.`id` at row 1")))))+ (is (=? {:type :metabase.actions.error/incorrect-value-type,+ :message "Some of your values aren’t of the correct type for the database."+ :errors {"id" "This value should be of type Integer."}}+ (sql-jdbc.actions/maybe-parse-sql-error+ :mysql actions.error/incorrect-value-type nil nil+ "(conn=183) Incorrect integer value: 'STRING' for column `table`.`id` at row 1")))))(deftest ^:parallel actions-maybe-parse-sql-error-test-4(testing "violate fk constraints"- (is (= {:type :metabase.actions.error/violate-foreign-key-constraint- :message "Unable to create a new record."- :errors {"group-id" "This Group-id does not exist."}}- (sql-jdbc.actions/maybe-parse-sql-error- :mysql actions.error/violate-foreign-key-constraint nil :model.row/create- "(conn=45) Cannot add or update a child row: a foreign key constraint fails (`action-error-handling`.`user`, CONSTRAINT `user_group-id_group_-159406530` FOREIGN KEY (`group-id`) REFERENCES `group` (`id`))")))))+ (is (=? {:type :metabase.actions.error/violate-foreign-key-constraint+ :message "Unable to create a new record."+ :errors {"group-id" "This Group-id does not exist."}}+ (sql-jdbc.actions/maybe-parse-sql-error+ :mysql actions.error/violate-foreign-key-constraint nil :model.row/create+ "(conn=45) Cannot add or update a child row: a foreign key constraint fails (`action-error-handling`.`user`, CONSTRAINT `user_group-id_group_-159406530` FOREIGN KEY (`group-id`) REFERENCES `group` (`id`))")))))(deftest ^:parallel actions-maybe-parse-sql-error-test-5(testing "violate fk constraints"- (is (= {:type :metabase.actions.error/violate-foreign-key-constraint,- :message "Unable to update the record.",- :errors {"group" "This Group does not exist."}}- (sql-jdbc.actions/maybe-parse-sql-error- :mysql actions.error/violate-foreign-key-constraint nil :model.row/update- "(conn=21) Cannot delete or update a parent row: a foreign key constraint fails (`action-error-handling`.`user`, CONSTRAINT `user_group-id_group_-159406530` FOREIGN KEY (`group-id`) REFERENCES `group` (`id`))")))))+ (is (=? {:type :metabase.actions.error/violate-foreign-key-constraint,+ :message "Unable to update the record.",+ :errors {"group" "This Group does not exist."}}+ (sql-jdbc.actions/maybe-parse-sql-error+ :mysql actions.error/violate-foreign-key-constraint nil :model.row/update+ "(conn=21) Cannot delete or update a parent row: a foreign key constraint fails (`action-error-handling`.`user`, CONSTRAINT `user_group-id_group_-159406530` FOREIGN KEY (`group-id`) REFERENCES `group` (`id`))")))))(deftest ^:parallel actions-maybe-parse-sql-error-test-6(testing "violate fk constraints"- (is (= {:type :metabase.actions.error/violate-foreign-key-constraint- :message "Other tables rely on this row so it cannot be deleted."- :errors {}}- (sql-jdbc.actions/maybe-parse-sql-error- :mysql actions.error/violate-foreign-key-constraint nil :model.row/delete- "(conn=21) Cannot delete or update a parent row: a foreign key constraint fails (`action-error-handling`.`user`, CONSTRAINT `user_group-id_group_-159406530` FOREIGN KEY (`group-id`) REFERENCES `group` (`id`))")))))+ (is (=? {:type :metabase.actions.error/violate-foreign-key-constraint+ :message "Other tables rely on this row so it cannot be deleted."+ :errors {}}+ (sql-jdbc.actions/maybe-parse-sql-error+ :mysql actions.error/violate-foreign-key-constraint nil :model.row/delete+ "(conn=21) Cannot delete or update a parent row: a foreign key constraint fails (`action-error-handling`.`user`, CONSTRAINT `user_group-id_group_-159406530` FOREIGN KEY (`group-id`) REFERENCES `group` (`id`))")))))(deftest check-constraint-test(mt/test-driver :mysql@@ -662,16 +662,16 @@(sync/sync-database! database)(mt/with-actions-enabled(testing "when creating with invalid email"- (is (= {:errors {}- :message "Some of your values violate the constraint: email_format_check"- :status-code 400- :type actions.error/violate-check-constraint}- (sql-jdbc.actions-test/perform-action-ex-data- :model.row/create (mt/$ids {:create-row {"email" "invalid-email"- "age" 25}- :database (:id database)- :query {:source-table $$test_users}- :type :query}))))))))))))+ (is (=? {:errors {}+ :message "Some of your values violate the constraint: email_format_check"+ :status-code 400+ :type actions.error/violate-check-constraint}+ (sql-jdbc.actions-test/perform-action-ex-data+ :model.row/create (mt/$ids {:create-row {"email" "invalid-email"+ "age" 25}+ :database (:id database)+ :query {:source-table $$test_users}+ :type :query}))))))))))));; this contains specical test cases for mysql;; for generic tests, check [[metabase.driver.sql-jdbc.actions-test/action-error-handling-test]]diff --git a/test/metabase/driver/postgres_test.clj b/test/metabase/driver/postgres_test.cljindex c82ab330939..e11c57dd8f2 100644--- a/test/metabase/driver/postgres_test.clj+++ b/test/metabase/driver/postgres_test.clj@@ -1057,67 +1057,67 @@;; API tests are in [[metabase.actions.api-test]](deftest ^:parallel actions-maybe-parse-sql-violate-not-null-constraint-test(testing "violate not null constraint"- (is (= {:type :metabase.actions.error/violate-not-null-constraint,- :message "Ranking must have values."- :errors {"ranking" "You must provide a value."}}- (sql-jdbc.actions/maybe-parse-sql-error- :postgres actions.error/violate-not-null-constraint nil :model.row/created- "ERROR: null value in column \"ranking\" violates not-null constraint\n Detail: Failing row contains (3, admin, null).")))))+ (is (=? {:type :metabase.actions.error/violate-not-null-constraint,+ :message "Ranking must have values."+ :errors {"ranking" "You must provide a value."}}+ (sql-jdbc.actions/maybe-parse-sql-error+ :postgres actions.error/violate-not-null-constraint nil :model.row/created+ "ERROR: null value in column \"ranking\" violates not-null constraint\n Detail: Failing row contains (3, admin, null).")))))(deftest ^:parallel actions-maybe-parse-sql-violate-not-null-constraint-test-2(testing "violate not null constraint"- (is (= {:type :metabase.actions.error/violate-not-null-constraint,- :message "Ranking must have values."- :errors {"ranking" "You must provide a value."}}- (sql-jdbc.actions/maybe-parse-sql-error- :postgres actions.error/violate-not-null-constraint nil :model.row/created- "ERROR: null value in column \"ranking\" of relation \"group\" violates not-null constraint\n Detail: Failing row contains (57, admin, null).")))))+ (is (=? {:type :metabase.actions.error/violate-not-null-constraint,+ :message "Ranking must have values."+ :errors {"ranking" "You must provide a value."}}+ (sql-jdbc.actions/maybe-parse-sql-error+ :postgres actions.error/violate-not-null-constraint nil :model.row/created+ "ERROR: null value in column \"ranking\" of relation \"group\" violates not-null constraint\n Detail: Failing row contains (57, admin, null).")))))(deftest actions-maybe-parse-sql-error-violate-unique-constraint-test(testing "violate unique constraint"(with-redefs [postgres.actions/constraint->column-names (constantly ["ranking"])]- (is (= {:type :metabase.actions.error/violate-unique-constraint,- :message "Ranking already exists.",- :errors {"ranking" "This Ranking value already exists."}}- (sql-jdbc.actions/maybe-parse-sql-error- :postgres actions.error/violate-unique-constraint nil nil- "Batch entry 0 UPDATE \"public\".\"group\" SET \"ranking\" = CAST(2 AS INTEGER) WHERE \"public\".\"group\".\"id\" = 1 was aborted: ERROR: duplicate key value violates unique constraint \"group_ranking_key\"\n Detail: Key (ranking)=(2) already exists. Call getNextException to see other errors in the batch."))))))+ (is (=? {:type :metabase.actions.error/violate-unique-constraint,+ :message "Ranking already exists.",+ :errors {"ranking" "This Ranking value already exists."}}+ (sql-jdbc.actions/maybe-parse-sql-error+ :postgres actions.error/violate-unique-constraint nil nil+ "Batch entry 0 UPDATE \"public\".\"group\" SET \"ranking\" = CAST(2 AS INTEGER) WHERE \"public\".\"group\".\"id\" = 1 was aborted: ERROR: duplicate key value violates unique constraint \"group_ranking_key\"\n Detail: Key (ranking)=(2) already exists. Call getNextException to see other errors in the batch."))))))(deftest ^:parallel actions-maybe-parse-sql-error-incorrect-type-test(testing "incorrect type"- (is (= {:type :metabase.actions.error/incorrect-value-type,- :message "Some of your values aren’t of the correct type for the database.",- :errors {}}- (sql-jdbc.actions/maybe-parse-sql-error- :postgres actions.error/incorrect-value-type nil nil- "Batch entry 0 UPDATE \"public\".\"group\" SET \"ranking\" = CAST('S' AS INTEGER) WHERE \"public\".\"group\".\"id\" = 1 was aborted: ERROR: invalid input syntax for type integer: \"S\" Call getNextException to see other errors in the batch.")))))+ (is (=? {:type :metabase.actions.error/incorrect-value-type,+ :message "Some of your values aren’t of the correct type for the database.",+ :errors {}}+ (sql-jdbc.actions/maybe-parse-sql-error+ :postgres actions.error/incorrect-value-type nil nil+ "Batch entry 0 UPDATE \"public\".\"group\" SET \"ranking\" = CAST('S' AS INTEGER) WHERE \"public\".\"group\".\"id\" = 1 was aborted: ERROR: invalid input syntax for type integer: \"S\" Call getNextException to see other errors in the batch.")))))(deftest ^:parallel actions-maybe-parse-sql-error-violate-fk-constraints-test(testing "violate fk constraints"- (is (= {:type :metabase.actions.error/violate-foreign-key-constraint,- :message "Unable to create a new record.",- :errors {"group-id" "This Group-id does not exist."}}- (sql-jdbc.actions/maybe-parse-sql-error- :postgres actions.error/violate-foreign-key-constraint nil :model.row/create- "ERROR: insert or update on table \"user\" violates foreign key constraint \"user_group-id_group_-159406530\"\n Detail: Key (group-id)=(999) is not present in table \"group\".")))))+ (is (=? {:type :metabase.actions.error/violate-foreign-key-constraint,+ :message "Unable to create a new record.",+ :errors {"group-id" "This Group-id does not exist."}}+ (sql-jdbc.actions/maybe-parse-sql-error+ :postgres actions.error/violate-foreign-key-constraint nil :model.row/create+ "ERROR: insert or update on table \"user\" violates foreign key constraint \"user_group-id_group_-159406530\"\n Detail: Key (group-id)=(999) is not present in table \"group\".")))))(deftest ^:parallel actions-maybe-parse-sql-error-violate-fk-constraints-test-2(testing "violate fk constraints"- (is (= {:type :metabase.actions.error/violate-foreign-key-constraint,- :message "Unable to update the record.",- :errors {"id" "This Id does not exist."}}- (sql-jdbc.actions/maybe-parse-sql-error- :postgres actions.error/violate-foreign-key-constraint nil :model.row/update- "ERROR: update or delete on table \"group\" violates foreign key constraint \"user_group-id_group_-159406530\" on table \"user\"\n Detail: Key (id)=(1) is still referenced from table \"user\".")))))+ (is (=? {:type :metabase.actions.error/violate-foreign-key-constraint,+ :message "Unable to update the record.",+ :errors {"id" "This Id does not exist."}}+ (sql-jdbc.actions/maybe-parse-sql-error+ :postgres actions.error/violate-foreign-key-constraint nil :model.row/update+ "ERROR: update or delete on table \"group\" violates foreign key constraint \"user_group-id_group_-159406530\" on table \"user\"\n Detail: Key (id)=(1) is still referenced from table \"user\".")))))(deftest ^:parallel actions-maybe-parse-sql-error-violate-fk-constraints-test-3(testing "violate fk constraints"- (is (= {:type :metabase.actions.error/violate-foreign-key-constraint,- :message "Other tables rely on this row so it cannot be deleted.",- :errors {}}- (sql-jdbc.actions/maybe-parse-sql-error- :postgres actions.error/violate-foreign-key-constraint nil :model.row/delete- "ERROR: update or delete on table \"group\" violates foreign key constraint \"user_group-id_group_-159406530\" on table \"user\"\n Detail: Key (id)=(1) is still referenced from table \"user\".")))))+ (is (=? {:type :metabase.actions.error/violate-foreign-key-constraint,+ :message "Other tables rely on this row so it cannot be deleted.",+ :errors {}}+ (sql-jdbc.actions/maybe-parse-sql-error+ :postgres actions.error/violate-foreign-key-constraint nil :model.row/delete+ "ERROR: update or delete on table \"group\" violates foreign key constraint \"user_group-id_group_-159406530\" on table \"user\"\n Detail: Key (id)=(1) is still referenced from table \"user\".")))));; this contains special tests case for postgres;; for generic tests, check [[metabase.driver.sql-jdbc.actions-test/action-error-handling-test]]@@ -1138,16 +1138,16 @@(sync/sync-database! database)(mt/with-actions-enabled(testing "when creating with invalid email"- (is (= {:errors {}- :message "Some of your values violate the constraint: email_format_check"- :status-code 400- :type actions.error/violate-check-constraint}- (sql-jdbc.actions-test/perform-action-ex-data- :model.row/create (mt/$ids {:create-row {"email" "invalid-email"- "age" 25}- :database (:id database)- :query {:source-table $$test_users}- :type :query}))))))))))))+ (is (=? {:errors {}+ :message "Some of your values violate the constraint: email_format_check"+ :status-code 400+ :type actions.error/violate-check-constraint}+ (sql-jdbc.actions-test/perform-action-ex-data+ :model.row/create (mt/$ids {:create-row {"email" "invalid-email"+ "age" 25}+ :database (:id database)+ :query {:source-table $$test_users}+ :type :query}))))))))))));; this contains special tests case for postgres;; for generic tests, check [[metabase.driver.sql-jdbc.actions-test/action-error-handling-test]]