forked from longtao.wu/droboticflow
45 lines
1.8 KiB
Go
45 lines
1.8 KiB
Go
package store
|
|
|
|
import (
|
|
"droboticflow/internal/domain"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"testing"
|
|
)
|
|
|
|
func TestHumanTraceSummaryMongoKeepsZeroAndUnknownDistinct(t *testing.T) {
|
|
s, ctx := projectStripeTestStore(t)
|
|
for collection, rows := range map[string][]any{
|
|
"users": {bson.M{"id": "author", "organizationId": "org", "name": "Author", "phone": "private"}},
|
|
"suppliers": {bson.M{"id": "supplier", "organizationId": "org", "name": "Supplier"}},
|
|
"humanEvents": {
|
|
bson.M{"id": "created", "organizationId": "org", "itemId": "new", "eventType": "created"},
|
|
bson.M{"id": "legacy-rejection", "organizationId": "org", "itemId": "legacy", "eventType": "combined_quality_rejected", "payload": bson.M{"problems": "private", "annotationRevision": 3}},
|
|
bson.M{"id": "foreign", "organizationId": "other", "itemId": "new", "eventType": "rejected"},
|
|
},
|
|
} {
|
|
if _, err := s.db.Collection(collection).InsertMany(ctx, rows); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
summaries, err := s.ListHumanTraceSummaries(ctx, "org", []domain.HumanItemRecord{{ID: "new", LatestAuthorUserID: "author", SupplierID: "supplier"}, {ID: "legacy"}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if summaries["new"].Rejections == nil || *summaries["new"].Rejections != 0 || summaries["new"].Author != "Author" || summaries["new"].Supplier != "Supplier" {
|
|
t.Fatalf("bad known summary %+v", summaries)
|
|
}
|
|
if summaries["legacy"].Rejections != nil {
|
|
t.Fatal("invented complete count from partial history")
|
|
}
|
|
events, err := s.ListHumanTraceEvents(ctx, "org", "legacy")
|
|
if err != nil || len(events) != 1 {
|
|
t.Fatal(events, err)
|
|
}
|
|
if _, ok := events[0].Payload["problems"]; ok {
|
|
t.Fatal("loaded opinion payload")
|
|
}
|
|
if events[0].Payload["annotationRevision"] == nil {
|
|
t.Fatal("missing combined revision")
|
|
}
|
|
}
|