oficina / mapa Public

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

Plain git — no account needed to clone.

Download

Download this file

1package mapa
2
3import (
4 "fmt"
5 "testing"
6
7 "amadan.net/oficina/notion.git/notiontest"
8)
9
10// snapshotOutside is every row of every table outside notion_*, as
11// text, for I19: a Survey-only run changes nothing there.
12func (world *importWorld) snapshotOutside() string {
13 world.t.Helper()
14 var tables []string
15 world.store.database.Raw("SELECT name FROM sqlite_master WHERE " +
16 "type = 'table' AND name NOT LIKE 'notion_%' AND " +
17 "name NOT LIKE 'sqlite_%'").Scan(&tables)
18 out := ""
19 for _, table := range tables {
20 var rows []map[string]any
21 world.store.database.Table(table).Find(&rows)
22 out += fmt.Sprintf("%s %v\n", table, rows)
23 }
24 return out
25}
26
27// I19's run half (Notion import spec §14.2): a Survey-only run changes
28// no row outside notion_*. The survey stages every page and writes the
29// map, and nothing else.
30func TestI19ASurveyChangesNothingOutsideTheImport(t *testing.T) {
31 doc := notiontest.NewDocumented()
32 world := newImportWorld(t, doc.Workspace)
33 world.connect(ana)
34 lease, err := world.store.StartRun(ctx(), ana, false)
35 if err != nil {
36 t.Fatal(err)
37 }
38 before := world.snapshotOutside()
39 job := world.job(lease, ana)
40 if err := job.survey(ctx()); err != nil {
41 t.Fatalf("survey: %v", err)
42 }
43 if after := world.snapshotOutside(); after != before {
44 t.Errorf("the survey changed tables outside notion_*:\n%s\n%s",
45 before, after)
46 }
47 staged := world.count("notion_pages", "sealed_staged IS NOT NULL")
48 if staged != 6 {
49 t.Errorf("%d pages staged; the documented set has 6 live pages",
50 staged)
51 }
52 run := world.run(lease.run)
53 if run.State != runWriting || run.Total != 6 || run.Surveyed != 6 {
54 t.Errorf("after the survey: %+v", run)
55 }
56}
57
58// job is the importJob launch would build, without its goroutine.
59func (world *importWorld) job(lease runLease, who string) *importJob {
60 world.t.Helper()
61 client, err := world.app.notion.Client("secret_test")
62 if err != nil {
63 world.t.Fatal(err)
64 }
65 return &importJob{store: world.store, logger: world.app.logger,
66 zone: world.app.config.TimeZone, lease: lease, who: who,
67 client: client, files: world.app.notion.Files(),
68 images: world.app.images}
69}
70