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:
@@ -27,7 +27,7 @@ func (s *DashboardIntegrationTestSuite) TearDownSuite() {
|
||||
}
|
||||
|
||||
func (s *DashboardIntegrationTestSuite) TestGetSections_EndToEndFlow() {
|
||||
token := loginTestUser(s.T(), s.setup.Server, s.setup.DB)
|
||||
token := s.setup.Token
|
||||
|
||||
// Create test library
|
||||
libraryID := createTestLibraryWithFolder(s.T(), s.setup.Server, token, "Test Library", false)
|
||||
@@ -79,7 +79,7 @@ func (s *DashboardIntegrationTestSuite) TestGetSections_EndToEndFlow() {
|
||||
}
|
||||
|
||||
func (s *DashboardIntegrationTestSuite) TestGetSections_MissingLibraryID() {
|
||||
token := loginTestUser(s.T(), s.setup.Server, s.setup.DB)
|
||||
token := s.setup.Token
|
||||
|
||||
req, _ := http.NewRequest("GET", s.setup.Server.URL+"/api/dashboard/sections", nil)
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
@@ -93,7 +93,7 @@ func (s *DashboardIntegrationTestSuite) TestGetSections_MissingLibraryID() {
|
||||
}
|
||||
|
||||
func (s *DashboardIntegrationTestSuite) TestGetSections_InvalidLibraryID() {
|
||||
token := loginTestUser(s.T(), s.setup.Server, s.setup.DB)
|
||||
token := s.setup.Token
|
||||
|
||||
req, _ := http.NewRequest("GET", s.setup.Server.URL+"/api/dashboard/sections?library_id=invalid-uuid", nil)
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
@@ -118,7 +118,7 @@ func (s *DashboardIntegrationTestSuite) TestGetSections_Unauthorized() {
|
||||
}
|
||||
|
||||
func (s *DashboardIntegrationTestSuite) TestUpdatePreferences_Success() {
|
||||
token := loginTestUser(s.T(), s.setup.Server, s.setup.DB)
|
||||
token := s.setup.Token
|
||||
libraryID := createTestLibraryWithFolder(s.T(), s.setup.Server, token, "Test Library", false)
|
||||
|
||||
reqBody := map[string]interface{}{
|
||||
@@ -170,7 +170,7 @@ func (s *DashboardIntegrationTestSuite) TestUpdatePreferences_Unauthorized() {
|
||||
}
|
||||
|
||||
func (s *DashboardIntegrationTestSuite) TestRestoreSystemCollection_InvalidName() {
|
||||
token := loginTestUser(s.T(), s.setup.Server, s.setup.DB)
|
||||
token := s.setup.Token
|
||||
|
||||
reqBody := map[string]interface{}{
|
||||
"collection_name": "invalid-collection-name",
|
||||
@@ -207,7 +207,7 @@ func (s *DashboardIntegrationTestSuite) TestRestoreSystemCollection_Unauthorized
|
||||
}
|
||||
|
||||
func (s *DashboardIntegrationTestSuite) TestRestoreSystemCollection_ValidNames() {
|
||||
token := loginTestUser(s.T(), s.setup.Server, s.setup.DB)
|
||||
token := s.setup.Token
|
||||
|
||||
validCollections := []string{"continue-reading", "recently-added", "recently-read", "not-started"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user