package store import ( "encoding/json" "testing" ) func TestReviewedSequencesProtectPreparation(t *testing.T) { pack, err := bundledSequences() if err != nil { t.Fatal(err) } base, err := BundledBank() if err != nil { t.Fatal(err) } if len(pack.Sequences) != 60 { t.Fatal(len(pack.Sequences)) } copyPack := func() sequencePack { raw, _ := json.Marshal(pack) var copy sequencePack if err := json.Unmarshal(raw, ©); err != nil { t.Fatal(err) } return copy } t.Run("no free speech first", func(t *testing.T) { copy := copyPack() copy.Sequences[0].Steps[0] = copy.Sequences[0].Steps[len(copy.Sequences[0].Steps)-1] if validateSequences(copy, base) == nil { t.Fatal("unprepared speaking accepted") } }) t.Run("no unrelated writing at the end", func(t *testing.T) { copy := copyPack() n := len(copy.Sequences[0].Steps) other := copy.Sequences[1] copy.Sequences[0].Steps[n-2] = other.Steps[len(other.Steps)-2] if validateSequences(copy, base) == nil { t.Fatal("unrelated writing accepted") } }) t.Run("both native titles required", func(t *testing.T) { copy := copyPack() delete(copy.Sequences[0].Titles, "ru-RU") if validateSequences(copy, base) == nil { t.Fatal("missing Russian topic accepted") } }) for _, module := range []string{"introductions", "family", "numbers_time", "daily_life", "food_shopping", "home_city"} { positions := sequencePositions(pack, "a1_"+module+"_v1") if len(positions) == 0 || positions[0].Step.Phase != "listen" { t.Fatal("no listening entry", module) } for _, native := range []string{"de-DE", "ru-RU"} { r := recommendationAt(pack, positions, 0, 0, "", native) if r.Topic != 1 || r.Topics != 10 || r.Title == "" || r.Complete { t.Fatal(r) } } } }