2018-01-29 06:51:01 -06:00
|
|
|
package api
|
|
|
|
|
2018-02-20 11:11:50 -06:00
|
|
|
import (
|
2021-09-14 09:08:04 -05:00
|
|
|
"context"
|
2018-02-21 04:24:54 -06:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2022-06-22 03:29:26 -05:00
|
|
|
"net/http"
|
2018-02-21 04:24:54 -06:00
|
|
|
"testing"
|
|
|
|
|
2022-06-30 08:31:54 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2018-02-21 04:24:54 -06:00
|
|
|
"github.com/grafana/grafana/pkg/api/dtos"
|
2021-01-15 07:43:20 -06:00
|
|
|
"github.com/grafana/grafana/pkg/api/response"
|
|
|
|
"github.com/grafana/grafana/pkg/api/routing"
|
2020-03-04 05:57:20 -06:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2022-06-22 03:29:26 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
|
|
|
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
2018-03-06 16:59:45 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
2022-03-03 08:05:47 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
2022-10-10 14:47:53 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/folder"
|
|
|
|
"github.com/grafana/grafana/pkg/services/folder/foldertest"
|
2022-06-28 03:09:25 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/guardian"
|
2022-07-15 11:06:44 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
2022-06-28 03:09:25 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
|
2022-09-20 11:58:04 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/team/teamtest"
|
2022-08-10 04:56:48 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/user"
|
2019-03-06 01:09:34 -06:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2022-06-22 03:29:26 -05:00
|
|
|
"github.com/grafana/grafana/pkg/web/webtest"
|
2018-02-20 11:11:50 -06:00
|
|
|
)
|
|
|
|
|
2020-11-13 02:52:38 -06:00
|
|
|
func TestFoldersAPIEndpoint(t *testing.T) {
|
2022-10-10 14:47:53 -05:00
|
|
|
folderService := &foldertest.FakeService{}
|
2022-02-16 07:15:44 -06:00
|
|
|
|
2020-11-13 02:52:38 -06:00
|
|
|
t.Run("Given a correct request for creating a folder", func(t *testing.T) {
|
|
|
|
cmd := models.CreateFolderCommand{
|
|
|
|
Uid: "uid",
|
|
|
|
Title: "Folder",
|
|
|
|
}
|
2018-02-21 04:24:54 -06:00
|
|
|
|
2022-10-10 14:47:53 -05:00
|
|
|
folderService.ExpectedFolder = &models.Folder{Id: 1, Uid: "uid", Title: "Folder"}
|
2018-02-21 04:24:54 -06:00
|
|
|
|
2022-02-16 07:15:44 -06:00
|
|
|
createFolderScenario(t, "When calling POST on", "/api/folders", "/api/folders", folderService, cmd,
|
2020-11-13 02:52:38 -06:00
|
|
|
func(sc *scenarioContext) {
|
2018-02-21 04:24:54 -06:00
|
|
|
callCreateFolder(sc)
|
|
|
|
|
2020-11-13 02:52:38 -06:00
|
|
|
folder := dtos.Folder{}
|
|
|
|
err := json.NewDecoder(sc.resp.Body).Decode(&folder)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(1), folder.Id)
|
|
|
|
assert.Equal(t, "uid", folder.Uid)
|
|
|
|
assert.Equal(t, "Folder", folder.Title)
|
2018-02-21 04:24:54 -06:00
|
|
|
})
|
2020-11-13 02:52:38 -06:00
|
|
|
})
|
2018-02-21 04:24:54 -06:00
|
|
|
|
2020-11-13 02:52:38 -06:00
|
|
|
t.Run("Given incorrect requests for creating a folder", func(t *testing.T) {
|
2022-10-10 14:47:53 -05:00
|
|
|
t.Cleanup(func() {
|
|
|
|
folderService.ExpectedError = nil
|
|
|
|
})
|
2020-11-13 02:52:38 -06:00
|
|
|
testCases := []struct {
|
|
|
|
Error error
|
|
|
|
ExpectedStatusCode int
|
|
|
|
}{
|
2022-06-30 08:31:54 -05:00
|
|
|
{Error: dashboards.ErrFolderWithSameUIDExists, ExpectedStatusCode: 409},
|
|
|
|
{Error: dashboards.ErrFolderTitleEmpty, ExpectedStatusCode: 400},
|
|
|
|
{Error: dashboards.ErrFolderSameNameExists, ExpectedStatusCode: 409},
|
|
|
|
{Error: dashboards.ErrDashboardInvalidUid, ExpectedStatusCode: 400},
|
|
|
|
{Error: dashboards.ErrDashboardUidTooLong, ExpectedStatusCode: 400},
|
|
|
|
{Error: dashboards.ErrFolderAccessDenied, ExpectedStatusCode: 403},
|
|
|
|
{Error: dashboards.ErrFolderNotFound, ExpectedStatusCode: 404},
|
|
|
|
{Error: dashboards.ErrFolderVersionMismatch, ExpectedStatusCode: 412},
|
|
|
|
{Error: dashboards.ErrFolderFailedGenerateUniqueUid, ExpectedStatusCode: 500},
|
2020-11-13 02:52:38 -06:00
|
|
|
}
|
2018-02-21 04:24:54 -06:00
|
|
|
|
2020-11-13 02:52:38 -06:00
|
|
|
cmd := models.CreateFolderCommand{
|
|
|
|
Uid: "uid",
|
|
|
|
Title: "Folder",
|
|
|
|
}
|
2018-02-21 04:24:54 -06:00
|
|
|
|
2020-11-13 02:52:38 -06:00
|
|
|
for _, tc := range testCases {
|
2022-10-10 14:47:53 -05:00
|
|
|
folderService.ExpectedError = tc.Error
|
2018-02-21 04:24:54 -06:00
|
|
|
|
2020-11-13 02:52:38 -06:00
|
|
|
createFolderScenario(t, fmt.Sprintf("Expect '%s' error when calling POST on", tc.Error.Error()),
|
2022-02-16 07:15:44 -06:00
|
|
|
"/api/folders", "/api/folders", folderService, cmd, func(sc *scenarioContext) {
|
2018-02-21 04:24:54 -06:00
|
|
|
callCreateFolder(sc)
|
2020-11-13 02:52:38 -06:00
|
|
|
assert.Equalf(t, tc.ExpectedStatusCode, sc.resp.Code, "Wrong status code for error %s", tc.Error)
|
2018-02-21 04:24:54 -06:00
|
|
|
})
|
2020-11-13 02:52:38 -06:00
|
|
|
}
|
|
|
|
})
|
2018-02-21 04:24:54 -06:00
|
|
|
|
2020-11-13 02:52:38 -06:00
|
|
|
t.Run("Given a correct request for updating a folder", func(t *testing.T) {
|
|
|
|
cmd := models.UpdateFolderCommand{
|
|
|
|
Title: "Folder upd",
|
|
|
|
}
|
2018-02-21 04:24:54 -06:00
|
|
|
|
2022-10-10 14:47:53 -05:00
|
|
|
folderService.ExpectedFolder = &models.Folder{Id: 1, Uid: "uid", Title: "Folder upd"}
|
2018-02-21 04:24:54 -06:00
|
|
|
|
2022-02-16 07:15:44 -06:00
|
|
|
updateFolderScenario(t, "When calling PUT on", "/api/folders/uid", "/api/folders/:uid", folderService, cmd,
|
2020-11-13 02:52:38 -06:00
|
|
|
func(sc *scenarioContext) {
|
2018-02-21 04:24:54 -06:00
|
|
|
callUpdateFolder(sc)
|
|
|
|
|
2020-11-13 02:52:38 -06:00
|
|
|
folder := dtos.Folder{}
|
|
|
|
err := json.NewDecoder(sc.resp.Body).Decode(&folder)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(1), folder.Id)
|
|
|
|
assert.Equal(t, "uid", folder.Uid)
|
|
|
|
assert.Equal(t, "Folder upd", folder.Title)
|
2018-02-21 04:24:54 -06:00
|
|
|
})
|
2020-11-13 02:52:38 -06:00
|
|
|
})
|
2018-02-21 04:24:54 -06:00
|
|
|
|
2020-11-13 02:52:38 -06:00
|
|
|
t.Run("Given incorrect requests for updating a folder", func(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
Error error
|
|
|
|
ExpectedStatusCode int
|
|
|
|
}{
|
2022-06-30 08:31:54 -05:00
|
|
|
{Error: dashboards.ErrFolderWithSameUIDExists, ExpectedStatusCode: 409},
|
|
|
|
{Error: dashboards.ErrFolderTitleEmpty, ExpectedStatusCode: 400},
|
|
|
|
{Error: dashboards.ErrFolderSameNameExists, ExpectedStatusCode: 409},
|
|
|
|
{Error: dashboards.ErrDashboardInvalidUid, ExpectedStatusCode: 400},
|
|
|
|
{Error: dashboards.ErrDashboardUidTooLong, ExpectedStatusCode: 400},
|
|
|
|
{Error: dashboards.ErrFolderAccessDenied, ExpectedStatusCode: 403},
|
|
|
|
{Error: dashboards.ErrFolderNotFound, ExpectedStatusCode: 404},
|
|
|
|
{Error: dashboards.ErrFolderVersionMismatch, ExpectedStatusCode: 412},
|
|
|
|
{Error: dashboards.ErrFolderFailedGenerateUniqueUid, ExpectedStatusCode: 500},
|
2020-11-13 02:52:38 -06:00
|
|
|
}
|
2018-02-21 04:24:54 -06:00
|
|
|
|
2020-11-13 02:52:38 -06:00
|
|
|
cmd := models.UpdateFolderCommand{
|
|
|
|
Title: "Folder upd",
|
|
|
|
}
|
2018-02-21 04:24:54 -06:00
|
|
|
|
2020-11-13 02:52:38 -06:00
|
|
|
for _, tc := range testCases {
|
2022-10-10 14:47:53 -05:00
|
|
|
folderService.ExpectedError = tc.Error
|
2020-11-13 02:52:38 -06:00
|
|
|
updateFolderScenario(t, fmt.Sprintf("Expect '%s' error when calling PUT on", tc.Error.Error()),
|
2022-02-16 07:15:44 -06:00
|
|
|
"/api/folders/uid", "/api/folders/:uid", folderService, cmd, func(sc *scenarioContext) {
|
2018-02-21 04:24:54 -06:00
|
|
|
callUpdateFolder(sc)
|
2020-11-13 02:52:38 -06:00
|
|
|
assert.Equalf(t, tc.ExpectedStatusCode, sc.resp.Code, "Wrong status code for %s", tc.Error)
|
2018-02-21 04:24:54 -06:00
|
|
|
})
|
2020-11-13 02:52:38 -06:00
|
|
|
}
|
2018-02-21 04:24:54 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-06-22 03:29:26 -05:00
|
|
|
func TestHTTPServer_FolderMetadata(t *testing.T) {
|
|
|
|
setUpRBACGuardian(t)
|
2022-10-10 14:47:53 -05:00
|
|
|
folderService := &foldertest.FakeService{}
|
2022-06-22 03:29:26 -05:00
|
|
|
server := SetupAPITestServer(t, func(hs *HTTPServer) {
|
|
|
|
hs.folderService = folderService
|
|
|
|
hs.AccessControl = acmock.New()
|
2022-11-08 03:52:07 -06:00
|
|
|
hs.QuotaService = quotatest.NewQuotaServiceFake()
|
2022-06-22 03:29:26 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Should attach access control metadata to multiple folders", func(t *testing.T) {
|
2022-10-10 14:47:53 -05:00
|
|
|
folderService.ExpectedFolders = []*models.Folder{{Uid: "1"}, {Uid: "2"}, {Uid: "3"}}
|
2022-06-22 03:29:26 -05:00
|
|
|
|
|
|
|
req := server.NewGetRequest("/api/folders?accesscontrol=true")
|
2022-08-11 06:28:55 -05:00
|
|
|
webtest.RequestWithSignedInUser(req, &user.SignedInUser{UserID: 1, OrgID: 1, Permissions: map[int64]map[string][]string{
|
2022-06-22 03:29:26 -05:00
|
|
|
1: accesscontrol.GroupScopesByAction([]accesscontrol.Permission{
|
|
|
|
{Action: dashboards.ActionFoldersRead, Scope: dashboards.ScopeFoldersAll},
|
|
|
|
{Action: dashboards.ActionFoldersWrite, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID("2")},
|
|
|
|
}),
|
|
|
|
}})
|
|
|
|
|
|
|
|
res, err := server.Send(req)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() { require.NoError(t, res.Body.Close()) }()
|
|
|
|
assert.Equal(t, http.StatusOK, res.StatusCode)
|
|
|
|
|
|
|
|
body := []dtos.FolderSearchHit{}
|
|
|
|
require.NoError(t, json.NewDecoder(res.Body).Decode(&body))
|
|
|
|
|
|
|
|
for _, f := range body {
|
|
|
|
assert.True(t, f.AccessControl[dashboards.ActionFoldersRead])
|
|
|
|
if f.Uid == "2" {
|
|
|
|
assert.True(t, f.AccessControl[dashboards.ActionFoldersWrite])
|
|
|
|
} else {
|
|
|
|
assert.False(t, f.AccessControl[dashboards.ActionFoldersWrite])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Should attach access control metadata to folder response", func(t *testing.T) {
|
2022-10-10 14:47:53 -05:00
|
|
|
folderService.ExpectedFolder = &models.Folder{Uid: "folderUid"}
|
2022-06-22 03:29:26 -05:00
|
|
|
|
|
|
|
req := server.NewGetRequest("/api/folders/folderUid?accesscontrol=true")
|
2022-08-11 06:28:55 -05:00
|
|
|
webtest.RequestWithSignedInUser(req, &user.SignedInUser{UserID: 1, OrgID: 1, Permissions: map[int64]map[string][]string{
|
2022-06-22 03:29:26 -05:00
|
|
|
1: accesscontrol.GroupScopesByAction([]accesscontrol.Permission{
|
|
|
|
{Action: dashboards.ActionFoldersRead, Scope: dashboards.ScopeFoldersAll},
|
|
|
|
{Action: dashboards.ActionFoldersWrite, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID("folderUid")},
|
|
|
|
}),
|
|
|
|
}})
|
|
|
|
|
|
|
|
res, err := server.Send(req)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, http.StatusOK, res.StatusCode)
|
|
|
|
defer func() { require.NoError(t, res.Body.Close()) }()
|
|
|
|
|
|
|
|
body := dtos.Folder{}
|
|
|
|
require.NoError(t, json.NewDecoder(res.Body).Decode(&body))
|
|
|
|
|
|
|
|
assert.True(t, body.AccessControl[dashboards.ActionFoldersRead])
|
|
|
|
assert.True(t, body.AccessControl[dashboards.ActionFoldersWrite])
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Should attach access control metadata to folder response", func(t *testing.T) {
|
2022-10-10 14:47:53 -05:00
|
|
|
folderService.ExpectedFolder = &models.Folder{Uid: "folderUid"}
|
2022-06-22 03:29:26 -05:00
|
|
|
|
|
|
|
req := server.NewGetRequest("/api/folders/folderUid")
|
2022-08-11 06:28:55 -05:00
|
|
|
webtest.RequestWithSignedInUser(req, &user.SignedInUser{UserID: 1, OrgID: 1, Permissions: map[int64]map[string][]string{
|
2022-06-22 03:29:26 -05:00
|
|
|
1: accesscontrol.GroupScopesByAction([]accesscontrol.Permission{
|
|
|
|
{Action: dashboards.ActionFoldersRead, Scope: dashboards.ScopeFoldersAll},
|
|
|
|
{Action: dashboards.ActionFoldersWrite, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID("folderUid")},
|
|
|
|
}),
|
|
|
|
}})
|
|
|
|
|
|
|
|
res, err := server.Send(req)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, http.StatusOK, res.StatusCode)
|
|
|
|
defer func() { require.NoError(t, res.Body.Close()) }()
|
|
|
|
|
|
|
|
body := dtos.Folder{}
|
|
|
|
require.NoError(t, json.NewDecoder(res.Body).Decode(&body))
|
|
|
|
|
|
|
|
assert.False(t, body.AccessControl[dashboards.ActionFoldersRead])
|
|
|
|
assert.False(t, body.AccessControl[dashboards.ActionFoldersWrite])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-02-21 04:24:54 -06:00
|
|
|
func callCreateFolder(sc *scenarioContext) {
|
|
|
|
sc.fakeReqWithParams("POST", sc.url, map[string]string{}).exec()
|
|
|
|
}
|
|
|
|
|
2022-10-10 14:47:53 -05:00
|
|
|
func createFolderScenario(t *testing.T, desc string, url string, routePattern string, folderService folder.Service,
|
2020-11-13 02:52:38 -06:00
|
|
|
cmd models.CreateFolderCommand, fn scenarioFunc) {
|
2022-06-22 03:29:26 -05:00
|
|
|
setUpRBACGuardian(t)
|
2020-11-13 02:52:38 -06:00
|
|
|
t.Run(fmt.Sprintf("%s %s", desc, url), func(t *testing.T) {
|
2022-07-18 08:14:58 -05:00
|
|
|
aclMockResp := []*models.DashboardACLInfoDTO{}
|
2022-09-20 11:58:04 -05:00
|
|
|
teamSvc := &teamtest.FakeService{}
|
2022-06-28 03:09:25 -05:00
|
|
|
dashSvc := &dashboards.FakeDashboardService{}
|
2022-07-18 08:14:58 -05:00
|
|
|
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*models.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
|
|
|
q := args.Get(1).(*models.GetDashboardACLInfoListQuery)
|
2022-06-28 03:09:25 -05:00
|
|
|
q.Result = aclMockResp
|
|
|
|
}).Return(nil)
|
|
|
|
store := mockstore.NewSQLStoreMock()
|
2022-09-20 11:58:04 -05:00
|
|
|
guardian.InitLegacyGuardian(store, dashSvc, teamSvc)
|
2019-03-06 01:09:34 -06:00
|
|
|
hs := HTTPServer{
|
2022-06-22 03:29:26 -05:00
|
|
|
AccessControl: acmock.New(),
|
2022-02-16 07:15:44 -06:00
|
|
|
folderService: folderService,
|
2022-06-22 03:29:26 -05:00
|
|
|
Cfg: setting.NewCfg(),
|
2022-03-03 08:05:47 -06:00
|
|
|
Features: featuremgmt.WithFeatures(),
|
2019-03-06 01:09:34 -06:00
|
|
|
}
|
|
|
|
|
2020-11-13 02:52:38 -06:00
|
|
|
sc := setupScenarioContext(t, url)
|
2021-01-15 07:43:20 -06:00
|
|
|
sc.defaultHandler = routing.Wrap(func(c *models.ReqContext) response.Response {
|
2021-11-29 03:18:01 -06:00
|
|
|
c.Req.Body = mockRequestBody(cmd)
|
2022-02-09 06:44:38 -06:00
|
|
|
c.Req.Header.Add("Content-Type", "application/json")
|
2018-02-21 04:24:54 -06:00
|
|
|
sc.context = c
|
2022-08-11 06:28:55 -05:00
|
|
|
sc.context.SignedInUser = &user.SignedInUser{OrgID: testOrgID, UserID: testUserID}
|
2018-02-21 04:24:54 -06:00
|
|
|
|
2021-11-29 03:18:01 -06:00
|
|
|
return hs.CreateFolder(c)
|
2018-02-21 04:24:54 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
sc.m.Post(routePattern, sc.defaultHandler)
|
2018-02-20 06:57:32 -06:00
|
|
|
|
2018-02-21 04:24:54 -06:00
|
|
|
fn(sc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func callUpdateFolder(sc *scenarioContext) {
|
|
|
|
sc.fakeReqWithParams("PUT", sc.url, map[string]string{}).exec()
|
|
|
|
}
|
2018-02-20 06:57:32 -06:00
|
|
|
|
2022-10-10 14:47:53 -05:00
|
|
|
func updateFolderScenario(t *testing.T, desc string, url string, routePattern string, folderService folder.Service,
|
2020-11-13 02:52:38 -06:00
|
|
|
cmd models.UpdateFolderCommand, fn scenarioFunc) {
|
2022-06-22 03:29:26 -05:00
|
|
|
setUpRBACGuardian(t)
|
2020-11-13 02:52:38 -06:00
|
|
|
t.Run(fmt.Sprintf("%s %s", desc, url), func(t *testing.T) {
|
2021-03-17 10:06:10 -05:00
|
|
|
hs := HTTPServer{
|
2022-02-16 07:15:44 -06:00
|
|
|
Cfg: setting.NewCfg(),
|
2022-06-22 03:29:26 -05:00
|
|
|
AccessControl: acmock.New(),
|
2022-02-16 07:15:44 -06:00
|
|
|
folderService: folderService,
|
2021-03-17 10:06:10 -05:00
|
|
|
}
|
|
|
|
|
2020-11-13 02:52:38 -06:00
|
|
|
sc := setupScenarioContext(t, url)
|
2021-01-15 07:43:20 -06:00
|
|
|
sc.defaultHandler = routing.Wrap(func(c *models.ReqContext) response.Response {
|
2021-11-29 03:18:01 -06:00
|
|
|
c.Req.Body = mockRequestBody(cmd)
|
2022-02-09 06:44:38 -06:00
|
|
|
c.Req.Header.Add("Content-Type", "application/json")
|
2018-02-21 04:24:54 -06:00
|
|
|
sc.context = c
|
2022-08-11 06:28:55 -05:00
|
|
|
sc.context.SignedInUser = &user.SignedInUser{OrgID: testOrgID, UserID: testUserID}
|
2018-02-20 06:57:32 -06:00
|
|
|
|
2021-11-29 03:18:01 -06:00
|
|
|
return hs.UpdateFolder(c)
|
2018-02-21 04:24:54 -06:00
|
|
|
})
|
2018-02-20 06:57:32 -06:00
|
|
|
|
2018-02-21 04:24:54 -06:00
|
|
|
sc.m.Put(routePattern, sc.defaultHandler)
|
2018-02-20 06:57:32 -06:00
|
|
|
|
2018-02-21 04:24:54 -06:00
|
|
|
fn(sc)
|
|
|
|
})
|
|
|
|
}
|
2018-02-20 11:11:50 -06:00
|
|
|
|
|
|
|
type fakeFolderService struct {
|
2022-10-10 14:47:53 -05:00
|
|
|
folder.Service
|
2021-03-17 10:06:10 -05:00
|
|
|
|
2020-03-04 05:57:20 -06:00
|
|
|
GetFoldersResult []*models.Folder
|
2018-02-20 11:11:50 -06:00
|
|
|
GetFoldersError error
|
2020-03-04 05:57:20 -06:00
|
|
|
GetFolderByUIDResult *models.Folder
|
2018-03-22 16:13:46 -05:00
|
|
|
GetFolderByUIDError error
|
2020-03-04 05:57:20 -06:00
|
|
|
GetFolderByIDResult *models.Folder
|
2018-03-22 16:13:46 -05:00
|
|
|
GetFolderByIDError error
|
2020-03-04 05:57:20 -06:00
|
|
|
CreateFolderResult *models.Folder
|
2018-02-20 11:11:50 -06:00
|
|
|
CreateFolderError error
|
2020-03-04 05:57:20 -06:00
|
|
|
UpdateFolderResult *models.Folder
|
2018-02-20 11:11:50 -06:00
|
|
|
UpdateFolderError error
|
2022-11-10 02:42:32 -06:00
|
|
|
DeleteFolderResult *folder.Folder
|
2018-02-20 11:11:50 -06:00
|
|
|
DeleteFolderError error
|
|
|
|
DeletedFolderUids []string
|
|
|
|
}
|
|
|
|
|
2022-08-10 04:56:48 -05:00
|
|
|
func (s *fakeFolderService) GetFolders(ctx context.Context, user *user.SignedInUser, orgID int64, limit int64, page int64) ([]*models.Folder, error) {
|
2018-02-20 11:11:50 -06:00
|
|
|
return s.GetFoldersResult, s.GetFoldersError
|
|
|
|
}
|
|
|
|
|
2022-08-10 04:56:48 -05:00
|
|
|
func (s *fakeFolderService) GetFolderByID(ctx context.Context, user *user.SignedInUser, id int64, orgID int64) (*models.Folder, error) {
|
2018-03-22 16:13:46 -05:00
|
|
|
return s.GetFolderByIDResult, s.GetFolderByIDError
|
2018-02-20 11:11:50 -06:00
|
|
|
}
|
|
|
|
|
2022-08-10 04:56:48 -05:00
|
|
|
func (s *fakeFolderService) GetFolderByUID(ctx context.Context, user *user.SignedInUser, orgID int64, uid string) (*models.Folder, error) {
|
2018-03-22 16:13:46 -05:00
|
|
|
return s.GetFolderByUIDResult, s.GetFolderByUIDError
|
2018-02-20 11:11:50 -06:00
|
|
|
}
|
|
|
|
|
2022-08-10 04:56:48 -05:00
|
|
|
func (s *fakeFolderService) CreateFolder(ctx context.Context, user *user.SignedInUser, orgID int64, title, uid string) (*models.Folder, error) {
|
2021-03-17 10:06:10 -05:00
|
|
|
return s.CreateFolderResult, s.CreateFolderError
|
2018-02-20 11:11:50 -06:00
|
|
|
}
|
|
|
|
|
2022-08-10 04:56:48 -05:00
|
|
|
func (s *fakeFolderService) UpdateFolder(ctx context.Context, user *user.SignedInUser, orgID int64, existingUid string, cmd *models.UpdateFolderCommand) error {
|
2018-02-21 04:24:54 -06:00
|
|
|
cmd.Result = s.UpdateFolderResult
|
2018-02-20 11:11:50 -06:00
|
|
|
return s.UpdateFolderError
|
|
|
|
}
|
|
|
|
|
2022-11-10 02:42:32 -06:00
|
|
|
func (s *fakeFolderService) DeleteFolder(ctx context.Context, cmd *folder.DeleteFolderCommand) error {
|
|
|
|
s.DeletedFolderUids = append(s.DeletedFolderUids, cmd.UID)
|
|
|
|
return s.DeleteFolderError
|
2018-02-20 11:11:50 -06:00
|
|
|
}
|