Add crussell_test database creation and schema seeding to dev script

- Create crussell_test database after PostgreSQL reset
- Seed test DB schema from init-script.sql so tests can run
- This fixes the TLS connection errors in test runs

Also:
- Fixed color variables in script (C_RESET, C_GREEN, etc.)
This commit is contained in:
2026-02-22 00:06:03 +00:00
parent 44cac94f64
commit 9ca102153b
4 changed files with 28 additions and 7 deletions
@@ -23,6 +23,9 @@ func setupTestDB(t *testing.T) func() {
pool := testdb.Pool(t)
testdb.Migrate(t, pool)
// Truncate tables to ensure clean state
testdb.TruncateTables(t, pool)
originalDB := db.DB
db.DB = pool
@@ -85,7 +85,7 @@ func makeRequest(handler http.HandlerFunc, method, path string, body interface{}
return w
}
func makeAuthRequest(handler http.HandlerFunc, method, path, token string, body interface{}) *httptest.ResponseRecorder {
func makeAuthRequest(handler http.Handler, method, path, token string, body interface{}) *httptest.ResponseRecorder {
var req *http.Request
if body != nil {
bodyBytes, _ := json.Marshal(body)
@@ -197,7 +197,6 @@ func TestScheduling_UpdateDefaultHours_NonAdmin(t *testing.T) {
defer cleanup()
userToken := jwt.GenerateUserToken("user-123")
handler := http.HandlerFunc(UpdateDefaultHours)
newHours := []DefaultHours{
{Weekday: 0, StartTime: "08:00", EndTime: "18:00", IsOpen: true},
@@ -210,7 +209,7 @@ func TestScheduling_UpdateDefaultHours_NonAdmin(t *testing.T) {
}
// Wrap handler with RequireAdmin middleware
w := makeAuthRequest(mw.RequireAdmin(UpdateDefaultHours), "PUT", "/api/scheduling/default-hours", userToken, newHours)
w := makeAuthRequest(mw.RequireAdmin(http.HandlerFunc(UpdateDefaultHours)), "PUT", "/api/scheduling/default-hours", userToken, newHours)
if w.Code != http.StatusForbidden {
t.Errorf("expected status 403, got %d. body: %s", w.Code, w.Body.String())
@@ -318,7 +317,7 @@ func TestScheduling_CreateExceptionalGroup_NonAdmin(t *testing.T) {
WeekStarts: []string{"2026-06-01"},
}
w := makeAuthRequest(mw.RequireAdmin(CreateExceptionalGroup), "POST", "/api/scheduling/exceptional-groups", userToken, newGroup)
w := makeAuthRequest(mw.RequireAdmin(http.HandlerFunc(CreateExceptionalGroup)), "POST", "/api/scheduling/exceptional-groups", userToken, newGroup)
if w.Code != http.StatusForbidden {
t.Errorf("expected status 403, got %d. body: %s", w.Code, w.Body.String())
@@ -378,7 +377,7 @@ func TestScheduling_DeleteExceptionalGroup_NonAdmin(t *testing.T) {
userToken := jwt.GenerateUserToken("user-123")
handler := mw.RequireAdmin(DeleteExceptionalGroup)
handler := mw.RequireAdmin(http.HandlerFunc(DeleteExceptionalGroup))
req := httptest.NewRequest("DELETE", "/api/scheduling/exceptional-groups?id=1", nil)
req.Header.Set("Authorization", "Bearer "+userToken)
w := httptest.NewRecorder()
@@ -507,7 +506,7 @@ func TestScheduling_UpdateExceptionalApplications_NonAdmin(t *testing.T) {
defer cleanup()
userToken := jwt.GenerateUserToken("user-123")
handler := mw.RequireAdmin(UpdateExceptionalApplications)
handler := mw.RequireAdmin(http.HandlerFunc(UpdateExceptionalApplications))
reqBody := map[string]interface{}{
"groupId": 1,
+2
View File
@@ -132,6 +132,8 @@ func TruncateTables(t *testing.T, pool *pgxpool.Pool) {
"exceptional_working_hours",
"exceptional_working_hours_groups",
"users",
"images",
"tags",
}
for _, table := range tables {