Folders: Introduce folder service function for fetching folders by org and UIDs that contain optionally the folder full path (#80716)
* Folders: Expose function for getting all org folders with specific UIDs * Return all org folders if UIDs is empty * Filter out not accessible folders by the user * Modify query to optionally returning a string that contains the UIDs of all parent folders separated by slash.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -759,24 +760,91 @@ func TestIntegrationGetFolders(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("get folders by UIDs should succeed", func(t *testing.T) {
|
||||
ff, err := folderStore.GetFolders(context.Background(), orgID, uids)
|
||||
actualFolders, err := folderStore.GetFolders(context.Background(), NewGetFoldersQuery(folder.GetFoldersQuery{OrgID: orgID, UIDs: uids[1:]}))
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, len(uids), len(ff))
|
||||
for _, f := range folders {
|
||||
folderInResponseIdx := slices.IndexFunc(ff, func(rf *folder.Folder) bool {
|
||||
assert.Equal(t, len(uids[1:]), len(actualFolders))
|
||||
for _, f := range folders[1:] {
|
||||
folderInResponseIdx := slices.IndexFunc(actualFolders, func(rf *folder.Folder) bool {
|
||||
return rf.UID == f.UID
|
||||
})
|
||||
assert.NotEqual(t, -1, folderInResponseIdx)
|
||||
rf := ff[folderInResponseIdx]
|
||||
assert.Equal(t, f.UID, rf.UID)
|
||||
assert.Equal(t, f.OrgID, rf.OrgID)
|
||||
assert.Equal(t, f.Title, rf.Title)
|
||||
assert.Equal(t, f.Description, rf.Description)
|
||||
assert.NotEmpty(t, rf.Created)
|
||||
assert.NotEmpty(t, rf.Updated)
|
||||
assert.NotEmpty(t, rf.URL)
|
||||
actualFolder := actualFolders[folderInResponseIdx]
|
||||
assert.Equal(t, f.UID, actualFolder.UID)
|
||||
assert.Equal(t, f.OrgID, actualFolder.OrgID)
|
||||
assert.Equal(t, f.Title, actualFolder.Title)
|
||||
assert.Equal(t, f.Description, actualFolder.Description)
|
||||
assert.NotEmpty(t, actualFolder.Created)
|
||||
assert.NotEmpty(t, actualFolder.Updated)
|
||||
assert.NotEmpty(t, actualFolder.URL)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("get folders by UIDs batching should work as expected", func(t *testing.T) {
|
||||
q := NewGetFoldersQuery(folder.GetFoldersQuery{OrgID: orgID, UIDs: uids[1:], BatchSize: 3})
|
||||
actualFolders, err := folderStore.GetFolders(context.Background(), q)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, len(uids[1:]), len(actualFolders))
|
||||
for _, f := range folders[1:] {
|
||||
folderInResponseIdx := slices.IndexFunc(actualFolders, func(rf *folder.Folder) bool {
|
||||
return rf.UID == f.UID
|
||||
})
|
||||
assert.NotEqual(t, -1, folderInResponseIdx)
|
||||
actualFolder := actualFolders[folderInResponseIdx]
|
||||
assert.Equal(t, f.UID, actualFolder.UID)
|
||||
assert.Equal(t, f.OrgID, actualFolder.OrgID)
|
||||
assert.Equal(t, f.Title, actualFolder.Title)
|
||||
assert.Equal(t, f.Description, actualFolder.Description)
|
||||
assert.NotEmpty(t, actualFolder.Created)
|
||||
assert.NotEmpty(t, actualFolder.Updated)
|
||||
assert.NotEmpty(t, actualFolder.URL)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("get folders by UIDs with fullpath should succeed", func(t *testing.T) {
|
||||
q := NewGetFoldersQuery(folder.GetFoldersQuery{OrgID: orgID, UIDs: uids[1:], WithFullpath: true})
|
||||
q.BatchSize = 3
|
||||
actualFolders, err := folderStore.GetFolders(context.Background(), q)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, len(uids[1:]), len(actualFolders))
|
||||
for _, f := range folders[1:] {
|
||||
folderInResponseIdx := slices.IndexFunc(actualFolders, func(rf *folder.Folder) bool {
|
||||
return rf.UID == f.UID
|
||||
})
|
||||
assert.NotEqual(t, -1, folderInResponseIdx)
|
||||
actualFolder := actualFolders[folderInResponseIdx]
|
||||
assert.Equal(t, f.UID, actualFolder.UID)
|
||||
assert.Equal(t, f.OrgID, actualFolder.OrgID)
|
||||
assert.Equal(t, f.Title, actualFolder.Title)
|
||||
assert.Equal(t, f.Description, actualFolder.Description)
|
||||
assert.NotEmpty(t, actualFolder.Created)
|
||||
assert.NotEmpty(t, actualFolder.Updated)
|
||||
assert.NotEmpty(t, actualFolder.URL)
|
||||
assert.NotEmpty(t, actualFolder.Fullpath)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("get folders by UIDs and ancestor UIDs should work as expected", func(t *testing.T) {
|
||||
q := NewGetFoldersQuery(folder.GetFoldersQuery{OrgID: orgID, UIDs: uids[1:], BatchSize: 3})
|
||||
q.ancestorUIDs = make([]string, 0, int(q.BatchSize)+1)
|
||||
for i := 0; i < int(q.BatchSize); i++ {
|
||||
q.ancestorUIDs = append(q.ancestorUIDs, uuid.New().String())
|
||||
}
|
||||
q.ancestorUIDs = append(q.ancestorUIDs, folders[len(folders)-1].UID)
|
||||
|
||||
actualFolders, err := folderStore.GetFolders(context.Background(), q)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, len(actualFolders))
|
||||
|
||||
f := folders[len(folders)-1]
|
||||
actualFolder := actualFolders[0]
|
||||
assert.Equal(t, f.UID, actualFolder.UID)
|
||||
assert.Equal(t, f.OrgID, actualFolder.OrgID)
|
||||
assert.Equal(t, f.Title, actualFolder.Title)
|
||||
assert.Equal(t, f.Description, actualFolder.Description)
|
||||
assert.NotEmpty(t, actualFolder.Created)
|
||||
assert.NotEmpty(t, actualFolder.Updated)
|
||||
assert.NotEmpty(t, actualFolder.URL)
|
||||
})
|
||||
}
|
||||
|
||||
func CreateOrg(t *testing.T, db *sqlstore.SQLStore) int64 {
|
||||
|
||||
Reference in New Issue
Block a user