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 "context"
5 "testing"
6
7 "amadan.net/oficina/equipo/internal/wire"
8)
9
10// A Research step of a job dispatched before web went off isn't granted
11// its start or a renewal: authorizeResearch refuses ability_off on every
12// lease call. A task no hand-off follows is outside the board.
13func TestResearchLeaseNeedsWeb(t *testing.T) {
14 h, base := boardBase(t)
15 refresh(t, h)
16 for _, r := range []any{
17 &handoffRecord{ID: "h_r", Person: abPerson, State: handoffOpen, LedgerKey: "k-r", CreatedAt: h.now(), UpdatedAt: h.now()},
18 &handoffTaskRecord{HandoffID: "h_r", TaskID: "tk_job", Created: true},
19 } {
20 if err := h.s.db.G.Create(r).Error; err != nil {
21 t.Fatal(err)
22 }
23 }
24 authorize := func(task string) string {
25 var refused string
26 if err := h.s.tx(context.Background(), func(tx *txn) error {
27 allowed, err := tx.researchAllowed(task)
28 if err != nil || allowed {
29 return err
30 }
31 refused, err = tx.authorizeResearch(&stepRecord{ID: "s_r", TaskID: task})
32 return err
33 }); err != nil {
34 t.Fatal(err)
35 }
36 return refused
37 }
38 if got := authorize("tk_job"); got != "" {
39 t.Errorf("with web on: %q", got)
40 }
41 base.set(func(f *fakeBoardBase) { f.board.Abilities["web"], f.board.Revision = false, 2 })
42 refresh(t, h)
43 if got := authorize("tk_job"); got != wire.CodeAbilityOff {
44 t.Errorf("with web off: %q", got)
45 }
46 if got := authorize("tk_own"); got != "" {
47 t.Errorf("a task outside the board: %q", got)
48 }
49}
50