fleet/ee/server/service/vpp_test.go
Magnus Jensen 1eb65057bb
Move dry run checks around for app store apps gitops and add test case (#33456)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #32432

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

## Testing

- [x] Added/updated automated tests

- [x] QA'd all new/changed functionality manually
2025-10-02 15:54:24 -03:00

49 lines
1.4 KiB
Go

package service
import (
"context"
"database/sql"
"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/require"
)
func TestBatchAssociateVPPApps(t *testing.T) {
t.Parallel()
ds := new(mock.Store)
svc := newTestService(t, ds)
ctx := viewer.NewContext(t.Context(), viewer.Viewer{User: &fleet.User{GlobalRole: ptr.String(fleet.RoleAdmin)}})
t.Run("Fails if missing VPP token when payloads to associate", func(t *testing.T) {
ds.GetVPPTokenByTeamIDFunc = func(ctx context.Context, teamID *uint) (*fleet.VPPTokenDB, error) {
return nil, sql.ErrNoRows
}
t.Run("dry run", func(t *testing.T) {
_, err := svc.BatchAssociateVPPApps(ctx, "", []fleet.VPPBatchPayload{
{
AppStoreID: "my-fake-app",
LabelsExcludeAny: []string{},
LabelsIncludeAny: []string{},
Categories: []string{},
},
}, true)
require.ErrorContains(t, err, "could not retrieve vpp token")
})
t.Run("not dry run", func(t *testing.T) {
_, err := svc.BatchAssociateVPPApps(ctx, "", []fleet.VPPBatchPayload{
{
AppStoreID: "my-fake-app",
LabelsExcludeAny: []string{},
LabelsIncludeAny: []string{},
Categories: []string{},
},
}, false)
require.ErrorContains(t, err, "could not retrieve vpp token")
})
})
}