Skip to content

Commit

Permalink
Test against wrong OS, wrong team, unavailable apps
Browse files Browse the repository at this point in the history
  • Loading branch information
dantecatalfamo committed Oct 3, 2024
1 parent 7669366 commit 7476ff4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/datastore/mysql/setup_experience.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ WHERE id IN (%s)`
for k := range missingTitleIDs {
keys = append(keys, fmt.Sprintf("%d", k))
}
return ctxerr.Errorf(ctx, "title IDs not availabe: %s", strings.Join(keys, ","))
return ctxerr.Errorf(ctx, "title IDs not available: %s", strings.Join(keys, ","))
}

if _, err := tx.ExecContext(ctx, stmtUnsetInstallers, teamID); err != nil {
Expand Down
39 changes: 35 additions & 4 deletions server/datastore/mysql/setup_experience_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,17 @@ func testSetSetupExperienceTitles(t *testing.T, ds *Datastore) {
}
}

softwareTitles, count, meta, err = ds.ListSoftwareTitles(ctx, fleet.SoftwareTitleListOptions{TeamID: &team2.ID}, fleet.TeamFilter{TeamID: &team2.ID})

Check failure on line 305 in server/datastore/mysql/setup_experience_test.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

ineffectual assignment to count (ineffassign)

Check failure on line 305 in server/datastore/mysql/setup_experience_test.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

ineffectual assignment to count (ineffassign)
require.NoError(t, err)

for _, title := range softwareTitles {
if title.AppStoreApp != nil {
titleVPP[title.AppStoreApp.AppStoreID] = title.ID
} else if title.SoftwarePackage != nil {
titleSoftware[title.SoftwarePackage.Name] = title.ID
}
}

err = ds.SetSetupExperienceSoftwareTitles(ctx, team1.ID, []uint{titleSoftware["file1"]})
require.NoError(t, err)

Expand All @@ -327,6 +338,7 @@ func testSetSetupExperienceTitles(t *testing.T, ds *Datastore) {
require.Len(t, titles, 0)
require.Equal(t, 0, count)

// Assign one vpp and one installer app
err = ds.SetSetupExperienceSoftwareTitles(ctx, team1.ID, []uint{titleVPP["1"], titleSoftware["file1"]})
require.NoError(t, err)

Expand All @@ -336,11 +348,30 @@ func testSetSetupExperienceTitles(t *testing.T, ds *Datastore) {
assert.Equal(t, 2, count)
assert.NotNil(t, meta)

// iOS app
// iOS software
err = ds.SetSetupExperienceSoftwareTitles(ctx, team2.ID, []uint{titleSoftware["file4"]})
require.Error(t, err)
require.ErrorContains(t, err, "unsupported")

// iOS app
// ios vpp app
err = ds.SetSetupExperienceSoftwareTitles(ctx, team1.ID, []uint{titleVPP["2"]})
require.ErrorContains(t, err, "unsupported")

// wrong team
err = ds.SetSetupExperienceSoftwareTitles(ctx, team1.ID, []uint{titleVPP["3"]})
require.Error(t, err)
require.ErrorContains(t, err, "not available")

// good other team assignment
err = ds.SetSetupExperienceSoftwareTitles(ctx, team2.ID, []uint{titleVPP["3"]})
require.NoError(t, err)

// non-existent title ID
err = ds.SetSetupExperienceSoftwareTitles(ctx, team1.ID, []uint{999})
require.ErrorContains(t, err, "not available")

// Failures and other team assignments didn't affected the number of apps on team 1
titles, count, meta, err = ds.ListSetupExperienceSoftwareTitles(ctx, team1.ID, fleet.ListOptions{})
require.NoError(t, err)
assert.Len(t, titles, 2)
assert.Equal(t, 2, count)
assert.NotNil(t, meta)
}

0 comments on commit 7476ff4

Please sign in to comment.