56 lines
1.9 KiB
Go
56 lines
1.9 KiB
Go
package api
|
|
|
|
import (
|
|
"droboticflow/internal/domain"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
func TestAnnotatorTaskViewsFilterBeforePagination(t *testing.T) {
|
|
f := newCombinedDraftFixture(t)
|
|
f.item.CreatedAt = "2020-01-01T00:00:00Z"
|
|
f.store.UpsertHumanItem(f.ctx, f.item)
|
|
for i := 0; i < 620; i++ {
|
|
item := f.item
|
|
item.ID = fmt.Sprint("submitted-", i)
|
|
item.CurrentStageID = "quality_review"
|
|
item.Status = domain.HumanItemClaimed
|
|
item.AssignedUserID = f.reviewer.ID
|
|
item.LatestAuthorUserID = f.annotator.ID
|
|
item.CreatedAt = "2026-10-16T00:00:00Z"
|
|
item.Subject.Payload = nil
|
|
f.store.UpsertHumanItem(f.ctx, item)
|
|
}
|
|
decode := func(url string) ([]domain.HumanItemRecord, string) {
|
|
t.Helper()
|
|
r := f.request(http.MethodGet, url, f.annotator, nil)
|
|
if r.Code != 200 {
|
|
t.Fatal(r.Code, r.Body.String())
|
|
}
|
|
var page struct {
|
|
Items []domain.HumanItemRecord `json:"items"`
|
|
Cursor string `json:"nextCursor"`
|
|
}
|
|
json.Unmarshal(r.Body.Bytes(), &page)
|
|
return page.Items, page.Cursor
|
|
}
|
|
active, cursor := decode("/api/human-items?pluginId=annotation-qa&pool=mine&annotationView=active&limit=2")
|
|
if len(active) != 1 || active[0].ID != f.item.ID || cursor != "" {
|
|
t.Fatalf("old pending task hidden: %v cursor=%s", active, cursor)
|
|
}
|
|
history, cursor := decode("/api/human-items?pluginId=annotation-qa&pool=mine&annotationView=submitted&limit=2")
|
|
if len(history) != 2 || cursor == "" {
|
|
t.Fatalf("claimed-by-reviewer history missing: %d", len(history))
|
|
}
|
|
second, _ := decode("/api/human-items?pluginId=annotation-qa&pool=mine&annotationView=submitted&limit=2&cursor=" + cursor)
|
|
if len(second) != 2 || second[0].ID == history[0].ID {
|
|
t.Fatal("history cursor did not advance")
|
|
}
|
|
r := f.request(http.MethodGet, "/api/human-items?pool=mine&annotationView=active", f.reviewer, nil)
|
|
if r.Code != 403 {
|
|
t.Fatal("reviewer view scope changed", r.Code)
|
|
}
|
|
}
|