41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package handlers
|
|
|
|
import (
|
|
"Rezina-Backend/internal/domain"
|
|
"github.com/gofiber/fiber/v2"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestAffiliateAdminOperationsRejectNonAdmins(t *testing.T) {
|
|
for _, role := range []domain.Role{domain.RoleStudent, domain.RoleOpenLearner, domain.RoleSupport, domain.RoleContentManager} {
|
|
h := &Handler{}
|
|
for _, handler := range []fiber.Handler{h.ListAffiliates, h.ReviewAffiliate, h.UpdateAffiliateSettings, h.ListAffiliatePayouts, h.ReviewAffiliatePayout, h.ReverseAffiliateCommission, h.GetAffiliateEvents} {
|
|
app := fiber.New()
|
|
app.Post("/", func(c *fiber.Ctx) error { c.Locals("user_id", int64(42)); c.Locals("role", role); return c.Next() }, handler)
|
|
r, err := app.Test(httptest.NewRequest("POST", "/", nil))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
r.Body.Close()
|
|
if r.StatusCode != 403 {
|
|
t.Fatalf("role=%s status=%d", role, r.StatusCode)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
func TestAffiliateUserFilterCannotSelectAllWithZero(t *testing.T) {
|
|
for _, query := range []string{"0", "-1", "bad", "9223372036854775808"} {
|
|
app := fiber.New()
|
|
app.Get("/", func(c *fiber.Ctx) error { _, err := affiliateFilter(c); return err })
|
|
r, err := app.Test(httptest.NewRequest("GET", "/?user_id="+query, nil))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
r.Body.Close()
|
|
if r.StatusCode != 400 {
|
|
t.Fatalf("accepted %s", query)
|
|
}
|
|
}
|
|
}
|