mirror of
https://github.com/hanzoai/team.git
synced 2026-10-30 14:49:35 +00:00
* Simplify invite_people email parsing Replace backwards in-place mutation loop with a straightforward forward filter into a new slice. Extract into parseEmailList so the logic can be unit tested directly. * MM-68150: Upgrade golangci-lint to v2.12.2 Remove //go:fix inline from NewPointer, which is a generic function not yet supported by the inline analyzer, and fix 11 slicesbackward modernize issues flagged by the new version. * MM-68150: Enable all linters by default; disable those with >20 existing issues Switch from opt-in (default: none) to opt-out (default: all) so new linters added to golangci-lint are evaluated automatically. Explicitly disable every linter that has more than 20 pre-existing violations, deferring those for later cleanup. Also disable a handful of linters whose violations are intentional patterns in this codebase (nilerr, dogsled, sqlclosecheck, iotamixing, predeclared, containedctx, iface, gocheckcompilerdirectives, promlinter, goprintffuncname, gomoddirectives). * MM-68150: Fix mirror linter issues Replace Write([]byte(s)) with WriteString(s), and FindIndex([]byte(s)) with FindStringIndex(s), to avoid unnecessary allocations. * MM-68150: Fix nosprintfhostport linter issue Use net.JoinHostPort to construct host:port strings instead of fmt.Sprintf with a manually formatted pattern. * MM-68150: Fix rowserrcheck and sqlclosecheck linter issues Check rows.Err() after iteration loops in schema_dump.go. In the sqlx_wrapper test, defer rows.Close() rather than closing inline. * MM-68150: Fix nilnesserr linter issues — wrong variable in error handlers In 11 places, a stale variable (often the outer err from a prior assignment) was used instead of the freshly-checked error variable (appErr, rowErr, jsonErr, writeErr, esErr). Each produces a typed-nil wrapped in a non-nil interface, silently discarding the real error. * MM-68150: Add i18n string for app.compile_csv_chunks.write_error --------- Co-authored-by: Mattermost Build <[email protected]>
94 lines
2.4 KiB
Go
94 lines
2.4 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package slashcommands
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
)
|
|
|
|
func TestParseEmailList(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected []string
|
|
}{
|
|
{
|
|
name: "single valid email",
|
|
input: "[email protected]",
|
|
expected: []string{"[email protected]"},
|
|
},
|
|
{
|
|
name: "multiple valid emails",
|
|
input: "[email protected] [email protected]",
|
|
expected: []string{"[email protected]", "[email protected]"},
|
|
},
|
|
{
|
|
name: "trailing commas stripped",
|
|
input: "[email protected], [email protected],",
|
|
expected: []string{"[email protected]", "[email protected]"},
|
|
},
|
|
{
|
|
name: "non-email tokens filtered out",
|
|
input: "notanemail [email protected] alsoinvalid",
|
|
expected: []string{"[email protected]"},
|
|
},
|
|
{
|
|
name: "comma immediately after email treated as one token",
|
|
input: "[email protected],[email protected]",
|
|
expected: []string{"[email protected],[email protected]"},
|
|
},
|
|
{
|
|
name: "empty input",
|
|
input: "",
|
|
expected: nil,
|
|
},
|
|
{
|
|
name: "all tokens invalid",
|
|
input: "notanemail alsoinvalid",
|
|
expected: nil,
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
result := parseEmailList(tc.input)
|
|
require.Equal(t, tc.expected, result)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestInvitePeopleProvider(t *testing.T) {
|
|
th := setup(t).initBasic(t)
|
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
*cfg.EmailSettings.SendEmailNotifications = true
|
|
*cfg.ServiceSettings.EnableEmailInvitations = true
|
|
})
|
|
|
|
cmd := InvitePeopleProvider{}
|
|
|
|
notTeamUser := th.createUser(t)
|
|
|
|
// Test without required permissions
|
|
args := &model.CommandArgs{
|
|
T: func(s string, args ...any) string { return s },
|
|
ChannelId: th.BasicChannel.Id,
|
|
TeamId: th.BasicTeam.Id,
|
|
UserId: notTeamUser.Id,
|
|
}
|
|
|
|
actual := cmd.DoCommand(th.App, th.Context, args, model.NewId()+"@simulator.amazonses.com")
|
|
assert.Equal(t, "api.command_invite_people.permission.app_error", actual.Text)
|
|
|
|
// Test with required permissions.
|
|
args.UserId = th.BasicUser.Id
|
|
actual = cmd.DoCommand(th.App, th.Context, args, model.NewId()+"@simulator.amazonses.com")
|
|
assert.Equal(t, "api.command.invite_people.sent", actual.Text)
|
|
}
|