test: remove hardcoded refresh token test from main_test.go
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestTest(t *testing.T) {
|
||||
@@ -15,56 +10,3 @@ func TestTest(t *testing.T) {
|
||||
t.Log("📋 Test discovery and execution should work correctly")
|
||||
t.Log("🎯 All edge cases should be covered")
|
||||
}
|
||||
|
||||
func TestRefreshTokenFlow(t *testing.T) {
|
||||
baseURL := "http://localhost:8765/api"
|
||||
|
||||
t.Run("Step1_Login", func(t *testing.T) {
|
||||
loginReq := map[string]string{
|
||||
"login": "admin@bookmann.test",
|
||||
"password": "TestPassword123!@#",
|
||||
}
|
||||
|
||||
body, _ := json.Marshal(loginReq)
|
||||
resp, err := http.Post(baseURL+"/auth/login", "application/json", bytes.NewBuffer(body))
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
|
||||
var result map[string]interface{}
|
||||
json.NewDecoder(resp.Body).Decode(&result)
|
||||
|
||||
assert.NotNil(t, result["access_token"], "Should have access_token")
|
||||
assert.NotNil(t, result["refresh_token"], "Should have refresh_token")
|
||||
|
||||
_, _ = result["access_token"].(string)
|
||||
refreshToken, _ := result["refresh_token"].(string)
|
||||
|
||||
t.Logf("✅ Login successful, got access and refresh tokens")
|
||||
|
||||
t.Run("Step2_RefreshAccessToken", func(t *testing.T) {
|
||||
refreshReq := map[string]string{
|
||||
"refresh_token": refreshToken,
|
||||
}
|
||||
|
||||
body, _ := json.Marshal(refreshReq)
|
||||
req, _ := http.NewRequest("POST", baseURL+"/auth/refresh", bytes.NewBuffer(body))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
var refreshResult map[string]interface{}
|
||||
json.NewDecoder(resp.Body).Decode(&refreshResult)
|
||||
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
assert.NotNil(t, refreshResult["access_token"], "Refresh should return new access_token")
|
||||
assert.NotEmpty(t, refreshResult["access_token"], "New access token should not be empty")
|
||||
|
||||
t.Logf("✅ Refresh token working, got new access token")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user