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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user