fix(tests): parse RespondSuccess envelope in GetUploadStats test
This commit is contained in:
parent
d23fc1be2a
commit
cfffedce92
2 changed files with 18 additions and 4 deletions
|
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
|
@ -301,6 +302,10 @@ func TestGetUploadStats_Success(t *testing.T) {
|
|||
assert.Equal(t, http.StatusOK, w.Code)
|
||||
|
||||
var resp map[string]interface{}
|
||||
json.Unmarshal(w.Body.Bytes(), &resp)
|
||||
assert.Equal(t, float64(5), resp["stats"].(map[string]interface{})["total_uploads"])
|
||||
require.NoError(t, json.Unmarshal(w.Body.Bytes(), &resp))
|
||||
data, ok := resp["data"].(map[string]interface{})
|
||||
require.True(t, ok, "response should have data field")
|
||||
stats, statsOk := data["stats"].(map[string]interface{})
|
||||
require.True(t, statsOk, "data should have stats field")
|
||||
assert.Equal(t, float64(5), stats["total_uploads"])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,15 @@ import (
|
|||
"veza-backend-api/internal/models"
|
||||
)
|
||||
|
||||
// buildSearchClause returns the SQL fragment for case-insensitive search.
|
||||
// SQLite: LIKE (case-insensitive for ASCII), PostgreSQL: ILIKE
|
||||
func (s *UserService) buildSearchClause() string {
|
||||
if s.db != nil && s.db.Dialector.Name() == "sqlite" {
|
||||
return "username LIKE ? OR email LIKE ? OR first_name LIKE ? OR last_name LIKE ?"
|
||||
}
|
||||
return "username ILIKE ? OR email ILIKE ? OR first_name ILIKE ? OR last_name ILIKE ?"
|
||||
}
|
||||
|
||||
// SearchUsersParams représente les paramètres de recherche d'utilisateurs
|
||||
// BE-API-008: Implement user search endpoint
|
||||
type SearchUsersParams struct {
|
||||
|
|
@ -43,7 +52,7 @@ func (s *UserService) SearchUsers(ctx context.Context, params SearchUsersParams)
|
|||
if params.Query != "" {
|
||||
searchPattern := "%" + params.Query + "%"
|
||||
query = query.Where(
|
||||
"username ILIKE ? OR email ILIKE ? OR first_name ILIKE ? OR last_name ILIKE ?",
|
||||
s.buildSearchClause(),
|
||||
searchPattern, searchPattern, searchPattern, searchPattern,
|
||||
)
|
||||
}
|
||||
|
|
@ -118,7 +127,7 @@ func (s *UserService) ListUsers(ctx context.Context, params ListUsersParams) ([]
|
|||
if params.Search != "" {
|
||||
searchPattern := "%" + params.Search + "%"
|
||||
query = query.Where(
|
||||
"username ILIKE ? OR email ILIKE ? OR first_name ILIKE ? OR last_name ILIKE ?",
|
||||
s.buildSearchClause(),
|
||||
searchPattern, searchPattern, searchPattern, searchPattern,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue