fleet/server/datastore/mysql/errors_test.go
Scott Gress 2747c96308
Fix software installer error team -> fleet (#41070)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** For #41031

# Details

* Updates server-side error message about software installers to use
"fleet" instead of "team".
* Update front-end code that rewrites that error text 🤦  

# Checklist for submitter

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

- [ ] 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.
n/a

## Testing

- [X] Added/updated automated tests
- [X] QA'd all new/changed functionality manually
- [X] Saw correct error banner when trying to add a VPP app that
conflicted with an FMA
<img width="741" height="67" alt="image"
src="https://github.com/user-attachments/assets/d171097c-b165-45f8-bafb-fd6337c94cb9"
/>
- [X] Saw correct error banner when trying to add a script with the same
contents as a another script
<img width="765" height="60" alt="image"
src="https://github.com/user-attachments/assets/db02b92a-942d-448d-9062-3fca49132a94"
/>

I haven't tested all the other cases but I think these two cover them;
one uses the `CantAddSoftwareConflictMessage` constant on the server and
one uses a hard-coded message. Everything else uses the constant.

For unreleased bug fixes in a release candidate, one of:

- [X] Confirmed that the fix is not expected to adversely impact load
test results
2026-03-05 17:28:52 -06:00

44 lines
1,022 B
Go

package mysql
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestAlreadyExistsError(t *testing.T) {
cases := []struct {
name string
fn func(t *testing.T)
}{{
name: "WithTeamID",
fn: func(t *testing.T) {
err := alreadyExists("User", "alice").WithTeamID(42)
expectedMsg := `User "alice" already exists with FleetID 42.`
require.Equal(t, expectedMsg, err.Error())
},
}, {
name: "WithTeamName",
fn: func(t *testing.T) {
err := alreadyExists("User", "alice").WithTeamName("Falcon Team")
expectedMsg := `User "alice" already exists with fleet "Falcon Team".`
require.Equal(t, expectedMsg, err.Error())
},
}, {
name: "IsError",
fn: func(t *testing.T) {
err := alreadyExists("User", "alice")
require.True(t, err.IsExists())
expectedMsg := `User "alice" already exists`
require.Equal(t, expectedMsg, err.Error())
require.Equal(t, err.Resource(), "User")
},
}}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
c.fn(t)
})
}
}