oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package chat
2
3import (
4 "amadan.net/oficina/equipo/internal/wire"
5 "encoding/json"
6 "strings"
7 "testing"
8)
9
10func TestCopyWithdrawalKeepsTaskChanges(t *testing.T) {
11 for _, next := range []bool{false, true} {
12 t.Run(map[bool]string{false: "placement", true: "next-step"}[next], func(t *testing.T) {
13 r := copyPendingRig(t, wire.StepQueued, "")
14 r.exec("UPDATE chat_projects SET copy_owner='' WHERE id='p1'")
15 r.exec("UPDATE chat_tasks SET copy_hold=1,watching='' WHERE id='tkcopy'")
16 r.must(r.tx(func(tx *txn) error {
17 if !next {
18 return tx.placeWaiting(hkOwner)
19 }
20 if err := tx.db.Where("id='copy'").Delete(&stepRecord{}).Error; err != nil {
21 return err
22 }
23 k, err := tx.loadTask("tkcopy")
24 if err != nil {
25 return err
26 }
27 steps, err := tx.steps(k.ID)
28 if err != nil {
29 return err
30 }
31 return tx.nextStep(&k, steps, stepRecord{Specialist: wire.SpecialistCopy, Person: hkOwner, CopyOwner: hkOwner, CopyRevision: 1, CandidateSHA: strings.Repeat("a", 40)})
32 }))
33 var k taskRecord
34 r.must(r.s.db.G.First(&k, "id='tkcopy'").Error)
35 if k.CopyHold || k.Watching != strings.Repeat("a", 40) {
36 t.Fatalf("caller overwrote withdrawal task changes: hold=%v watching=%q", k.CopyHold, k.Watching)
37 }
38 })
39 }
40}
41func TestCopyLegacyLongEditDoesNotRejectImport(t *testing.T) {
42 r := copyPendingRig(t, wire.StepDone, "")
43 raw, _ := json.Marshal(map[string]any{"action": "approve", "strings": []map[string]any{
44 {"id": "long", "original": strings.Repeat("a", 250), "text": strings.Repeat("b", 250), "edited": true, "done": true},
45 {"id": "short", "original": "Save it", "text": "Save changes", "edited": true, "done": true},
46 }})
47 var in CopyImport
48 r.must(json.Unmarshal(raw, &in))
49 r.must(r.s.ImportCopyReview(r.ctx, hkOwner, "p1", in))
50 var rows []copyFeedbackRecord
51 r.must(r.s.db.G.Find(&rows).Error)
52 if len(rows) != 1 || rows[0].Key != "short" {
53 t.Fatalf("long edit poisoned import: %+v", rows)
54 }
55}
56