Skip to content

Commit

Permalink
Add tests for api/present-items
Browse files Browse the repository at this point in the history
  • Loading branch information
johnswanson committed Jul 10, 2024
1 parent 7397ce6 commit 3e9e000
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/metabase/api/common_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,27 @@
(underive :event/write-permission-failure ::permission-failure-event)
(underive :event/update-permission-failure ::permission-failure-event)
(underive :event/create-permission-failure ::permission-failure-event))))

(deftest present-items-works
(testing "order is preserved"
(is (= [{:id 1 :model :foo} {:id 2 :model :foo} {:id 3 :model :foo}]
(api/present-items (fn [_ vs]
(reverse vs))
[{:id 1 :model :foo}
{:id 2 :model :foo}
{:id 3 :model :foo}]))))
(testing "duplicate IDs across different models are fine, order is maintained"
(is (= [{:id 1 :model :foo}
{:id 1 :model :bar}
{:id 2 :model :foo}
{:id 2 :model :bar}
{:id 3 :model :foo}
{:id 3 :model :bar}]
(api/present-items (fn [_ vs]
(reverse vs))
[{:id 1 :model :foo}
{:id 1 :model :bar}
{:id 2 :model :foo}
{:id 2 :model :bar}
{:id 3 :model :foo}
{:id 3 :model :bar}])))))

0 comments on commit 3e9e000

Please sign in to comment.