This is an automated email from the ASF dual-hosted git repository.

mintsweet pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 0be3e7f37 feat: add total count to scope list api (#5866)
0be3e7f37 is described below

commit 0be3e7f3722b39cbf741122e90632c2920f4d9ab
Author: Klesh Wong <[email protected]>
AuthorDate: Mon Aug 14 18:11:15 2023 +0800

    feat: add total count to scope list api (#5866)
    
    * feat: add total count to scope list api
    
    * fix: e2e test
---
 Makefile                                           |  6 ++----
 .../helpers/pluginhelper/api/scope_db_helper.go    | 12 +++++++----
 .../pluginhelper/api/scope_generic_helper.go       | 15 ++++++++++----
 backend/server/services/remote/plugin/scope_api.go | 13 +++++++++---
 .../services/remote/plugin/scope_db_helper.go      | 12 +++++++----
 backend/test/e2e/manual/azuredevops/azure_test.go  | 13 ++++++------
 backend/test/e2e/manual/gitlab/gitlab_test.go      |  2 +-
 .../test/e2e/manual/pagerduty/pagerduty_test.go    |  9 ++++----
 backend/test/e2e/remote/python_plugin_test.go      | 24 +++++++++++-----------
 backend/test/helper/api.go                         | 11 ++++++----
 backend/test/helper/models.go                      | 12 ++++++++++-
 11 files changed, 82 insertions(+), 47 deletions(-)

diff --git a/Makefile b/Makefile
index 8d70432d4..1ce6c7027 100644
--- a/Makefile
+++ b/Makefile
@@ -112,10 +112,8 @@ unit-test-only:
 python-unit-test:
        make python-unit-test -C backend
 
-e2e-test: build e2e-test-only
-
-e2e-test-only:
-       make e2e-test-only -C backend
+e2e-test:
+       make e2e-test -C backend
 
 e2e-plugins-test:
        make e2e-plugins-test -C backend
diff --git a/backend/helpers/pluginhelper/api/scope_db_helper.go 
b/backend/helpers/pluginhelper/api/scope_db_helper.go
index 08b14cea4..0a3d0e2b8 100644
--- a/backend/helpers/pluginhelper/api/scope_db_helper.go
+++ b/backend/helpers/pluginhelper/api/scope_db_helper.go
@@ -32,7 +32,7 @@ type ScopeDatabaseHelper[Conn any, Scope 
plugin.ToolLayerScope, Tr any] interfac
        SaveScope(scopes []*Scope) errors.Error
        UpdateScope(scope *Scope) errors.Error
        GetScope(connectionId uint64, scopeId string) (*Scope, errors.Error)
-       ListScopes(input *plugin.ApiResourceInput, connectionId uint64) 
([]*Scope, errors.Error)
+       ListScopes(input *plugin.ApiResourceInput, connectionId uint64) 
([]*Scope, int64, errors.Error)
 
        DeleteScope(scope *Scope) errors.Error
        GetScopeConfig(ruleId uint64) (*Tr, errors.Error)
@@ -112,7 +112,7 @@ func (s *ScopeDatabaseHelperImpl[Conn, Scope, Tr]) 
GetScopeAndConfig(connectionI
        return scope, scopeConfig, nil
 }
 
-func (s *ScopeDatabaseHelperImpl[Conn, Scope, Tr]) ListScopes(input 
*plugin.ApiResourceInput, connectionId uint64) ([]*Scope, errors.Error) {
+func (s *ScopeDatabaseHelperImpl[Conn, Scope, Tr]) ListScopes(input 
*plugin.ApiResourceInput, connectionId uint64) ([]*Scope, int64, errors.Error) {
        searchTerm := input.Query.Get("searchTerm")
        query := dal.Where("connection_id = ?", connectionId)
        if searchTerm != "" && s.params.SearchScopeParamName != "" {
@@ -120,8 +120,12 @@ func (s *ScopeDatabaseHelperImpl[Conn, Scope, Tr]) 
ListScopes(input *plugin.ApiR
        }
        limit, offset := GetLimitOffset(input.Query, "pageSize", "page")
        var scopes []*Scope
-       err := s.db.All(&scopes, query, dal.Limit(limit), dal.Offset(offset))
-       return scopes, err
+       count, err := s.db.Count(dal.From(new(Scope)), query)
+       if err != nil {
+               return nil, 0, err
+       }
+       err = s.db.All(&scopes, query, dal.Limit(limit), dal.Offset(offset))
+       return scopes, count, err
 }
 
 func (s *ScopeDatabaseHelperImpl[Conn, Scope, Tr]) DeleteScope(scope *Scope) 
errors.Error {
diff --git a/backend/helpers/pluginhelper/api/scope_generic_helper.go 
b/backend/helpers/pluginhelper/api/scope_generic_helper.go
index fa19fae96..264ac1738 100644
--- a/backend/helpers/pluginhelper/api/scope_generic_helper.go
+++ b/backend/helpers/pluginhelper/api/scope_generic_helper.go
@@ -67,6 +67,10 @@ type (
                Scope                    Scope                    
`mapstructure:",squash"` // ideally we need this field to be embedded in the 
struct
                ScopeResDoc[ScopeConfig] `mapstructure:",squash"` // however, 
only this type of embeding is supported as of golang 1.20
        }
+       ScopeListRes[Scope plugin.ToolLayerScope, ScopeConfig any] struct {
+               Scopes []*ScopeRes[Scope, ScopeConfig] `mapstructure:"scopes" 
json:"scopes"`
+               Count  int64                           `mapstructure:"count" 
json:"count"`
+       }
        ReflectionParameters struct {
                // This corresponds to the struct field of the scope struct's 
ID field
                ScopeIdFieldName string `validate:"required"`
@@ -225,7 +229,7 @@ func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig]) 
UpdateScope(input *pl
        return scopeRes[0], nil
 }
 
-func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig]) GetScopes(input 
*plugin.ApiResourceInput) ([]*ScopeRes[Scope, ScopeConfig], errors.Error) {
+func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig]) GetScopes(input 
*plugin.ApiResourceInput) (*ScopeListRes[Scope, ScopeConfig], errors.Error) {
        params, err := gs.extractFromGetReqParam(input, false)
        if err != nil {
                return nil, errors.BadInput.New("invalid path params: 
\"connectionId\" not set")
@@ -234,9 +238,9 @@ func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig]) 
GetScopes(input *plug
        if err != nil {
                return nil, errors.Default.Wrap(err, fmt.Sprintf("error 
verifying connection for connection ID %d", params.connectionId))
        }
-       scopes, err := gs.dbHelper.ListScopes(input, params.connectionId)
+       scopes, count, err := gs.dbHelper.ListScopes(input, params.connectionId)
        if err != nil {
-               return nil, errors.Default.Wrap(err, fmt.Sprintf("error 
verifying connection for connection ID %d", params.connectionId))
+               return nil, err
        }
        apiScopes, err := gs.addScopeConfig(scopes...)
        if err != nil {
@@ -266,7 +270,10 @@ func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig]) 
GetScopes(input *plug
                        gs.log.Warn(nil, "The following dangling scopes were 
found: %v", danglingIds)
                }
        }
-       return apiScopes, nil
+       return &ScopeListRes[Scope, ScopeConfig]{
+               Scopes: apiScopes,
+               Count:  count,
+       }, nil
 }
 
 func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig]) GetScope(input 
*plugin.ApiResourceInput) (*ScopeRes[Scope, ScopeConfig], errors.Error) {
diff --git a/backend/server/services/remote/plugin/scope_api.go 
b/backend/server/services/remote/plugin/scope_api.go
index 177f70e76..e934486c4 100644
--- a/backend/server/services/remote/plugin/scope_api.go
+++ b/backend/server/services/remote/plugin/scope_api.go
@@ -71,15 +71,22 @@ func (pa *pluginAPI) UpdateScope(input 
*plugin.ApiResourceInput) (*plugin.ApiRes
 }
 
 func (pa *pluginAPI) ListScopes(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
-       scopes, err := pa.scopeHelper.GetScopes(input)
+       paginated, err := pa.scopeHelper.GetScopes(input)
        if err != nil {
                return nil, err
        }
-       response, err := convertScopeResponse(scopes...)
+       scopes, err := convertScopeResponse(paginated.Scopes...)
        if err != nil {
                return nil, err
        }
-       return &plugin.ApiResourceOutput{Body: response, Status: 
http.StatusOK}, nil
+       body := &struct {
+               Scopes []map[string]any `json:"scopes"`
+               Count  int64            `json:"count"`
+       }{
+               Scopes: scopes,
+               Count:  paginated.Count,
+       }
+       return &plugin.ApiResourceOutput{Body: body, Status: http.StatusOK}, nil
 }
 
 func (pa *pluginAPI) GetScope(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
diff --git a/backend/server/services/remote/plugin/scope_db_helper.go 
b/backend/server/services/remote/plugin/scope_db_helper.go
index 6ac6f1103..5e19f0826 100644
--- a/backend/server/services/remote/plugin/scope_db_helper.go
+++ b/backend/server/services/remote/plugin/scope_db_helper.go
@@ -84,12 +84,16 @@ func (s *ScopeDatabaseHelperImpl) GetScope(connectionId 
uint64, scopeId string)
        return scope, nil
 }
 
-func (s *ScopeDatabaseHelperImpl) ListScopes(input *plugin.ApiResourceInput, 
connectionId uint64) ([]*models.DynamicScopeModel, errors.Error) {
+func (s *ScopeDatabaseHelperImpl) ListScopes(input *plugin.ApiResourceInput, 
connectionId uint64) ([]*models.DynamicScopeModel, int64, errors.Error) {
+       count, err := s.db.Count(dal.From(s.pa.scopeType.TableName()), 
dal.Where("connection_id = ?", connectionId))
+       if err != nil {
+               return nil, 0, err
+       }
        limit, offset := api.GetLimitOffset(input.Query, "pageSize", "page")
        scopes := models.NewDynamicScopeModel(s.pa.scopeType).NewSlice()
-       err := api.CallDB(s.db.All, scopes, dal.Where("connection_id = ?", 
connectionId), dal.Limit(limit), dal.Offset(offset))
+       err = api.CallDB(s.db.All, scopes, dal.Where("connection_id = ?", 
connectionId), dal.Limit(limit), dal.Offset(offset))
        if err != nil {
-               return nil, err
+               return nil, 0, err
        }
        var result []*models.DynamicScopeModel
        for _, scopeRaw := range scopes.UnwrapSlice() {
@@ -97,7 +101,7 @@ func (s *ScopeDatabaseHelperImpl) ListScopes(input 
*plugin.ApiResourceInput, con
                _ = scope.From(scopeRaw)
                result = append(result, scope)
        }
-       return result, nil
+       return result, count, nil
 }
 
 func (s *ScopeDatabaseHelperImpl) DeleteScope(scope *models.DynamicScopeModel) 
errors.Error {
diff --git a/backend/test/e2e/manual/azuredevops/azure_test.go 
b/backend/test/e2e/manual/azuredevops/azure_test.go
index fe2cdd35b..14eb0564f 100644
--- a/backend/test/e2e/manual/azuredevops/azure_test.go
+++ b/backend/test/e2e/manual/azuredevops/azure_test.go
@@ -19,6 +19,11 @@ package azuredevops
 
 import (
        "fmt"
+       "net/http"
+       "strings"
+       "testing"
+       "time"
+
        "github.com/apache/incubator-devlake/core/config"
        "github.com/apache/incubator-devlake/core/models"
        "github.com/apache/incubator-devlake/core/models/common"
@@ -27,10 +32,6 @@ import (
        pluginmodels 
"github.com/apache/incubator-devlake/plugins/pagerduty/models"
        "github.com/apache/incubator-devlake/test/helper"
        "github.com/stretchr/testify/require"
-       "net/http"
-       "strings"
-       "testing"
-       "time"
 )
 
 const (
@@ -101,7 +102,7 @@ func TestAzure(t *testing.T) {
                scopes := 
helper.Cast[[]AzureGitRepo](client.CreateScopes(azurePlugin, connection.ID, 
remoteScopesToScopes(remoteScopes, cfg.Repos)...))
                scopesCount := len(scopes)
                scopesResponse := client.ListScopes(azurePlugin, connection.ID, 
false)
-               require.Equal(t, scopesCount, len(scopesResponse))
+               require.Equal(t, scopesCount, len(scopesResponse.Scopes))
                // associate scopes with the scope config
                for _, scope := range scopes {
                        scope.ScopeConfigId = repoConfig.ID
@@ -133,7 +134,7 @@ func TestAzure(t *testing.T) {
                // run the bp
                pipeline := client.TriggerBlueprint(bp.ID)
                require.Equal(t, models.TASK_COMPLETED, pipeline.Status)
-               createdScopesList := client.ListScopes(azurePlugin, 
connection.ID, true)
+               createdScopesList := client.ListScopes(azurePlugin, 
connection.ID, true).Scopes
                require.True(t, len(createdScopesList) > 0)
                
client.SetExpectedStatusCode(http.StatusConflict).DeleteConnection(azurePlugin, 
connection.ID)
                client.DeleteScopeConfig(azurePlugin, connection.ID, 
repoConfig.ID)
diff --git a/backend/test/e2e/manual/gitlab/gitlab_test.go 
b/backend/test/e2e/manual/gitlab/gitlab_test.go
index 3be42a486..e0a0d0b7e 100644
--- a/backend/test/e2e/manual/gitlab/gitlab_test.go
+++ b/backend/test/e2e/manual/gitlab/gitlab_test.go
@@ -121,7 +121,7 @@ func TestGitlabPlugin(t *testing.T) {
                        }
                }
                createdScopes := 
helper.Cast[[]*pluginmodels.GitlabProject](client.CreateScopes(pluginName, 
connection.ID, scopeData...))
-               listedScopes := client.ListScopes(pluginName, connection.ID, 
false)
+               listedScopes := client.ListScopes(pluginName, connection.ID, 
false).Scopes
                require.Equal(t, len(createdScopes), len(listedScopes))
                outputProject := client.CreateProject(&helper.ProjectConfig{
                        ProjectName: fmt.Sprintf("project-%s", pluginName),
diff --git a/backend/test/e2e/manual/pagerduty/pagerduty_test.go 
b/backend/test/e2e/manual/pagerduty/pagerduty_test.go
index 12bd7b2f8..9afce0ff8 100644
--- a/backend/test/e2e/manual/pagerduty/pagerduty_test.go
+++ b/backend/test/e2e/manual/pagerduty/pagerduty_test.go
@@ -19,6 +19,10 @@ package pagerduty
 
 import (
        "fmt"
+       "net/http"
+       "testing"
+       "time"
+
        "github.com/apache/incubator-devlake/core/config"
        "github.com/apache/incubator-devlake/core/models"
        "github.com/apache/incubator-devlake/core/plugin"
@@ -27,9 +31,6 @@ import (
        pluginmodels 
"github.com/apache/incubator-devlake/plugins/pagerduty/models"
        "github.com/apache/incubator-devlake/test/helper"
        "github.com/stretchr/testify/require"
-       "net/http"
-       "testing"
-       "time"
 )
 
 const pluginName = "pagerduty"
@@ -100,7 +101,7 @@ func TestPagerDutyPlugin(t *testing.T) {
                fmt.Printf("=========================Triggering blueprint for 
project %s =========================\n", outputProject.Name)
                pipeline := client.TriggerBlueprint(bp.ID)
                require.Equal(t, models.TASK_COMPLETED, pipeline.Status)
-               createdScopesList := client.ListScopes(pluginName, 
connection.ID, true)
+               createdScopesList := client.ListScopes(pluginName, 
connection.ID, true).Scopes
                require.True(t, len(createdScopesList) > 0)
                
client.SetExpectedStatusCode(http.StatusConflict).DeleteConnection(pluginName, 
connection.ID)
                client.DeleteBlueprint(bp.ID)
diff --git a/backend/test/e2e/remote/python_plugin_test.go 
b/backend/test/e2e/remote/python_plugin_test.go
index 10b778ff2..83b4a9fa7 100644
--- a/backend/test/e2e/remote/python_plugin_test.go
+++ b/backend/test/e2e/remote/python_plugin_test.go
@@ -77,7 +77,7 @@ func TestDeleteConnection_WithDependentScopesAndConfig(t 
*testing.T) {
        refs = client.DeleteConnection(PLUGIN_NAME, connection.ID)
        require.Equal(t, 0, len(refs.Projects))
        require.Equal(t, 0, len(refs.Blueprints))
-       scopeRes := 
client.SetExpectedStatusCode(http.StatusBadRequest).ListScopes(PLUGIN_NAME, 
connection.ID, false)
+       scopeRes := 
client.SetExpectedStatusCode(http.StatusBadRequest).ListScopes(PLUGIN_NAME, 
connection.ID, false).Scopes
        require.Equal(t, 0, len(scopeRes))
        configs := client.ListScopeConfigs(PLUGIN_NAME, connection.ID)
        require.Equal(t, 0, len(configs))
@@ -130,7 +130,7 @@ func TestCreateScope(t *testing.T) {
        conn := CreateTestConnection(client)
        scopeConfig := CreateTestScopeConfig(client, conn.ID)
        scope := CreateTestScope(client, scopeConfig, conn.ID)
-       scopes := client.ListScopes(PLUGIN_NAME, conn.ID, false)
+       scopes := client.ListScopes(PLUGIN_NAME, conn.ID, false).Scopes
        require.Equal(t, 1, len(scopes))
        cicdScope := helper.Cast[FakeProject](client.GetScope(PLUGIN_NAME, 
conn.ID, scope.Id, false).Scope)
        require.Equal(t, scope.Id, cicdScope.Id)
@@ -175,13 +175,13 @@ func TestBlueprintV200_withScopeDeletion_Conflict(t 
*testing.T) {
        client := CreateClient(t)
        params := CreateTestBlueprints(t, client, 1)
        client.TriggerBlueprint(params.blueprints[0].ID)
-       scopesResponse := client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true)
+       scopesResponse := client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true).Scopes
        require.Equal(t, 1, len(scopesResponse))
        require.Equal(t, 1, len(scopesResponse[0].Blueprints))
        refs := DeleteScopeWithDataIntegrityValidation(t, 
client.SetExpectedStatusCode(http.StatusConflict), params.connection.ID, 
params.scope.Id, false)
        require.Equal(t, 1, len(refs.Blueprints))
        require.Equal(t, 1, len(refs.Projects))
-       scopesResponse = client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true)
+       scopesResponse = client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true).Scopes
        require.Equal(t, 1, len(scopesResponse))
        bpsResult := client.ListBlueprints()
        require.Equal(t, 1, len(bpsResult.Blueprints))
@@ -191,11 +191,11 @@ func TestBlueprintV200_withBlueprintDeletion(t 
*testing.T) {
        client := CreateClient(t)
        params := CreateTestBlueprints(t, client, 2)
        client.TriggerBlueprint(params.blueprints[0].ID)
-       scopesResponse := client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true)
+       scopesResponse := client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true).Scopes
        require.Equal(t, 1, len(scopesResponse))
        require.Equal(t, 2, len(scopesResponse[0].Blueprints))
        client.DeleteBlueprint(params.blueprints[0].ID)
-       scopesResponse = client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true)
+       scopesResponse = client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true).Scopes
        require.Equal(t, 1, len(scopesResponse))
        bpsList := client.ListBlueprints()
        require.Equal(t, 1, len(bpsList.Blueprints))
@@ -208,18 +208,18 @@ func 
TestBlueprintV200_withBlueprintDeletion_thenScopeDeletion(t *testing.T) {
        client := CreateClient(t)
        params := CreateTestBlueprints(t, client, 1)
        client.TriggerBlueprint(params.blueprints[0].ID)
-       scopesResponse := client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true)
+       scopesResponse := client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true).Scopes
        require.Equal(t, 1, len(scopesResponse))
        require.Equal(t, 1, len(scopesResponse[0].Blueprints))
        client.DeleteBlueprint(params.blueprints[0].ID)
-       scopesResponse = client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true)
+       scopesResponse = client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true).Scopes
        require.Equal(t, 1, len(scopesResponse))
        bpsList := client.ListBlueprints()
        require.Equal(t, 0, len(bpsList.Blueprints))
        refs := DeleteScopeWithDataIntegrityValidation(t, client, 
params.connection.ID, params.scope.Id, false)
        require.Equal(t, 0, len(refs.Blueprints))
        require.Equal(t, 0, len(refs.Projects))
-       scopesResponse = client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true)
+       scopesResponse = client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true).Scopes
        require.Equal(t, 0, len(scopesResponse))
        projectsResponse := client.ListProjects()
        require.Equal(t, 1, len(projectsResponse.Projects))
@@ -229,18 +229,18 @@ func 
TestBlueprintV200_withProjectDeletion_thenScopeDeletion(t *testing.T) {
        client := CreateClient(t)
        params := CreateTestBlueprints(t, client, 1)
        client.TriggerBlueprint(params.blueprints[0].ID)
-       scopesResponse := client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true)
+       scopesResponse := client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true).Scopes
        require.Equal(t, 1, len(scopesResponse))
        require.Equal(t, 1, len(scopesResponse[0].Blueprints))
        client.DeleteProject(params.projects[0].Name)
-       scopesResponse = client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true)
+       scopesResponse = client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true).Scopes
        require.Equal(t, 1, len(scopesResponse))
        bpsList := client.ListBlueprints()
        require.Equal(t, 0, len(bpsList.Blueprints))
        refs := DeleteScopeWithDataIntegrityValidation(t, client, 
params.connection.ID, params.scope.Id, false)
        require.Equal(t, 0, len(refs.Blueprints))
        require.Equal(t, 0, len(refs.Projects))
-       scopesResponse = client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true)
+       scopesResponse = client.ListScopes(PLUGIN_NAME, params.connection.ID, 
true).Scopes
        require.Equal(t, 0, len(scopesResponse))
        projectsResponse := client.ListProjects()
        require.Equal(t, 0, len(projectsResponse.Projects))
diff --git a/backend/test/helper/api.go b/backend/test/helper/api.go
index 23423e074..21aad1fd3 100644
--- a/backend/test/helper/api.go
+++ b/backend/test/helper/api.go
@@ -208,17 +208,20 @@ func (d *DevlakeClient) UpdateScope(pluginName string, 
connectionId uint64, scop
        }, http.MethodPatch, 
fmt.Sprintf("%s/plugins/%s/connections/%d/scopes/%s", d.Endpoint, pluginName, 
connectionId, scopeId), nil, scope)
 }
 
