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

Add tests for api endpoints: `timeline-event`, `search` (#34072)


* Add a unit test for /api/pulse/preview_card_info/:id

For the GET endpoint
/api/pulse/preview_card_info/:id

* Add a unit test for the GET endpoint /search/models

* Add a unit test for DELETE /api/timeline-event/:id

* Add a unit test for DELETE /api/timeline-event/:id

* Commit Ngoc's suggestion: Update test/metabase/api/timeline_event_test.clj

Co-authored-by: default avatarNgoc Khuat <qn.khuat@gmail.com>

* Apply Ngoc's suggestion to destructure :timeline_id

* Remove test for event that I created in with-temp

* Fix failed test I introduced, change collection to collection-id

* Test deleting a non-existent timeline event by id

* Move my search-models-test lower

* Copy-paste Ngoc's query-model-set-test and macro

https://github.com/metabase/metabase/pull/32624/files#diff-734923de9c62f49d6b708d64a214ee38d7d0fb1b2c20343bff7b947a6021b021R297-R332

https://github.com/metabase/metabase/pull/32624/files#diff-54344d8b75319d40a4cb2a2afe935500c23d34f0f3c63c51f005493d4dc4f8f1R690-R732



* Remove "database" and "table" from test expectation

Those failed in this PR,
though they passed in 32624

* Revert test for pulse/preview_card_info/, as it'll be removed

* Remove with-verified-cards, which I needlessly copied into this PR

That's needed in 32624,
but not this PR.

* Add a test for the archived-string param

---------

Co-authored-by: default avatarNgoc Khuat <qn.khuat@gmail.com>
parent bc7bd102
No related branches found
No related tags found
No related merge requests found
......@@ -285,6 +285,16 @@
(with-search-items-in-root-collection "test"
(is (= [] (:available_models (mt/user-http-request :crowberto :get 200 "search?q=noresults")))))))
(deftest query-model-set-test
(let [search-term "query-model-set"]
(with-search-items-in-root-collection search-term
(testing "should return a list of models that search result will return"
(is (= #{"dashboard" "dataset" "segment" "collection" "action" "metric" "card"}
(set (mt/user-http-request :crowberto :get 200 "search/models" :q search-term)))))
(testing "should not return models when there is no search result"
(is (= #{}
(set (mt/user-http-request :crowberto :get 200 "search/models" :q "noresults"))))))))
(def ^:private dashboard-count-results
(letfn [(make-card [dashboard-count]
(make-result (str "dashboard-count " dashboard-count) :dashboardcard_count dashboard-count,
......@@ -755,3 +765,55 @@
(snowplow-test/with-fake-snowplow-collector
(mt/user-http-request :crowberto :get 200 "search" :q "test" :archived true)
(is (empty? (snowplow-test/pop-event-data-and-user-id!))))))
(deftest available-models-should-be-independent-of-models-param-test
(testing "if a search request includes `models` params, the `available_models` from the response should not be restricted by it"
(let [search-term "Available models"]
(with-search-items-in-root-collection search-term
(testing "GET /api/search"
(is (= #{"dashboard" "dataset" "segment" "collection" "action" "metric" "card"}
(-> (mt/user-http-request :crowberto :get 200 "search" :q search-term :models "card")
:available_models
set)))
(is (= #{"dashboard" "dataset" "segment" "collection" "action" "metric" "card"}
(-> (mt/user-http-request :crowberto :get 200 "search" :q search-term :models "card" :models "dashboard")
:available_models
set))))
(testing "GET /api/search/models"
(is (= #{"dashboard" "dataset" "segment" "collection" "action" "metric" "card"}
(set (mt/user-http-request :crowberto :get 200 "search/models" :q search-term :models "card"))))
(is (= #{"dashboard" "dataset" "segment" "collection" "action" "metric" "card"}
(set (mt/user-http-request :crowberto :get 200 "search/models" :q search-term :models "card" :models "dashboard")))))))))
(deftest models-table-db-id-test
(testing "search/models request includes `table-db-id` param"
(with-search-items-in-root-collection "Available models"
(testing "`table-db-id` is invalid"
(is (=? {:errors {:table-db-id "nullable value must be an integer greater than zero."}}
(mt/user-http-request :crowberto :get 400 "search/models" :table-db-id -1))))
(testing "`table-db-id` is for a non-existent database"
(is (= #{"dashboard" "database" "segment" "collection" "action" "metric"}
(set (mt/user-http-request :crowberto :get 200 "search/models" :table-db-id Integer/MAX_VALUE)))))
(testing "`table-db-id` is for an existing database"
(is (= #{"dashboard" "database" "segment" "collection" "action" "metric" "card" "dataset" "table"}
(set (mt/user-http-request :crowberto :get 200 "search/models" :table-db-id (mt/id)))))))))
(deftest models-archived-string-test
(testing "search/models request includes `archived-string` param"
(with-search-items-in-root-collection "Available models"
(mt/with-temp [Card {model-id :id} action-model-params
Action _ (archived {:name "test action"
:type :query
:model_id model-id})]
(testing "`archived-string` is invalid"
(is (=? {:message "Invalid input: [\"value must be a valid boolean string ('true' or 'false').\"]"}
(mt/user-http-request :crowberto :get 500 "search/models" :archived-string 1))))
(testing "`archived-string` is 'false'"
(is (= #{"dashboard" "database" "segment" "collection" "action" "metric" "card" "dataset" "table"}
(set (mt/user-http-request :crowberto :get 200 "search/models" :archived-string "false")))))
(testing "`archived-string` is 'true'"
(is (= #{"action"}
(set (mt/user-http-request :crowberto :get 200 "search/models" :archived-string "true")))))))))
......@@ -66,3 +66,19 @@
(is (true?
(->> (mt/user-http-request :rasta :put 200 (str "timeline-event/" (u/the-id event)) {:archived true})
:archived))))))))
(deftest delete-timeline-event-test
(testing "DELETE /api/timeline-event/:id"
(mt/with-temp [Collection {collection-id :id} {:name "Example Data"}
Timeline {timeline-id :id} {:name "Some Events"
:collection_id collection-id}
TimelineEvent {event-id :id} {:name "Example Event"
:timeline_id timeline-id}]
(testing "delete an existing timeline-event `id`"
(is (= nil
(mt/user-http-request :rasta :delete 204 (str "timeline-event/" event-id))))
(is (= "Not found."
(mt/user-http-request :rasta :get 404 (str "timeline-event/" event-id)))))
(testing "delete a non-existent timeline-event `id`"
(is (= "Not found."
(mt/user-http-request :rasta :get 404 (str "timeline-event/" Integer/MAX_VALUE))))))))
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