Skip to content
Snippets Groups Projects
Unverified Commit 72769e07 authored by Ryan Kienstra's avatar Ryan Kienstra Committed by GitHub
Browse files

Add unit tests for 2 `/api/persist/` endpoints (#33776)

parent fa94e6e5
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,8 @@
[metabase.models.database :refer [Database]]
[metabase.task.persist-refresh :as task.persist-refresh]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]))
[metabase.test.fixtures :as fixtures]
[metabase.util :as u]))
(use-fixtures :once (fixtures/initialize :db :test-users))
......@@ -43,3 +44,39 @@
(is (= default-cron
(get-in (task.persist-refresh/job-info-by-db-id)
[(:id db) :schedule])))))))
(deftest persisted-info-by-id-test
(with-setup db
(mt/with-temp
[:model/Card model {:database_id (u/the-id db), :dataset true}
:model/PersistedInfo pinfo {:database_id (u/the-id db), :card_id (u/the-id model)}]
(testing "Should require a non-negative persisted-info-id"
(is (= "API endpoint does not exist."
(mt/user-http-request :crowberto :get 404 (format "persist/%d" -1)))))
(testing "Should not get info when the persisted-info-id doesn't exist"
(is (= "Not found."
(mt/user-http-request :crowberto :get 404 (format "persist/%d" Integer/MAX_VALUE)))))
(testing "Should get info when the ID exists"
(is (=? {:active true
:card_id (u/the-id model)
:id (u/the-id pinfo)
:state "persisted"}
(mt/user-http-request :crowberto :get 200 (format "persist/%d" (u/the-id pinfo)))))))))
(deftest persisted-info-by-card-id-test
(with-setup db
(mt/with-temp
[:model/Card model {:database_id (u/the-id db), :dataset true}
:model/PersistedInfo pinfo {:database_id (u/the-id db), :card_id (u/the-id model)}]
(testing "Should require a non-negative card-id"
(is (= "API endpoint does not exist."
(mt/user-http-request :crowberto :get 404 (format "persist/card/%d" -1)))))
(testing "Should not get info when the card-id doesn't exist"
(is (= "Not found."
(mt/user-http-request :crowberto :get 404 (format "persist/card/%d" Integer/MAX_VALUE)))))
(testing "Should get info when the ID exists"
(is (=? {:active true
:card_id (u/the-id model)
:id (u/the-id pinfo)
:state "persisted"}
(mt/user-http-request :crowberto :get 200 (format "persist/card/%d" (u/the-id model)))))))))
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