test: improve test isolation and setup management

Add Token and RegularToken fields to TestServerSetup for pre-authenticated
access. Update setupTestServer to create fresh users with valid tokens at
initialization time. Simplify createTestMediaItemID to use setup.Token.
Remove loginTestUser, loginRegularUser, loginAdminUser functions in favor
of setup.Token/setup.RegularToken. Update createTestUserOnce and
getTestUserID/getRegularUserID to be idempotent. Update all test files to
use setup.Token instead of calling login helpers.
This commit is contained in:
2026-02-22 01:57:22 -05:00
parent 9a09161f24
commit f54508e4dd
16 changed files with 819 additions and 793 deletions
+2 -2
View File
@@ -76,7 +76,7 @@ func TestPreviewCollection(t *testing.T) {
assert.Equal(t, http.StatusBadRequest, rec.Code)
})
t.Run("NonExistentLibrary_ReturnsInternalServerError", func(t *testing.T) {
t.Run("NonExistentLibrary_ReturnsBadRequest", func(t *testing.T) {
reqBody := map[string]interface{}{
"library_id": uuid.New().String(),
"rules": []map[string]interface{}{},
@@ -91,7 +91,7 @@ func TestPreviewCollection(t *testing.T) {
rec := httptest.NewRecorder()
setup.Server.Config.Handler.ServeHTTP(rec, req)
assert.Equal(t, http.StatusInternalServerError, rec.Code)
assert.Equal(t, http.StatusBadRequest, rec.Code)
})
t.Run("EmptyRules_ReturnsEmptyItems", func(t *testing.T) {