v4/interactions/cmd_roleypoly_test.go
2025-03-26 16:36:00 -07:00

66 lines
1.7 KiB
Go

package interactions_test
import (
"fmt"
"testing"
"git.sapphic.engineer/roleypoly/v4/interactions"
"github.com/stretchr/testify/assert"
)
func TestCmdRoleypoly(t *testing.T) {
i, dcm, _ := makeInteractions(t)
ix := mkInteraction("roleypoly")
commands := []interactions.InteractionCommand{
{ID: "1", Name: "pick-role"},
{ID: "2", Name: "pickable-roles"},
{ID: "3", Name: "remove-role"},
}
dcm.MockResponse("GET", "/applications/*/commands", 200, commands)
ir, err := i.CmdRoleypoly(ix)
assert.Nil(t, err)
embed := ir.Data.Embeds[0]
// test that the button is cool
button := ir.Data.Components[0]
assert.Equal(t, fmt.Sprintf("%s/s/guild-id", i.PublicBaseURL), button.URL)
// test the command mentions
tests := map[string]string{
"See all the roles": "</2:pickable-roles>",
"Pick a role": "</1:pick-role>",
"Remove a role": "</3:remove-role>",
}
for _, field := range embed.Fields {
assert.Equal(t, tests[field.Name], field.Value)
}
// test weird name cases
// not weird
ix.Member.Nick = "Doll"
ix.Member.User.GlobalName = "Dolly"
ix.Member.User.Username = "41666."
ir, err = i.CmdRoleypoly(ix)
assert.Nil(t, err)
assert.Equal(t, ":beginner: Hey there, Doll", ir.Data.Embeds[0].Title)
// no nick
ix.Member.Nick = ""
ix.Member.User.GlobalName = "Dolly"
ix.Member.User.Username = "41666."
ir, err = i.CmdRoleypoly(ix)
assert.Nil(t, err)
assert.Equal(t, ":beginner: Hey there, Dolly", ir.Data.Embeds[0].Title)
// no globalname
ix.Member.Nick = ""
ix.Member.User.GlobalName = ""
ix.Member.User.Username = "41666."
ir, err = i.CmdRoleypoly(ix)
assert.Nil(t, err)
assert.Equal(t, ":beginner: Hey there, 41666.", ir.Data.Embeds[0].Title)
}