This commit is contained in:
Ravi Prasad
2025-05-01 01:29:17 -05:00
parent 00519f0420
commit 09d81c251a
3 changed files with 62 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
package main
import (
"io"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/gofiber/fiber/v2"
"github.com/nprasad2077/NBA_Go/routes"
"github.com/nprasad2077/NBA_Go/config"
)
func setupTestApp() *fiber.App {
app := fiber.New()
db := config.InitDB() // uses SQLite file; can be mocked or in-memory for advanced testing
routes.RegisterPlayerAdvancedRoutes(app, db)
return app
}
func TestGetPlayerAdvancedStats(t *testing.T) {
app := setupTestApp()
tests := []struct {
description string
route string
expectedCode int
expectInBody string
}{
{
description: "valid route",
route: "/api/playeradvancedstats",
expectedCode: 200,
expectInBody: `"data"`, // assuming a JSON object with "data"
},
{
description: "invalid route",
route: "/api/invalid",
expectedCode: 404,
expectInBody: "Cannot GET /api/invalid",
},
}
for _, tc := range tests {
req, _ := http.NewRequest("GET", tc.route, nil)
resp, err := app.Test(req, -1)
assert.Nil(t, err, tc.description)
assert.Equal(t, tc.expectedCode, resp.StatusCode, tc.description)
body, _ := io.ReadAll(resp.Body)
assert.Contains(t, string(body), tc.expectInBody, tc.description)
}
}