Files
bookhoard/cmd/server/tests/main_test.go
T
john-okeefe 9b41b3ecb0 Add refresh token flow integration test
- Test login returns both access_token and refresh_token
- Test refresh endpoint accepts UUID token and returns new access_token
- Verifies end-to-end refresh token flow works correctly
2026-01-31 11:44:47 -05:00

71 lines
2.0 KiB
Go

package main
import (
"bytes"
"encoding/json"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestTest(t *testing.T) {
t.Log("🧪 Comprehensive test suite verification")
t.Log("✅ Testing framework is properly configured")
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")
})
})
}