| 1 | package equipo |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "testing" |
| 6 | |
| 7 | "amadan.net/oficina/equipo/internal/equipo/chat" |
| 8 | "amadan.net/rastrillo/rastrillo/migrate" |
| 9 | ) |
| 10 | |
| 11 | // #49: project p_hydlybiyyy3jy574grtydymnyd (oficina/equipo) was stored |
| 12 | // with the title "Create". The migration clears every title Equipo chose |
| 13 | // itself (title_set 0), so each project shows its repository's name ("Store" |
| 14 | // for oficina/base was the same bug); a title an owner set stays, and so |
| 15 | // does every task. A second run changes nothing. |
| 16 | func TestClearEquipoChosenTitlesMigration(t *testing.T) { |
| 17 | all := Schema.All() |
| 18 | at := -1 |
| 19 | for i, m := range all { |
| 20 | if m.ID == "equipo/0103_clear_equipo_chosen_titles" { |
| 21 | at = i |
| 22 | } |
| 23 | } |
| 24 | if at < 0 { |
| 25 | t.Fatal("missing the migration that clears Equipo-chosen titles") |
| 26 | } |
| 27 | ctx := context.Background() |
| 28 | d, err := migrate.Replay(ctx, all[:at]) |
| 29 | if err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | defer d.Close() |
| 33 | for _, q := range []string{ |
| 34 | "INSERT INTO chat_projects(id,repo,title,title_set,state,revision) VALUES('p_hydlybiyyy3jy574grtydymnyd','amadan.net/oficina/equipo','Create',0,'active',1)", |
| 35 | "INSERT INTO chat_projects(id,repo,title,title_set,state,revision) VALUES('p_named','amadan.net/oficina/new','New',1,'active',3)", |
| 36 | "INSERT INTO chat_projects(id,repo,title,state,revision) VALUES('p_legacy','amadan.net/oficina/web','Project','active',1)", |
| 37 | "INSERT INTO chat_projects(id,repo,title,title_set,state,revision) VALUES('p_base','amadan.net/oficina/base','Store',0,'active',2)", |
| 38 | "INSERT INTO chat_projects(id,repo,title,title_set,state,revision) VALUES('p_owner','amadan.net/oficina/alta','Alta provisioning',1,'active',4)", |
| 39 | "INSERT INTO chat_projects(id,repo,title,title_set,state,revision) VALUES('p_clean','amadan.net/oficina/docs','',0,'active',5)", |
| 40 | "INSERT INTO chat_tasks(id,project_id,title,stage) VALUES('tkqpu72zbeuo','p_hydlybiyyy3jy574grtydymnyd','Swipe down to dismiss the keyboard on iOS','noted')", |
| 41 | } { |
| 42 | if _, err := d.ExecContext(ctx, q); err != nil { |
| 43 | t.Fatal(err) |
| 44 | } |
| 45 | } |
| 46 | for range 2 { |
| 47 | if _, err := d.ExecContext(ctx, all[at].SQL); err != nil { |
| 48 | t.Fatal(err) |
| 49 | } |
| 50 | } |
| 51 | for id, want := range map[string]struct { |
| 52 | title string |
| 53 | revision int64 |
| 54 | }{"p_hydlybiyyy3jy574grtydymnyd": {"", 2}, "p_named": {"New", 3}, "p_legacy": {"", 2}, "p_base": {"", 3}, "p_owner": {"Alta provisioning", 4}, "p_clean": {"", 5}} { |
| 55 | var title string |
| 56 | var revision int64 |
| 57 | if err := d.QueryRowContext(ctx, "SELECT title, revision FROM chat_projects WHERE id = ?", id).Scan(&title, &revision); err != nil { |
| 58 | t.Fatal(err) |
| 59 | } |
| 60 | if title != want.title || revision != want.revision { |
| 61 | t.Errorf("%s: %q rev %d, want %q rev %d", id, title, revision, want.title, want.revision) |
| 62 | } |
| 63 | } |
| 64 | if got := chat.ProjectTitle("amadan.net/oficina/equipo"); got != "Equipo" { |
| 65 | t.Fatalf("cleared title shows %q", got) |
| 66 | } |
| 67 | var project string |
| 68 | if err := d.QueryRowContext(ctx, "SELECT project_id FROM chat_tasks WHERE id = 'tkqpu72zbeuo'").Scan(&project); err != nil || project != "p_hydlybiyyy3jy574grtydymnyd" { |
| 69 | t.Fatal("task lost its project", project, err) |
| 70 | } |
| 71 | } |
| 72 | |