Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
69e7eb64
Commit
69e7eb64
authored
9 years ago
by
Allen Gilliland
Browse files
Options
Downloads
Patches
Plain Diff
getting the Pulse api unit tests going.
parent
d4b1d743
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/metabase/api/pulse_test.clj
+49
-61
49 additions, 61 deletions
test/metabase/api/pulse_test.clj
with
49 additions
and
61 deletions
test/metabase/api/pulse_test.clj
+
49
−
61
View file @
69e7eb64
...
...
@@ -26,57 +26,17 @@
:dataset_query
{}
:visualization_settings
{}))
(
defn
new-pulse
[]
(
let
[
cards
[(
new-card
)
,
(
new-card
)]
(
defn
new-pulse
[
&
{
:keys
[
name
cards
channels
]
:or
{
name
(
random-name
)
cards
nil
channels
nil
}}]
(
let
[
cards
(
or
cards
[(
new-card
)
,
(
new-card
)])
card-ids
(
filter
identity
(
map
:id
cards
))]
(
pulse/create-pulse
(
random-
name
)
(
user->id
:crowberto
)
card-ids
[])))
(
pulse/create-pulse
name
(
user->id
:crowberto
)
card-ids
[])))
;; ## GET /api/emailreport/form_input
;; Test that we can get the form input options for the Test Org
;(expect-let [_ @test-db ; force lazy loading of Test Data / Metabase DB
; _ (cascade-delete Database :name [not= "Test Database"])] ; Delete all Databases that aren't the Test DB
; {:users #{{:id (user->id :rasta), :name "Rasta Toucan"}
; {:id (user->id :crowberto), :name "Crowberto Corv"}
; {:id (user->id :lucky), :name "Lucky Pigeon"}
; {:id (user->id :trashbird), :name "Trash Bird"}}
; :databases [{:id (:id @test-db)
; :name "Test Database"}],
; :timezones ["GMT"
; "UTC"
; "US/Alaska"
; "US/Arizona"
; "US/Central"
; "US/Eastern"
; "US/Hawaii"
; "US/Mountain"
; "US/Pacific"
; "America/Costa_Rica"]
; :times_of_day [{:id "morning", :realhour 8, :name "Morning"}
; {:id "midday", :realhour 12, :name "Midday"}
; {:id "afternoon", :realhour 16, :name "Afternoon"}
; {:id "evening", :realhour 20, :name "Evening"}
; {:id "midnight", :realhour 0, :name "Midnight"}]
; :days_of_week [{:id "sun", :name "Sun"}
; {:id "mon", :name "Mon"}
; {:id "tue", :name "Tue"}
; {:id "wed", :name "Wed"}
; {:id "thu", :name "Thu"}
; {:id "fri", :name "Fri"}
; {:id "sat", :name "Sat"}]
; :modes [{:name "Active", :id 1}
; {:name "Disabled", :id 2}]
; :permissions [{:name "None", :id 0}
; {:name "Read Only", :id 1}
; {:name "Read & Write", :id 2}]}
; (-> ((user->client :rasta) :get 200 "emailreport/form_input" :org @org-id) ; convert to a set so test doesn't fail if order differs
; (update-in [:users] set)))
;; ## /api/pulse/* AUTHENTICATION Tests
;; We assume that all endpoints for a given context are enforced by the same middleware, so we don't run the same
;; authentication test on every single individual endpoint
(
expect
(
get
middleware/response-unauthentic
:body
)
(
http/client
:get
401
"pulse"
))
(
expect
(
get
middleware/response-unauthentic
:body
)
(
http/client
:put
401
"pulse/13"
))
(
defn
delete-existing-pulses
[]
(
->>
(
db/sel
:many
:field
[
Pulse
:id
])
(
mapv
#
(
db/cascade-delete
Pulse
:id
%
))))
(
defn
user-details
[
user
]
(
match-$
user
...
...
@@ -112,9 +72,9 @@
:created_at
$
:updated_at
$
:creator_id
$
:creator
(
user-details
@
(
:creator
pulse
))
:cards
(
mapv
pulse-card-details
@
(
:cards
pulse
))
:channels
(
mapv
pulse-channel-details
@
(
:channels
pulse
))}))
:creator
(
user-details
(
:creator
pulse
))
:cards
(
mapv
pulse-card-details
(
:cards
pulse
))
:channels
(
mapv
pulse-channel-details
(
:channels
pulse
))}))
(
defn
pulse-response
[{
:keys
[
created_at
updated_at
]
:as
pulse
}]
(
->
pulse
...
...
@@ -123,6 +83,14 @@
(
assoc
:updated_at
(
not
(
nil?
updated_at
)))))
;; ## /api/pulse/* AUTHENTICATION Tests
;; We assume that all endpoints for a given context are enforced by the same middleware, so we don't run the same
;; authentication test on every single individual endpoint
(
expect
(
get
middleware/response-unauthentic
:body
)
(
http/client
:get
401
"pulse"
))
(
expect
(
get
middleware/response-unauthentic
:body
)
(
http/client
:put
401
"pulse/13"
))
;; ## POST /api/pulse
(
expect
{
:errors
{
:name
"field is a required param."
}}
...
...
@@ -158,22 +126,42 @@
{
:name
"A Pulse"
:public_perms
common/perms-readwrite
:creator_id
(
user->id
:rasta
)
:creator
(
user-details
(
fetch-user
:rasta
))
:created_at
true
:updated_at
true
:cards
(
into
[]
(
map
pulse-card-details
[
card1
card2
]))}
(
pulse-response
((
user->client
:rasta
)
:post
200
"pulse"
{
:name
"A Pulse"
:cards
[{
:id
(
:id
card1
)}
{
:id
(
:id
card2
)}]
:channels
[{
:channel_type
"email"
:schedule_type
"daily"
}]})))
:cards
(
mapv
pulse-card-details
[
card1
card2
])
:channels
[{
:channel_type
"email"
:schedule_type
"daily"
:schedule_hour
12
:schedule_day
nil
:details
{}
:recipients
[]}]}
(
->
(
pulse-response
((
user->client
:rasta
)
:post
200
"pulse"
{
:name
"A Pulse"
:cards
[{
:id
(
:id
card1
)}
{
:id
(
:id
card2
)}]
:channels
[{
:channel_type
"email"
:schedule_type
"daily"
:schedule_hour
12
:schedule_day
nil
:recipients
[]}]}))
(
update
:channels
(
fn
[
chans
]
(
mapv
#
(
dissoc
%
:id
:pulse_id
:created_at
:updated_at
)
chans
)))))
;; ## GET /api/pulse
(
expect-let
[
pulse1
(
new-pulse
)
;pulse2 (new-pulse)
]
[(
pulse-details
pulse1
)]
(
expect-let
[
_
(
delete-existing-pulses
)
pulse1
(
new-pulse
:name
"ABC"
)
pulse2
(
new-pulse
:name
"DEF"
)]
[(
pulse-details
pulse1
)
(
pulse-details
pulse2
)]
((
user->client
:rasta
)
:get
200
"pulse"
))
;; ## GET /api/pulse/:id
(
expect-let
[
pulse1
(
new-pulse
)]
(
pulse-details
pulse1
)
((
user->client
:rasta
)
:get
200
(
format
"pulse/%d"
(
:id
pulse1
))))
;(expect-eval-actual-first
; (match-$ (sel :one EmailReport (order :id :DESC))
; {:description nil
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment