Put the user's role and branch on GET /profile, upsert role_user and branch_user on POST, and drop their list endpoints.
Also accept flexible card-order form values, move mock seed under db/mock, and regenerate Swagger. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
7225dc0399
commit
8795ae2195
47 files changed
+1308
-1785
No files matched your search
@@ -0,0 +1,96 @@
|
||||
package activitylog
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"online-back/pkg/logging"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type stubRepository struct {
|
||||
mu sync.Mutex
|
||||
listFilter ListFilter
|
||||
listResult ListActivityLogDTO
|
||||
created []CreateActivityLogDTO
|
||||
}
|
||||
|
||||
func (s *stubRepository) List(_ context.Context, filter ListFilter) (ListActivityLogDTO, error) {
|
||||
s.listFilter = filter
|
||||
return s.listResult, nil
|
||||
}
|
||||
|
||||
func (s *stubRepository) GetByID(_ context.Context, _ int64) (ActivityLogDTO, error) {
|
||||
return ActivityLogDTO{}, nil
|
||||
}
|
||||
|
||||
func (s *stubRepository) Create(_ context.Context, dto CreateActivityLogDTO) (ActivityLogDTO, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.created = append(s.created, dto)
|
||||
return ActivityLogDTO{Id: 1}, nil
|
||||
}
|
||||
|
||||
func (s *stubRepository) createdEntries() []CreateActivityLogDTO {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
out := make([]CreateActivityLogDTO, len(s.created))
|
||||
copy(out, s.created)
|
||||
return out
|
||||
}
|
||||
|
||||
func TestParseListFilterIgnoresUndefinedAndCapsLimit(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
c, _ := gin.CreateTestContext(w)
|
||||
req := httptest.NewRequest(http.MethodGet, "/activity-logs?user_id=undefined&module=card-orders&limit=1000&page=2", nil)
|
||||
c.Request = req
|
||||
|
||||
filter, ok := parseListFilter(c)
|
||||
if !ok {
|
||||
t.Fatal("expected filter to parse")
|
||||
}
|
||||
if filter.UserId != nil {
|
||||
t.Fatalf("user_id should be ignored, got %v", *filter.UserId)
|
||||
}
|
||||
if filter.Module != "card-orders" {
|
||||
t.Fatalf("module=%q", filter.Module)
|
||||
}
|
||||
if filter.Limit != maxLimit {
|
||||
t.Fatalf("limit=%d", filter.Limit)
|
||||
}
|
||||
if filter.Page != 2 {
|
||||
t.Fatalf("page=%d", filter.Page)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetByIDListsModuleWhenPathIsNotNumeric(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
|
||||
repo := &stubRepository{listResult: ListActivityLogDTO{Count: 0, Logs: []ActivityLogDTO{}}}
|
||||
h := &handler{logger: logging.GetLogger(), repository: repo}
|
||||
|
||||
r := gin.New()
|
||||
group := r.Group("/activity-logs")
|
||||
group.GET("", h.list)
|
||||
group.GET("/:id", h.getByID)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodGet, "/activity-logs/card-orders?limit=1000", nil)
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
if repo.listFilter.Module != "card-orders" {
|
||||
t.Fatalf("module=%q", repo.listFilter.Module)
|
||||
}
|
||||
if repo.listFilter.Limit != maxLimit {
|
||||
t.Fatalf("limit=%d", repo.listFilter.Limit)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user