fix(tests): Fix edge cases in test file migration
This commit is contained in:
@@ -29,7 +29,7 @@ func TestDeviceRegistrationFlow(t *testing.T) {
|
||||
req := httptest.NewRequest("POST", "/api/devices/register", bytes.NewReader(regBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
rec := httptest.NewRecorder()
|
||||
ts.Config.Handler.ServeHTTP(rec, req)
|
||||
setup.Server.Config.Handler.ServeHTTP(rec, req)
|
||||
|
||||
assert.Equal(t, http.StatusCreated, rec.Code, "Should initiate device registration")
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestDeviceRegistrationFlow(t *testing.T) {
|
||||
req = httptest.NewRequest("POST", "/api/devices/register/status", bytes.NewReader(statusBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
rec = httptest.NewRecorder()
|
||||
ts.Config.Handler.ServeHTTP(rec, req)
|
||||
setup.Server.Config.Handler.ServeHTTP(rec, req)
|
||||
|
||||
assert.Equal(t, http.StatusOK, rec.Code, "Should check registration status")
|
||||
|
||||
@@ -74,7 +74,7 @@ func TestDeviceRegistrationFlow(t *testing.T) {
|
||||
req = httptest.NewRequest("POST", "/api/auth/login", bytes.NewReader(loginBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
rec = httptest.NewRecorder()
|
||||
ts.Config.Handler.ServeHTTP(rec, req)
|
||||
setup.Server.Config.Handler.ServeHTTP(rec, req)
|
||||
|
||||
assert.Equal(t, http.StatusOK, rec.Code, "Should login successfully")
|
||||
|
||||
@@ -89,7 +89,7 @@ func TestDeviceRegistrationFlow(t *testing.T) {
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
rec = httptest.NewRecorder()
|
||||
ts.Config.Handler.ServeHTTP(rec, req)
|
||||
setup.Server.Config.Handler.ServeHTTP(rec, req)
|
||||
|
||||
assert.Equal(t, http.StatusOK, rec.Code, "Should approve device")
|
||||
|
||||
@@ -97,7 +97,7 @@ func TestDeviceRegistrationFlow(t *testing.T) {
|
||||
req = httptest.NewRequest("POST", "/api/devices/register/status", bytes.NewReader(statusBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
rec = httptest.NewRecorder()
|
||||
ts.Config.Handler.ServeHTTP(rec, req)
|
||||
setup.Server.Config.Handler.ServeHTTP(rec, req)
|
||||
|
||||
assert.Equal(t, http.StatusOK, rec.Code, "Should check registration status after approval")
|
||||
|
||||
@@ -203,7 +203,7 @@ func TestDeviceAuthentication(t *testing.T) {
|
||||
userID := getTestUserID(t, setup.DB)
|
||||
|
||||
deviceToken := fmt.Sprintf("dev_%s", uuid.New().String())
|
||||
_, err := db.CreateDevice(context.Background(), database.CreateDeviceParams{
|
||||
_, err := setup.DB.CreateDevice(context.Background(), database.CreateDeviceParams{
|
||||
UserID: pgtype.UUID{Bytes: [16]byte(userID), Valid: true},
|
||||
DeviceName: "Test Device",
|
||||
DeviceType: "koreader",
|
||||
@@ -220,7 +220,7 @@ func TestDeviceAuthentication(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/devices", nil)
|
||||
req.Header.Set("Authorization", "Bearer "+deviceToken)
|
||||
rec := httptest.NewRecorder()
|
||||
ts.Config.Handler.ServeHTTP(rec, req)
|
||||
setup.Server.Config.Handler.ServeHTTP(rec, req)
|
||||
|
||||
// This should fail because device auth middleware is not applied to /api/devices
|
||||
// Device auth is for sync endpoints only
|
||||
@@ -235,7 +235,7 @@ func TestListPendingRegistrations(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/devices/pending", nil)
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
rec := httptest.NewRecorder()
|
||||
ts.Config.Handler.ServeHTTP(rec, req)
|
||||
setup.Server.Config.Handler.ServeHTTP(rec, req)
|
||||
|
||||
assert.Equal(t, http.StatusOK, rec.Code, "Should list pending registrations")
|
||||
|
||||
@@ -262,7 +262,7 @@ func TestApproveDeviceRegistration(t *testing.T) {
|
||||
req := httptest.NewRequest("POST", "/api/devices/register", bytes.NewReader(regBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
rec := httptest.NewRecorder()
|
||||
ts.Config.Handler.ServeHTTP(rec, req)
|
||||
setup.Server.Config.Handler.ServeHTTP(rec, req)
|
||||
|
||||
assert.Equal(t, http.StatusCreated, rec.Code, "Should initiate device registration")
|
||||
|
||||
@@ -275,7 +275,7 @@ func TestApproveDeviceRegistration(t *testing.T) {
|
||||
req = httptest.NewRequest("GET", fmt.Sprintf("/api/devices/approve/%s", registrationID), nil)
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
rec = httptest.NewRecorder()
|
||||
ts.Config.Handler.ServeHTTP(rec, req)
|
||||
setup.Server.Config.Handler.ServeHTTP(rec, req)
|
||||
|
||||
assert.Equal(t, http.StatusOK, rec.Code, "Should approve device registration")
|
||||
|
||||
@@ -300,7 +300,7 @@ func TestRejectDeviceRegistration(t *testing.T) {
|
||||
req := httptest.NewRequest("POST", "/api/devices/register", bytes.NewReader(regBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
rec := httptest.NewRecorder()
|
||||
ts.Config.Handler.ServeHTTP(rec, req)
|
||||
setup.Server.Config.Handler.ServeHTTP(rec, req)
|
||||
|
||||
assert.Equal(t, http.StatusCreated, rec.Code, "Should initiate device registration")
|
||||
|
||||
@@ -313,7 +313,7 @@ func TestRejectDeviceRegistration(t *testing.T) {
|
||||
req = httptest.NewRequest("POST", fmt.Sprintf("/api/devices/reject/%s", registrationID), nil)
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
rec = httptest.NewRecorder()
|
||||
ts.Config.Handler.ServeHTTP(rec, req)
|
||||
setup.Server.Config.Handler.ServeHTTP(rec, req)
|
||||
|
||||
assert.Equal(t, http.StatusOK, rec.Code, "Should reject device registration")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user