54 lines
1.4 KiB
Go
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
|
|
}
|