-func (d *DevlakeClient) ListScopes(pluginName string, connectionId uint64, 
listBlueprints bool) []ScopeResponse {
-       scopesRaw := sendHttpRequest[[]map[string]any](d.testCtx, d.timeout, 
&testContext{
+func (d *DevlakeClient) ListScopes(pluginName string, connectionId uint64, 
listBlueprints bool) ScopeListResponseOut {
+       scopesRaw := sendHttpRequest[ScopeListResponseIn](d.testCtx, d.timeout, 
&testContext{
                client:       d,
                printPayload: true,
                inlineJson:   false,
        }, http.MethodGet, 
fmt.Sprintf("%s/plugins/%s/connections/%d/scopes?blueprints=%v", d.Endpoint, 
pluginName, connectionId, listBlueprints), nil, nil)
        var responses []ScopeResponse
-       for _, scopeRaw := range scopesRaw {
+       for _, scopeRaw := range scopesRaw.Scopes {
                responses = append(responses, getScopeResponse(scopeRaw))
        }
-       return responses
+       return ScopeListResponseOut{
+               Scopes: responses,
+               Count:  scopesRaw.Count,
+       }
 }
 
 func (d *DevlakeClient) GetScope(pluginName string, connectionId uint64, 
scopeId string, listBlueprints bool) ScopeResponse {
diff --git a/backend/test/helper/models.go b/backend/test/helper/models.go
index ad49c50c8..03903212a 100644
--- a/backend/test/helper/models.go
+++ b/backend/test/helper/models.go
@@ -18,9 +18,10 @@ limitations under the License.
 package helper
 
 import (
+       "time"
+
        "github.com/apache/incubator-devlake/core/config"
        "github.com/apache/incubator-devlake/core/models"
-       "time"
 
        "github.com/apache/incubator-devlake/core/plugin"
        "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
@@ -43,6 +44,15 @@ type (
                ScopeConfig any
                Blueprints  []*models.Blueprint
        }
+
+       ScopeListResponseIn struct {
+               Scopes []map[string]interface{}
+               Count  int64
+       }
+       ScopeListResponseOut struct {
+               Scopes []ScopeResponse
+               Count  int64
+       }
 )
 
 type Connection struct {

Reply via email to