2021-09-14 13:58:48 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/fleetdm/fleet/v4/server/contexts/viewer"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/mock"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/ptr"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestService_ListSoftware(t *testing.T) {
|
|
|
|
ds := new(mock.Store)
|
|
|
|
|
|
|
|
var calledWithTeamID *uint
|
2021-10-20 21:01:20 +00:00
|
|
|
var calledWithOpt fleet.SoftwareListOptions
|
|
|
|
ds.ListSoftwareFunc = func(ctx context.Context, opt fleet.SoftwareListOptions) ([]fleet.Software, error) {
|
|
|
|
calledWithTeamID = opt.TeamID
|
2021-09-14 13:58:48 +00:00
|
|
|
calledWithOpt = opt
|
|
|
|
return []fleet.Software{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
user := &fleet.User{ID: 3, Email: "foo@bar.com", GlobalRole: ptr.String(fleet.RoleObserver)}
|
|
|
|
|
|
|
|
svc := newTestService(ds, nil, nil)
|
|
|
|
ctx := context.Background()
|
|
|
|
ctx = viewer.NewContext(ctx, viewer.Viewer{User: user})
|
|
|
|
|
2021-10-20 21:01:20 +00:00
|
|
|
_, err := svc.ListSoftware(ctx, fleet.SoftwareListOptions{TeamID: ptr.Uint(42), ListOptions: fleet.ListOptions{PerPage: 77, Page: 4}})
|
2021-09-14 13:58:48 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
assert.True(t, ds.ListSoftwareFuncInvoked)
|
|
|
|
assert.Equal(t, ptr.Uint(42), calledWithTeamID)
|
2021-10-20 21:01:20 +00:00
|
|
|
assert.Equal(t, fleet.ListOptions{PerPage: 77, Page: 4}, calledWithOpt.ListOptions)
|
2021-09-14 13:58:48 +00:00
|
|
|
}
|