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
57733085
Commit
57733085
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
tests for the revision API endpoints and dashboards
parent
93b9298e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/models/dashboard.clj
+20
-21
20 additions, 21 deletions
src/metabase/models/dashboard.clj
test/metabase/api/revision_test.clj
+91
-0
91 additions, 0 deletions
test/metabase/api/revision_test.clj
test/metabase/models/revision_test.clj
+1
-1
1 addition, 1 deletion
test/metabase/models/revision_test.clj
with
112 additions
and
22 deletions
src/metabase/models/dashboard.clj
+
20
−
21
View file @
57733085
...
...
@@ -71,27 +71,26 @@
serialized-dashboard
)
(
defn-
describe-diff
[
_
username
dashboard
₁
dashboard
₂
]
(
let
[[
_
changes
]
(
diff
dashboard
₁
dashboard
₂
)]
(
println
"CHANGES -> "
changes
)
(
str
(
->>
[(
when
(
:name
changes
)
(
format
"renamed it from \"%s\" to \"%s\""
(
:name
dashboard
₁
)
(
:name
dashboard
₂
)))
(
when
(
:description
changes
)
(
format
"changed the description from \"%s\" to \"%s\""
(
:description
dashboard
₁
)
(
:description
dashboard
₂
)))
(
when
(
:public_perms
changes
)
(
if
(
zero?
(
:public_perms
dashboard
₂
))
"made it private"
"made it public"
))
; TODO - are both 1 and 2 "public" now ?
(
when
(
:cards
changes
)
(
let
[
num-cards
₁
(
count
(
:cards
dashboard
₁
))
num-cards
₂
(
count
(
:cards
dashboard
₂
))]
(
cond
(
>
num-cards
₁
num-cards
₂
)
"removed a card"
(
<
num-cards
₁
num-cards
₂
)
"added a card"
:else
"repositioned the cards"
)))]
(
filter
identity
)
build-sentence
(
apply
str
username
" "
)
(
#
(
s/replace-first
%
"it "
"this dashboard "
)))
\.
)))
(
let
[[
removals
changes
]
(
diff
dashboard
₁
dashboard
₂
)]
(
->>
[(
when
(
:name
changes
)
(
format
"renamed it from \"%s\" to \"%s\""
(
:name
dashboard
₁
)
(
:name
dashboard
₂
)))
(
when
(
:description
changes
)
(
format
"changed the description from \"%s\" to \"%s\""
(
:description
dashboard
₁
)
(
:description
dashboard
₂
)))
(
when
(
:public_perms
changes
)
(
if
(
zero?
(
:public_perms
dashboard
₂
))
"made it private"
"made it public"
))
; TODO - are both 1 and 2 "public" now ?
(
when
(
or
(
:cards
changes
)
(
:cards
removals
))
(
let
[
num-cards
₁
(
count
(
:cards
dashboard
₁
))
num-cards
₂
(
count
(
:cards
dashboard
₂
))]
(
cond
(
<
num-cards
₁
num-cards
₂
)
"added a card"
(
>
num-cards
₁
num-cards
₂
)
"removed a card"
:else
"rearranged the cards"
)))]
(
filter
identity
)
build-sentence
(
apply
str
username
" "
)
(
#
(
s/replace-first
%
"it "
"this dashboard "
)))))
(
extend
DashboardEntity
IRevisioned
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/revision_test.clj
0 → 100644
+
91
−
0
View file @
57733085
(
ns
metabase.api.revision-test
(
:require
[
expectations
:refer
:all
]
[
korma.core
:as
k
]
[
medley.core
:as
m
]
[
metabase.api.revision
:refer
:all
]
[
metabase.db
:as
db
]
(
metabase.models
[
dashboard
:refer
[
Dashboard
]]
[
dashboard-card
:refer
[
DashboardCard
]]
[
revision-test
:refer
[
with-fake-card
]])
[
metabase.test.data.users
:refer
:all
]))
(
defn
x
[]
(
with-fake-card
[{
card-id
₁
:id
}]
(
with-fake-card
[{
card-id
₂
:id
}]
((
user->client
:rasta
)
:get
200
"revision"
,
:entity
:card,
:id
card-id
₁
))))
(
defn
y
[]
(
with-fake-card
[{
card-id
:id
}]
((
user->client
:rasta
)
:get
200
"revision"
,
:entity
:card,
:id
card-id
)))
(
defn-
fake-dashboard
[
&
{
:as
kwargs
}]
(
m/mapply
db/ins
Dashboard
(
merge
{
:name
(
str
(
java.util.UUID/randomUUID
))
:public_perms
0
:creator_id
(
user->id
:rasta
)}
kwargs
)))
(
defmacro
with-fake-dashboard
[[
binding
&
{
:as
kwargs
}]
&
body
]
`
(
let
[
dash
#
(
fake-dashboard
~@
kwargs
)
~
binding
dash
#
]
(
try
~@
body
(
finally
(
db/cascade-delete
Dashboard
:id
(
:id
dash
#
))))))
(
def
^
:private
rasta-revision-info
(
delay
{
:id
(
user->id
:rasta
)
:common_name
"Rasta Toucan"
,
:first_name
"Rasta"
,
:last_name
"Toucan"
}))
;;; # TESTS FOR GET /api/revision
(
expect
[{
:description
"First revision."
,
:user
{}}]
(
with-fake-card
[{
card-id
:id
}]
((
user->client
:rasta
)
:get
200
"revision"
,
:entity
:card,
:id
card-id
)))
(
expect
[{
:is_reversion
false,
:user
@
rasta-revision-info,
:description
"First revision."
}]
(
with-fake-dashboard
[{
dash-id
:id
}]
(
with-fake-card
[{
card-id
:id
}]
((
user->client
:rasta
)
:post
200
(
format
"dash/%d/cards"
dash-id
)
,
{
:cardId
card-id
})
(
->>
((
user->client
:rasta
)
:get
200
"revision"
,
:entity
:dashboard,
:id
dash-id
)
(
mapv
#
(
dissoc
%
:timestamp
:id
))))))
(
expect
[{
:is_reversion
false,
:user
@
rasta-revision-info,
:description
"Rasta Toucan added a card."
}
{
:is_reversion
false,
:user
@
rasta-revision-info,
:description
"First revision."
}]
(
with-fake-dashboard
[{
dash-id
:id
}]
(
with-fake-card
[{
card-id
₁
:id
}]
(
with-fake-card
[{
card-id
₂
:id
}]
((
user->client
:rasta
)
:post
200
(
format
"dash/%d/cards"
dash-id
)
,
{
:cardId
card-id
₁
})
((
user->client
:rasta
)
:post
200
(
format
"dash/%d/cards"
dash-id
)
,
{
:cardId
card-id
₂
})
(
->>
((
user->client
:rasta
)
:get
200
"revision"
,
:entity
:dashboard,
:id
dash-id
)
(
mapv
#
(
dissoc
%
:timestamp
:id
)))))))
(
expect
[{
:is_reversion
false,
:user
@
rasta-revision-info,
:description
"Rasta Toucan removed a card."
}
{
:is_reversion
false,
:user
@
rasta-revision-info,
:description
"Rasta Toucan added a card."
}
{
:is_reversion
false,
:user
@
rasta-revision-info,
:description
"First revision."
}]
(
with-fake-dashboard
[{
dash-id
:id
}]
(
with-fake-card
[{
card-id
₁
:id
}]
(
with-fake-card
[{
card-id
₂
:id
}]
((
user->client
:rasta
)
:post
200
(
format
"dash/%d/cards"
dash-id
)
,
{
:cardId
card-id
₁
})
((
user->client
:rasta
)
:post
200
(
format
"dash/%d/cards"
dash-id
)
,
{
:cardId
card-id
₂
})
((
user->client
:rasta
)
:delete
204
(
format
"dash/%d/cards"
dash-id
)
,
:dashcardId
(
db/sel
:one
:id
DashboardCard
(
k/order
:id
:desc
)))
(
->>
((
user->client
:rasta
)
:get
200
"revision"
,
:entity
:dashboard,
:id
dash-id
)
(
mapv
#
(
dissoc
%
:timestamp
:id
)))))))
;;; # TESTS FOR POST /api/revision/revert
(
expect
[
2
[{
:is_reversion
true,
:user
@
rasta-revision-info,
:description
"Rasta Toucan reverted to an earlier revision and added a card."
}
{
:is_reversion
false,
:user
@
rasta-revision-info,
:description
"Rasta Toucan removed a card."
}
{
:is_reversion
false,
:user
@
rasta-revision-info,
:description
"Rasta Toucan added a card."
}
{
:is_reversion
false,
:user
@
rasta-revision-info,
:description
"First revision."
}]]
(
with-fake-dashboard
[{
dash-id
:id
}]
(
with-fake-card
[{
card-id
₁
:id
}]
(
with-fake-card
[{
card-id
₂
:id
}]
((
user->client
:rasta
)
:post
200
(
format
"dash/%d/cards"
dash-id
)
,
{
:cardId
card-id
₁
})
((
user->client
:rasta
)
:post
200
(
format
"dash/%d/cards"
dash-id
)
,
{
:cardId
card-id
₂
})
((
user->client
:rasta
)
:delete
204
(
format
"dash/%d/cards"
dash-id
)
,
:dashcardId
(
db/sel
:one
:id
DashboardCard
(
k/order
:id
:desc
)))
(
let
[[
_
{
previous-revision-id
:id
}]
(
metabase.models.revision/revisions
Dashboard
dash-id
)]
;; Revert to the previous revision
((
user->client
:rasta
)
:post
200
"revision/revert"
,
{
:entity
:dashboard,
:id
dash-id,
:revision_id
previous-revision-id
})
[
;; [1] There should be 2 cards again
(
count
@
(
:ordered_cards
(
Dashboard
dash-id
)))
;; [2] A new revision recording the reversion should have been pushed
(
->>
((
user->client
:rasta
)
:get
200
"revision"
,
:entity
:dashboard,
:id
dash-id
)
(
mapv
#
(
dissoc
%
:timestamp
:id
)))])))))
This diff is collapsed.
Click to expand it.
test/metabase/models/revision_test.clj
+
1
−
1
View file @
57733085
...
...
@@ -9,7 +9,7 @@
[
metabase.test.data.users
:refer
:all
]
[
metabase.util
:as
u
]))
(
defn
-
fake-card
[
&
{
:as
kwargs
}]
(
defn
fake-card
[
&
{
:as
kwargs
}]
(
m/mapply
db/ins
Card
(
merge
{
:name
(
str
(
java.util.UUID/randomUUID
))
:display
:table
:public_perms
0
...
...
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