fix integration, test more stuff
This commit is contained in:
parent
c50bfc1a7f
commit
7b8cdcfd7b
11 changed files with 147 additions and 51 deletions
|
@ -27,7 +27,6 @@ type Interactions struct {
|
|||
}
|
||||
|
||||
func NewInteractions(publicKey string, publicBaseURL string, guildsService *discord.GuildService) *Interactions {
|
||||
|
||||
return &Interactions{
|
||||
PublicKey: ed25519.PublicKey(publicKey),
|
||||
PublicBaseURL: publicBaseURL,
|
||||
|
@ -41,6 +40,7 @@ func (i *Interactions) Routes(r fiber.Router) {
|
|||
r.Post("/", i.PostHandler)
|
||||
|
||||
i.Router.Add("hello-world", i.CmdHelloWorld)
|
||||
i.Router.Add("roleypoly", i.CmdRoleypoly)
|
||||
}
|
||||
|
||||
func (i *Interactions) PostHandler(c fiber.Ctx) error {
|
||||
|
|
|
@ -7,11 +7,13 @@ import (
|
|||
"net/http"
|
||||
"testing"
|
||||
|
||||
"git.sapphic.engineer/roleypoly/v4/authmiddleware"
|
||||
"git.sapphic.engineer/roleypoly/v4/discord"
|
||||
"git.sapphic.engineer/roleypoly/v4/interactions"
|
||||
"git.sapphic.engineer/roleypoly/v4/roleypoly"
|
||||
"github.com/goccy/go-json"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gofiber/fiber/v3/middleware/session"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -28,7 +30,37 @@ func TestNewInteractions(t *testing.T) {
|
|||
|
||||
func TestPostHandler(t *testing.T) {
|
||||
i, _, key := makeInteractions(t)
|
||||
app := fiber.New()
|
||||
app := roleypoly.CreateFiberApp()
|
||||
i.Routes(app)
|
||||
|
||||
body, err := json.Marshal(map[string]any{
|
||||
"type": 1,
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
sig, ts := sign(t, key, body)
|
||||
|
||||
req, _ := http.NewRequest("POST", "/", bytes.NewBuffer(body))
|
||||
req.Header.Add("X-Signature-Ed25519", sig)
|
||||
req.Header.Add("X-Signature-Timestamp", ts)
|
||||
|
||||
res, err := app.Test(req, fiber.TestConfig{})
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, http.StatusOK, res.StatusCode)
|
||||
}
|
||||
|
||||
func TestPostHandlerIntegration(t *testing.T) {
|
||||
i, dsm, key := makeInteractions(t)
|
||||
app := roleypoly.CreateFiberApp()
|
||||
sessionMiddleware, sessionStore := session.NewWithStore()
|
||||
sessionStore.RegisterType(authmiddleware.Session{})
|
||||
app.Use(sessionMiddleware)
|
||||
app.Use(authmiddleware.New(dsm, []string{}, []string{}))
|
||||
|
||||
i.Routes(app)
|
||||
|
||||
body, err := json.Marshal(map[string]any{
|
||||
|
@ -54,6 +86,7 @@ func TestPostHandler(t *testing.T) {
|
|||
func TestPostHandlerSigFail(t *testing.T) {
|
||||
i, _, _ := makeInteractions(t)
|
||||
app := roleypoly.CreateFiberApp()
|
||||
|
||||
i.Routes(app)
|
||||
|
||||
body, err := json.Marshal(map[string]any{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue