Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
3be1d71f
Commit
3be1d71f
authored
Mar 11, 2019
by
Leonard Gram
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
teams: test refactorings.
parent
319879cf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
82 deletions
+52
-82
pkg/services/teams/team.go
+0
-1
pkg/services/teams/teams_test.go
+52
-81
No files found.
pkg/services/teams/team.go
View file @
3be1d71f
...
...
@@ -23,7 +23,6 @@ func canUpdateTeam(orgId int64, teamId int64, user *m.SignedInUser) error {
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
// TODO: look into how we want to do logging
return
err
}
...
...
pkg/services/teams/teams_test.go
View file @
3be1d71f
...
...
@@ -11,57 +11,43 @@ import (
func
TestUpdateTeam
(
t
*
testing
.
T
)
{
Convey
(
"Updating a team"
,
t
,
func
()
{
bus
.
ClearBusHandlers
()
Convey
(
"Given an editor and a team he isn't a member of"
,
func
()
{
editor
:=
m
.
SignedInUser
{
UserId
:
1
,
OrgId
:
1
,
OrgRole
:
m
.
ROLE_EDITOR
,
}
Convey
(
"Should not be able to update the team"
,
func
()
{
cmd
:=
m
.
UpdateTeamCommand
{
Id
:
1
,
OrgId
:
editor
.
OrgId
,
}
admin
:=
m
.
SignedInUser
{
UserId
:
1
,
OrgId
:
1
,
OrgRole
:
m
.
ROLE_ADMIN
,
}
editor
:=
m
.
SignedInUser
{
UserId
:
2
,
OrgId
:
1
,
OrgRole
:
m
.
ROLE_EDITOR
,
}
testTeam
:=
m
.
Team
{
Id
:
1
,
OrgId
:
1
,
}
updateTeamCmd
:=
m
.
UpdateTeamCommand
{
Id
:
testTeam
.
Id
,
OrgId
:
testTeam
.
OrgId
,
}
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
UpdateTeamCommand
)
error
{
return
errors
.
New
(
"Editor not allowed to update team."
)
}
)
Convey
(
"Given an editor and a team he isn't a member of"
,
func
()
{
Convey
(
"Should not be able to update the team"
,
func
()
{
shouldNotUpdateTeam
(
)
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
GetTeamMembersQuery
)
error
{
cmd
.
Result
=
[]
*
m
.
TeamMemberDTO
{}
return
nil
})
err
:=
UpdateTeam
(
&
editor
,
&
cmd
)
err
:=
UpdateTeam
(
&
editor
,
&
updateTeamCmd
)
So
(
err
,
ShouldEqual
,
m
.
ErrNotAllowedToUpdateTeam
)
})
})
Convey
(
"Given an editor and a team he is a member of"
,
func
()
{
editor
:=
m
.
SignedInUser
{
UserId
:
1
,
OrgId
:
1
,
OrgRole
:
m
.
ROLE_EDITOR
,
}
testTeam
:=
m
.
Team
{
Id
:
1
,
OrgId
:
1
,
}
Convey
(
"Should be able to update the team"
,
func
()
{
cmd
:=
m
.
UpdateTeamCommand
{
Id
:
testTeam
.
Id
,
OrgId
:
testTeam
.
OrgId
,
}
teamUpdated
:=
false
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
UpdateTeamCommand
)
error
{
teamUpdated
=
true
return
nil
})
teamUpdatedCallback
:=
updateTeamCalled
()
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
GetTeamMembersQuery
)
error
{
cmd
.
Result
=
[]
*
m
.
TeamMemberDTO
{{
...
...
@@ -73,38 +59,29 @@ func TestUpdateTeam(t *testing.T) {
return
nil
})
err
:=
UpdateTeam
(
&
editor
,
&
cmd
)
So
(
teamUpdated
,
ShouldBeTrue
)
err
:=
UpdateTeam
(
&
editor
,
&
updateTeamCmd
)
So
(
teamUpdatedCallback
(),
ShouldBeTrue
)
So
(
err
,
ShouldBeNil
)
})
})
Convey
(
"Given an editor and a team in another org"
,
func
()
{
editor
:=
m
.
SignedInUser
{
UserId
:
1
,
OrgId
:
1
,
OrgRole
:
m
.
ROLE_EDITOR
,
}
testTeam
:=
m
.
Team
{
testTeamOtherOrg
:=
m
.
Team
{
Id
:
1
,
OrgId
:
2
,
}
Convey
(
"Shouldn't be able to update the team"
,
func
()
{
cmd
:=
m
.
UpdateTeamCommand
{
Id
:
testTeam
.
Id
,
OrgId
:
testTeam
.
OrgId
,
Id
:
testTeam
OtherOrg
.
Id
,
OrgId
:
testTeam
OtherOrg
.
OrgId
,
}
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
UpdateTeamCommand
)
error
{
return
errors
.
New
(
"Can't update a team in a different org."
)
})
shouldNotUpdateTeam
()
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
GetTeamMembersQuery
)
error
{
cmd
.
Result
=
[]
*
m
.
TeamMemberDTO
{{
OrgId
:
testTeam
.
OrgId
,
TeamId
:
testTeam
.
Id
,
OrgId
:
testTeam
OtherOrg
.
OrgId
,
TeamId
:
testTeam
OtherOrg
.
Id
,
UserId
:
editor
.
UserId
,
Permission
:
int64
(
m
.
PERMISSION_ADMIN
),
}}
...
...
@@ -112,41 +89,35 @@ func TestUpdateTeam(t *testing.T) {
})
err
:=
UpdateTeam
(
&
editor
,
&
cmd
)
So
(
err
,
ShouldEqual
,
m
.
ErrNotAllowedToUpdateTeamInDifferentOrg
)
})
})
Convey
(
"Given an org admin and a team"
,
func
()
{
editor
:=
m
.
SignedInUser
{
UserId
:
1
,
OrgId
:
1
,
OrgRole
:
m
.
ROLE_ADMIN
,
}
testTeam
:=
m
.
Team
{
Id
:
1
,
OrgId
:
1
,
}
Convey
(
"Should be able to update the team"
,
func
()
{
cmd
:=
m
.
UpdateTeamCommand
{
Id
:
testTeam
.
Id
,
OrgId
:
testTeam
.
OrgId
,
}
teamUpdated
:=
false
teamUpdatedCallback
:=
updateTeamCalled
()
err
:=
UpdateTeam
(
&
admin
,
&
updateTeamCmd
)
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
UpdateTeamCommand
)
error
{
teamUpdated
=
true
return
nil
})
err
:=
UpdateTeam
(
&
editor
,
&
cmd
)
So
(
teamUpdated
,
ShouldBeTrue
)
So
(
teamUpdatedCallback
(),
ShouldBeTrue
)
So
(
err
,
ShouldBeNil
)
})
})
})
}
func
updateTeamCalled
()
func
()
bool
{
wasCalled
:=
false
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
UpdateTeamCommand
)
error
{
wasCalled
=
true
return
nil
})
return
func
()
bool
{
return
wasCalled
}
}
func
shouldNotUpdateTeam
()
{
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
UpdateTeamCommand
)
error
{
return
errors
.
New
(
"UpdateTeamCommand not expected."
)
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment