Skip to content
Snippets Groups Projects
Commit 77396ad3 authored by Allen Gilliland's avatar Allen Gilliland
Browse files

unit test for segment delete via api.

parent 17982fd6
Branches
Tags
No related merge requests found
......@@ -48,7 +48,7 @@
(check-superuser)
(check-404 (segment/exists-segment? id))
(segment/delete-segment id *current-user-id*)
{:ok true})
{:success true})
(defendpoint GET "/:id/revisions"
......
(ns metabase.models.segment
(:require [clojure.tools.logging :as log]
[korma.core :as k]
[korma.db :as kdb]
(:require [korma.core :as k]
[medley.core :as m]
[metabase.config :as config]
[metabase.db :as db]
......
......@@ -9,7 +9,8 @@
[table :refer [Table]])
[metabase.test.util :as tu]
[metabase.test.data.users :refer :all]
[metabase.test.data :refer :all]))
[metabase.test.data :refer :all]
[metabase.models.segment :as segment]))
;; ## Helper Fns
......@@ -25,7 +26,7 @@
:common_name $}))
(defn segment-response [{:keys [created_at updated_at] :as segment}]
(-> segment
(-> (into {} segment) ; model class -> map
(dissoc :id :table_id)
(assoc :created_at (not (nil? created_at)))
(assoc :updated_at (not (nil? updated_at)))))
......@@ -145,8 +146,35 @@
;; ## DELETE /api/segment/:id
;; test security. requires superuser perms
(expect "You don't have permissions to do that."
((user->client :rasta) :delete 403 "segment/1"))
;; ## GET /api/segment
(expect
[{:success true}
{:name "Droids in the desert"
:description "Lookin' for a jedi"
:creator_id (user->id :rasta)
:creator (user-details (fetch-user :rasta))
:created_at true
:updated_at true
:is_active false
:definition {}}]
(tu/with-temp Database [{database-id :id} {:name "Hillbilly"
:engine :yeehaw
:details {}
:is_sample false}]
(tu/with-temp Table [{table-id :id} {:name "Stuff"
:db_id database-id
:active true}]
(tu/with-temp Segment [{:keys [id]} {:creator_id (user->id :rasta)
:table_id table-id
:name "Droids in the desert"
:description "Lookin' for a jedi"
:definition {}}]
[((user->client :crowberto) :delete 200 (format "segment/%d" id))
(segment-response (segment/retrieve-segment id))]))))
;; ## GET /api/segment/:id
......@@ -175,3 +203,8 @@
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}]
(segment-response ((user->client :crowberto) :get 200 (format "segment/%d" id)))))))
;; ## GET /api/segment/:id/revisions
;; ## POST /api/segment/:id/revert
......@@ -145,7 +145,6 @@
;; 3. ability to set description, including to nil
;; 4. ability to modify the definition json
;; 5. revision is captured along with our commit message
;; TODO: check on the revision
(expect
{:creator_id (user->id :rasta)
:creator (user-details :rasta)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment