mirror of
https://github.com/mattermost/focalboard.git
synced 2024-11-24 08:22:29 +02:00
integration tests for GetBoardsComplianceHistory
This commit is contained in:
parent
dd1e64958f
commit
4272e2eac0
@ -133,6 +133,13 @@ func (a *API) handleGetBoardsComplianceHistory(w http.ResponseWriter, r *http.Re
|
||||
return
|
||||
}
|
||||
|
||||
// check for valid team
|
||||
_, err := a.app.GetTeam(teamID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r, model.NewErrBadRequest("invalid team id: "+teamID))
|
||||
return
|
||||
}
|
||||
|
||||
if strPage == "" {
|
||||
strPage = complianceDefaultPage
|
||||
}
|
||||
@ -221,6 +228,13 @@ func (a *API) handleGetBlocksComplianceHistory(w http.ResponseWriter, r *http.Re
|
||||
return
|
||||
}
|
||||
|
||||
// check for valid team
|
||||
_, err := a.app.GetTeam(teamID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r, model.NewErrBadRequest("invalid team id: "+teamID))
|
||||
return
|
||||
}
|
||||
|
||||
if strPage == "" {
|
||||
strPage = complianceDefaultPage
|
||||
}
|
||||
|
@ -1006,7 +1006,7 @@ func (c *Client) GetBoardsForCompliance(teamID string, page, perPage int) (*mode
|
||||
}
|
||||
|
||||
func (c *Client) GetBoardsComplianceHistory(
|
||||
modifiedSince int, includeDeleted bool, teamID string, page, perPage int) (*model.BoardsComplianceHistoryResponse, *Response) {
|
||||
modifiedSince int64, includeDeleted bool, teamID string, page, perPage int) (*model.BoardsComplianceHistoryResponse, *Response) {
|
||||
query := fmt.Sprintf("?modified_since=%d&include_deleted=%t&team_id=%s&page=%d&per_page=%d",
|
||||
modifiedSince, includeDeleted, teamID, page, perPage)
|
||||
r, err := c.DoAPIGet("/admin/boards_history"+query, "")
|
||||
@ -1025,7 +1025,7 @@ func (c *Client) GetBoardsComplianceHistory(
|
||||
}
|
||||
|
||||
func (c *Client) GetBlocksComplianceHistory(
|
||||
modifiedSince int, includeDeleted bool, teamID, boardID string, page, perPage int) (*model.BlocksComplianceHistoryResponse, *Response) {
|
||||
modifiedSince int64, includeDeleted bool, teamID, boardID string, page, perPage int) (*model.BlocksComplianceHistoryResponse, *Response) {
|
||||
query := fmt.Sprintf("?modified_since=%d&include_deleted=%t&team_id=%s&board_id=%s&page=%d&per_page=%d",
|
||||
modifiedSince, includeDeleted, teamID, boardID, page, perPage)
|
||||
r, err := c.DoAPIGet("/admin/blocks_history"+query, "")
|
||||
|
@ -15,6 +15,12 @@ const (
|
||||
testAdmin = "test-admin"
|
||||
)
|
||||
|
||||
var (
|
||||
OneHour int64 = 360000
|
||||
OneDay int64 = OneHour * 24
|
||||
OneYear int64 = OneDay * 365
|
||||
)
|
||||
|
||||
func setupTestHelperForCompliance(t *testing.T, complianceLicense bool) (*TestHelper, Clients) {
|
||||
os.Setenv("FOCALBOARD_UNIT_TESTING_COMPLIANCE", strconv.FormatBool(complianceLicense))
|
||||
|
||||
@ -47,10 +53,10 @@ func TestGetBoardsForCompliance(t *testing.T) {
|
||||
_ = th.CreateBoards(testTeamID, model.BoardTypeOpen, 2)
|
||||
th.Logout(th.Client)
|
||||
|
||||
boards, resp := clients.Anon.GetBoardsForCompliance(testTeamID, 0, 0)
|
||||
bcr, resp := clients.Anon.GetBoardsForCompliance(testTeamID, 0, 0)
|
||||
|
||||
th.CheckUnauthorized(resp)
|
||||
require.Nil(t, boards)
|
||||
require.Nil(t, bcr)
|
||||
})
|
||||
|
||||
t.Run("a user without manage_system permission should be rejected", func(t *testing.T) {
|
||||
@ -72,7 +78,7 @@ func TestGetBoardsForCompliance(t *testing.T) {
|
||||
const count = 10
|
||||
_ = th.CreateBoards(testTeamID, model.BoardTypeOpen, count)
|
||||
|
||||
bcr, resp := clients.Admin.GetBoardsForCompliance(testTeamID, 0, 0) // admin.GetBoardsForCompliance(testTeamID, 0, 0)
|
||||
bcr, resp := clients.Admin.GetBoardsForCompliance(testTeamID, 0, 0)
|
||||
th.CheckOK(resp)
|
||||
require.False(t, bcr.HasNext)
|
||||
require.Len(t, bcr.Results, count)
|
||||
@ -114,3 +120,91 @@ func TestGetBoardsForCompliance(t *testing.T) {
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestGetBoardsComplianceHistory(t *testing.T) {
|
||||
t.Run("missing Features.Compliance license should fail", func(t *testing.T) {
|
||||
th, clients := setupTestHelperForCompliance(t, false)
|
||||
defer th.TearDown()
|
||||
|
||||
_ = th.CreateBoards(testTeamID, model.BoardTypeOpen, 2)
|
||||
|
||||
bchr, resp := clients.Admin.GetBoardsComplianceHistory(utils.GetMillis()-OneDay, true, testTeamID, 0, 0)
|
||||
|
||||
th.CheckNotImplemented(resp)
|
||||
require.Nil(t, bchr)
|
||||
})
|
||||
|
||||
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
|
||||
th, clients := setupTestHelperForCompliance(t, true)
|
||||
defer th.TearDown()
|
||||
|
||||
_ = th.CreateBoards(testTeamID, model.BoardTypeOpen, 2)
|
||||
th.Logout(th.Client)
|
||||
|
||||
bchr, resp := clients.Anon.GetBoardsComplianceHistory(utils.GetMillis()-OneDay, true, testTeamID, 0, 0)
|
||||
|
||||
th.CheckUnauthorized(resp)
|
||||
require.Nil(t, bchr)
|
||||
})
|
||||
|
||||
t.Run("a user without manage_system permission should be rejected", func(t *testing.T) {
|
||||
th, clients := setupTestHelperForCompliance(t, true)
|
||||
defer th.TearDown()
|
||||
|
||||
_ = th.CreateBoards(testTeamID, model.BoardTypeOpen, 2)
|
||||
|
||||
bcr, resp := clients.TeamMember.GetBoardsComplianceHistory(utils.GetMillis()-OneDay, true, testTeamID, 0, 0)
|
||||
|
||||
th.CheckUnauthorized(resp)
|
||||
require.Nil(t, bcr)
|
||||
})
|
||||
|
||||
t.Run("good call", func(t *testing.T) {
|
||||
th, clients := setupTestHelperForCompliance(t, true)
|
||||
defer th.TearDown()
|
||||
|
||||
const count = 10
|
||||
_ = th.CreateBoards(testTeamID, model.BoardTypeOpen, count)
|
||||
|
||||
bchr, resp := clients.Admin.GetBoardsComplianceHistory(utils.GetMillis()-OneDay, true, testTeamID, 0, 0)
|
||||
th.CheckOK(resp)
|
||||
require.False(t, bchr.HasNext)
|
||||
require.Len(t, bchr.Results, count)
|
||||
})
|
||||
|
||||
t.Run("pagination", func(t *testing.T) {
|
||||
th, clients := setupTestHelperForCompliance(t, true)
|
||||
defer th.TearDown()
|
||||
|
||||
const count = 20
|
||||
const perPage = 3
|
||||
_ = th.CreateBoards(testTeamID, model.BoardTypeOpen, count)
|
||||
|
||||
boardHistory := make([]model.BoardHistory, 0, count)
|
||||
page := 0
|
||||
for {
|
||||
bchr, resp := clients.Admin.GetBoardsComplianceHistory(utils.GetMillis()-OneDay, true, testTeamID, page, perPage)
|
||||
page++
|
||||
th.CheckOK(resp)
|
||||
boardHistory = append(boardHistory, bchr.Results...)
|
||||
if !bchr.HasNext {
|
||||
break
|
||||
}
|
||||
}
|
||||
require.Len(t, boardHistory, count)
|
||||
require.Equal(t, int(math.Floor((count/perPage)+1)), page)
|
||||
})
|
||||
|
||||
t.Run("invalid teamID", func(t *testing.T) {
|
||||
th, clients := setupTestHelperForCompliance(t, true)
|
||||
defer th.TearDown()
|
||||
|
||||
_ = th.CreateBoards(testTeamID, model.BoardTypeOpen, 2)
|
||||
|
||||
bchr, resp := clients.Admin.GetBoardsComplianceHistory(utils.GetMillis()-OneDay, true, utils.NewID(utils.IDTypeTeam), 0, 0)
|
||||
|
||||
th.CheckBadRequest(resp)
|
||||
require.Nil(t, bchr)
|
||||
})
|
||||
|
||||
}
|
||||
|
@ -75,8 +75,8 @@ func (s *SQLStore) getBoardsComplianceHistory(db sq.BaseRunner, opts model.Query
|
||||
"bh.id",
|
||||
"bh.team_id",
|
||||
"CASE WHEN bh.delete_at=0 THEN false ELSE true END AS isDeleted",
|
||||
"("+sqlDescendentLastUpdate+") as decendentLastUpdateAt",
|
||||
"("+sqlDescendentFirstUpdate+") as decendentFirstUpdateAt",
|
||||
"COALESCE(("+sqlDescendentLastUpdate+"),0) as decendentLastUpdateAt",
|
||||
"COALESCE(("+sqlDescendentFirstUpdate+"),0) as decendentFirstUpdateAt",
|
||||
"bh.created_by",
|
||||
"bh.modified_by",
|
||||
).
|
||||
@ -186,7 +186,6 @@ func (s *SQLStore) boardsHistoryFromRows(rows *sql.Rows) ([]model.BoardHistory,
|
||||
&boardHistory.ID,
|
||||
&boardHistory.TeamID,
|
||||
&boardHistory.IsDeleted,
|
||||
&boardHistory.CreatedBy,
|
||||
&boardHistory.DescendantLastUpdateAt,
|
||||
&boardHistory.DescendantFirstUpdateAt,
|
||||
&boardHistory.CreatedBy,
|
||||
|
Loading…
Reference in New Issue
Block a user