--region takes a place name as well as a code ("Bonn", "Köln", "cologne",
"name:dub" to force a name that looks like a code). The node uses the same
GeoNames list as the browser (internal/places), follows the place's cell plus
any cell within 40 km, and prints what each name became.
The node reminds the owner on its terminal, once a day per listing, about
every listing with 5 days or less left (the UI marks the same range). The
sign-in token is never in the line.
scripts/e2e/ui.ts drives the real bundle in jsdom against real nodes: a buyer
writes from a listing page, the owner reads and answers in their own page and
the buyer's page shows the verified answer; a node with no region gets its
first one by place name in the browser and keeps it over a restart. e2e.sh
also checks --region by name and the reminder, and keeps its scratch files in
the checkout's .tmp.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
89 lines
2.6 KiB
Go
89 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.stinnesbeck.com/nils/allmende/internal/places"
|
|
)
|
|
|
|
func realPlaces() ([]places.Place, error) { return places.Load(os.DirFS("../../web/dist")) }
|
|
|
|
func TestCodesPassThroughWithoutLoadingPlaces(t *testing.T) {
|
|
loaded := false
|
|
got, notes, err := resolveRegions([]string{"u1j", " U1X ", "u1j"}, func() ([]places.Place, error) {
|
|
loaded = true
|
|
return nil, nil
|
|
})
|
|
if err != nil || loaded || len(notes) != 0 || !reflect.DeepEqual(got, []string{"u1j", "u1x"}) {
|
|
t.Fatalf("got %v notes %v loaded=%v err=%v", got, notes, loaded, err)
|
|
}
|
|
}
|
|
|
|
func TestANameBecomesItsCellsAndSaysSo(t *testing.T) {
|
|
got, notes, err := resolveRegions([]string{"bonn", "Cologne"}, realPlaces)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got[0] != "u1j" {
|
|
t.Fatalf("Bonn's own cell comes first: %v", got)
|
|
}
|
|
if len(notes) != 2 || !strings.Contains(notes[0], "Bonn") || !strings.Contains(notes[1], "Köln (Cologne)") {
|
|
t.Fatalf("notes = %q", notes)
|
|
}
|
|
seen := map[string]bool{}
|
|
for _, r := range got {
|
|
if seen[r] {
|
|
t.Fatalf("repeated region in %v", got)
|
|
}
|
|
seen[r] = true
|
|
}
|
|
}
|
|
|
|
func TestACodeAndANameMix(t *testing.T) {
|
|
got, _, err := resolveRegions([]string{"u30", "Bonn"}, realPlaces)
|
|
if err != nil || got[0] != "u30" || got[1] != "u1j" {
|
|
t.Fatalf("got %v err=%v", got, err)
|
|
}
|
|
}
|
|
|
|
func TestAnUnknownNameIsRefusedWithAHint(t *testing.T) {
|
|
_, _, err := resolveRegions([]string{"Atlantisxyz"}, realPlaces)
|
|
if err == nil || !strings.Contains(err.Error(), "neither a region code") {
|
|
t.Fatalf("err = %v", err)
|
|
}
|
|
}
|
|
|
|
func TestANameThatLooksLikeACodeCanBeForced(t *testing.T) {
|
|
got, notes, err := resolveRegions([]string{"name:dublin"}, realPlaces)
|
|
if err != nil || len(notes) != 1 || !strings.Contains(notes[0], "Dublin") || len(got) == 0 {
|
|
t.Fatalf("got %v notes %v err=%v", got, notes, err)
|
|
}
|
|
// Without the prefix, "dub" is a valid code and is taken as one.
|
|
got, notes, err = resolveRegions([]string{"dub"}, realPlaces)
|
|
if err != nil || len(notes) != 0 || !reflect.DeepEqual(got, []string{"dub"}) {
|
|
t.Fatalf("dub: %v %v %v", got, notes, err)
|
|
}
|
|
}
|
|
|
|
func TestNamesNeedThePlaceList(t *testing.T) {
|
|
_, _, err := resolveRegions([]string{"Bonn"}, func() ([]places.Place, error) { return nil, errors.New("gone") })
|
|
if err == nil || !strings.Contains(err.Error(), "not available") {
|
|
t.Fatalf("err = %v", err)
|
|
}
|
|
}
|
|
|
|
func TestTooManyRegionsAreRefused(t *testing.T) {
|
|
var many []string
|
|
for _, c := range "0123456789bcdefghjkmn" {
|
|
many = append(many, "u0"+string(c))
|
|
}
|
|
_, _, err := resolveRegions(many, nil)
|
|
if err == nil || !strings.Contains(err.Error(), "at most") {
|
|
t.Fatalf("err = %v", err)
|
|
}
|
|
}
|