Files
calculate_negative_points/internal/test/test_helper.go
Eugene Howe b0957bfa49
Some checks failed
Docker Build and Publish / publish (push) Failing after 1m33s
webapp
2026-02-17 09:47:30 -05:00

54 lines
1.4 KiB
Go

package test
import (
"encoding/json"
"net/http/httptest"
"os"
"path/filepath"
"runtime"
"clintonambulance.com/calculate_negative_points/internal/config"
"github.com/gorilla/sessions"
"github.com/onsi/ginkgo/v2"
)
func CreateTestConfig() *config.ApplicationConfig {
appSecret := "12345678901234567890123456789012"
appSecretBlock := "09876543210987654321098765431098"
basepath := os.Getenv("APP_MIGRATION_DIRECTORY")
if basepath == "" {
_, b, _, _ := runtime.Caller(0)
basepath = filepath.Dir(b)
}
return &config.ApplicationConfig{
AppSecret: config.SecretFromValue(appSecret),
AppSecretBlock: config.SecretFromValue(appSecretBlock),
CookieStore: sessions.NewCookieStore([]byte(appSecret)),
Environment: "test",
Listen: "127.0.0.1:3000",
MatchThreshold: 3,
SessionName: "calculate-negative-points-test",
NocoDBConfig: config.NocoDBConfig{
ApiToken: config.SecretFromValue("1234567890"),
BaseUrl: "https://example.com",
EmployeesTableId: "0987654321",
InfractionsTableId: "2468013579",
NegativeInfractionId: 1,
NoPointsViewId: "1357924680",
},
}
}
func UnmarshalBody[K comparable, V any](rec *httptest.ResponseRecorder) map[K]V {
var body map[K]V
err := json.NewDecoder(rec.Body).Decode(&body)
if err != nil {
ginkgo.Fail("Could not decode response")
}
return body
}