irl testing pass

This commit is contained in:
41666 2025-03-26 14:03:50 -07:00
parent dfbb9e2bca
commit 02f5075d3b
5 changed files with 21 additions and 8 deletions

View file

@ -13,14 +13,14 @@ import (
type Interactions struct {
PublicKey ed25519.PublicKey
Guilds discord.IGuildService
Guilds *discord.GuildService
Router *InteractionRouter
// if interactions are able to be used
OK bool
}
func NewInteractions(publicKey string, guildsService discord.IGuildService) *Interactions {
func NewInteractions(publicKey string, guildsService *discord.GuildService) *Interactions {
return &Interactions{
PublicKey: ed25519.PublicKey(publicKey),
Guilds: guildsService,

View file

@ -19,9 +19,9 @@ func TestNewInteractions(t *testing.T) {
pub, _, _ := ed25519.GenerateKey(nil)
key := hex.EncodeToString(pub)
gsm := &discord.GuildServiceMock{}
gs := &discord.GuildService{}
i := interactions.NewInteractions(key, gsm)
i := interactions.NewInteractions(key, gs)
assert.True(t, i.OK, "interactions OK")
assert.Equal(t, string(i.PublicKey), key, "public key accepted from args")
}

View file

@ -16,13 +16,13 @@ import (
"github.com/stretchr/testify/assert"
)
func makeInteractions(t *testing.T) (*interactions.Interactions, *discord.GuildServiceMock, ed25519.PrivateKey) {
func makeInteractions(t *testing.T) (*interactions.Interactions, *discord.GuildService, ed25519.PrivateKey) {
pub, priv, err := ed25519.GenerateKey(nil)
if err != nil {
t.Errorf("makeInteractions: failed to generate key: %v", err)
}
gs := &discord.GuildServiceMock{}
gs := &discord.GuildService{}
i := &interactions.Interactions{
PublicKey: pub,

View file

@ -29,7 +29,7 @@ func CreateFiberApp() *fiber.App {
return app
}
func SetupControllers(app *fiber.App, dc discord.IDiscordClient, publicKey string) {
func SetupControllers(app *fiber.App, dc *discord.DiscordClient, publicKey string) {
gs := discord.NewGuildService(dc)
(&testing.TestingController{

View file

@ -16,6 +16,7 @@ type TestingController struct {
func (t *TestingController) Routes(r fiber.Router) {
r.Get("/picker/:version?", t.Picker)
r.Get("/m/:server/:user", t.GetMember)
r.Get("/g/:server", t.GetGuild)
}
func (t *TestingController) Picker(c fiber.Ctx) error {
@ -39,5 +40,17 @@ func (t *TestingController) GetMember(c fiber.Ctx) error {
types.NewAPIError(500, err.Error()).Send(c)
}
return c.JSON(m)
return c.JSON(m.DiscordMember)
}
func (t *TestingController) GetGuild(c fiber.Ctx) error {
serverID := c.Params("server")
g, err := t.Guilds.GetGuild(serverID)
if err != nil {
log.Println("testing/get guild: ", err)
types.NewAPIError(500, err.Error()).Send(c)
}
return c.JSON(g.DiscordGuild)
}