| 1 | package chat |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "testing" |
| 7 | |
| 8 | "amadan.net/oficina/equipo/internal/wire" |
| 9 | ) |
| 10 | |
| 11 | func TestProjectListCursorAndTypedMarker(t *testing.T) { |
| 12 | r := placementRig(t) |
| 13 | ctx := context.Background() |
| 14 | data, _ := json.Marshal(placementData{ByName: true}) |
| 15 | c := cardRecord{ID: "c_typed", Person: hkOwner, Kind: wire.CardQuestion, State: wire.CardOpen, Options: "[]", Placement: string(data), Revision: 1} |
| 16 | err := r.s.tx(ctx, func(tx *txn) error { |
| 17 | typed, err := tx.cardView(c) |
| 18 | if err != nil { |
| 19 | return err |
| 20 | } |
| 21 | if !typed.PlacementByName { |
| 22 | t.Error("typed placement must have a marker even after opting out") |
| 23 | } |
| 24 | c.Placement = "" |
| 25 | ordinary, err := tx.cardView(c) |
| 26 | if ordinary.PlacementByName { |
| 27 | t.Error("ordinary question has project marker") |
| 28 | } |
| 29 | if err != nil { |
| 30 | return err |
| 31 | } |
| 32 | return tx.event("", hkOwner, wire.EventProject, "project", "p_event", 1, "", "", 0, wire.Project{}) |
| 33 | }) |
| 34 | if err != nil { |
| 35 | t.Fatal(err) |
| 36 | } |
| 37 | if _, _, err := r.s.AddProject(ctx, hkOwner, "oficina/new"); err != nil { |
| 38 | t.Fatal(err) |
| 39 | } |
| 40 | list, err := r.s.Projects(ctx, hkOwner) |
| 41 | if err != nil { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | cursor, err := r.s.Cursor(ctx) |
| 45 | if err != nil { |
| 46 | t.Fatal(err) |
| 47 | } |
| 48 | if cursor == 0 || list.Cursor != cursor { |
| 49 | t.Fatalf("list cursor = %d, events = %d", list.Cursor, cursor) |
| 50 | } |
| 51 | } |
| 52 | |