refactor(tests): Update all test files to use TestServerSetup pattern
This commit is contained in:
@@ -17,8 +17,7 @@ import (
|
||||
)
|
||||
|
||||
func TestListAllQueueItems_Admin(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginAdminUser(t, ts, db)
|
||||
|
||||
@@ -35,12 +34,11 @@ func TestListAllQueueItems_Admin(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetDeviceQueueStats(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginTestUser(t, ts, db)
|
||||
token := loginTestUser(t, setup.Server, setup.DB)
|
||||
|
||||
userID := getTestUserID(t, db)
|
||||
userID := getTestUserID(t, setup.DB)
|
||||
|
||||
deviceToken := fmt.Sprintf("dev_%s", uuid.New().String())
|
||||
device, err := db.CreateDevice(context.Background(), database.CreateDeviceParams{
|
||||
@@ -72,12 +70,11 @@ func TestGetDeviceQueueStats(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListDeviceQueueItems(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginTestUser(t, ts, db)
|
||||
token := loginTestUser(t, setup.Server, setup.DB)
|
||||
|
||||
userID := getTestUserID(t, db)
|
||||
userID := getTestUserID(t, setup.DB)
|
||||
|
||||
deviceToken := fmt.Sprintf("dev_%s", uuid.New().String())
|
||||
device, err := db.CreateDevice(context.Background(), database.CreateDeviceParams{
|
||||
@@ -109,10 +106,9 @@ func TestListDeviceQueueItems(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRetryQueueItem(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginTestUser(t, ts, db)
|
||||
token := loginTestUser(t, setup.Server, setup.DB)
|
||||
|
||||
itemID := uuid.New().String()
|
||||
|
||||
@@ -125,10 +121,9 @@ func TestRetryQueueItem(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteQueueItem(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginTestUser(t, ts, db)
|
||||
token := loginTestUser(t, setup.Server, setup.DB)
|
||||
|
||||
itemID := uuid.New().String()
|
||||
|
||||
@@ -141,12 +136,11 @@ func TestDeleteQueueItem(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClearDeviceQueue(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginTestUser(t, ts, db)
|
||||
token := loginTestUser(t, setup.Server, setup.DB)
|
||||
|
||||
userID := getTestUserID(t, db)
|
||||
userID := getTestUserID(t, setup.DB)
|
||||
|
||||
deviceToken := fmt.Sprintf("dev_%s", uuid.New().String())
|
||||
device, err := db.CreateDevice(context.Background(), database.CreateDeviceParams{
|
||||
@@ -174,8 +168,7 @@ func TestClearDeviceQueue(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestQueueEndpoints_Unauthorized(t *testing.T) {
|
||||
ts, _, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -230,7 +223,7 @@ func loginAdminUser(t *testing.T, ts *httptest.Server, db *database.Queries) str
|
||||
|
||||
_, err = db.ListUsers(context.Background())
|
||||
if err == nil {
|
||||
return loginTestUser(t, ts, db)
|
||||
return loginTestUser(t, setup.Server, setup.DB)
|
||||
}
|
||||
|
||||
loginRequest := map[string]interface{}{
|
||||
@@ -239,7 +232,7 @@ func loginAdminUser(t *testing.T, ts *httptest.Server, db *database.Queries) str
|
||||
}
|
||||
body, _ := json.Marshal(loginRequest)
|
||||
|
||||
req, _ := http.NewRequest("POST", ts.URL+"/api/auth/login", bytes.NewBuffer(body))
|
||||
req, _ := http.NewRequest("POST", setup.Server.URL+"/api/auth/login", bytes.NewBuffer(body))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{}
|
||||
@@ -262,7 +255,7 @@ func loginUserWithID(t *testing.T, ts *httptest.Server, db *database.Queries, us
|
||||
}
|
||||
body, _ := json.Marshal(loginRequest)
|
||||
|
||||
req, _ := http.NewRequest("POST", ts.URL+"/api/auth/login", bytes.NewBuffer(body))
|
||||
req, _ := http.NewRequest("POST", setup.Server.URL+"/api/auth/login", bytes.NewBuffer(body))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{}
|
||||
|
||||
Reference in New Issue
Block a user