package main import ( "reflect" "strings" "testing" ) // The sent side must never start at Y. // // Y means "already sent", so the uploader skips the contact for ever. An // operator whose eQSL default was Y had a logbook that never reached eQSL and // nothing on screen to explain it — the log said "not eligible, EQSLSent // already Y" and that is the only place it was ever said. func TestNoConfirmationDefaultsToAlreadySent(t *testing.T) { d := defaultQSLDefaults() v := reflect.ValueOf(d) for i := 0; i < v.NumField(); i++ { name := v.Type().Field(i).Name val := strings.ToUpper(strings.TrimSpace(v.Field(i).String())) if val == "Y" { t.Errorf("%s defaults to Y — every new QSO would be skipped by its uploader for ever", name) } } } // Every field has a default. A service added without one comes back blank, // which is not a status anybody chose — HAMLOG.online arrived that way and // every existing profile got nothing for it. func TestEveryConfirmationHasADefault(t *testing.T) { d := defaultQSLDefaults() v := reflect.ValueOf(d) for i := 0; i < v.NumField(); i++ { if strings.TrimSpace(v.Field(i).String()) == "" { t.Errorf("%s has no default — add it to defaultQSLDefaults", v.Type().Field(i).Name) } } } // A profile saved before a service existed has no value stored for it, and // gets the shipped one rather than a blank. func TestStoredBlanksAreFilledFromTheDefaults(t *testing.T) { // What an old profile looks like: the services it knew about are set, the // ones added later are empty. stored := QSLDefaults{ QSLSent: "N", QSLRcvd: "N", EQSLSent: "R", EQSLRcvd: "N", LOTWSent: "R", LOTWRcvd: "N", ClublogStatus: "R", ClublogCfm: "N", HRDLogStatus: "R", QRZComStatus: "R", QRZComCfm: "N", } got := fillMissingQSLDefaults(stored) if got.HamlogStatus != "R" || got.HamlogCfm != "N" || got.HamqthStatus != "R" { t.Errorf("services added later were left blank: hamlog=%q/%q hamqth=%q", got.HamlogStatus, got.HamlogCfm, got.HamqthStatus) } // And a value the operator DID choose is untouched. chosen := QSLDefaults{QSLSent: "I", EQSLSent: "N"} filled := fillMissingQSLDefaults(chosen) if filled.QSLSent != "I" || filled.EQSLSent != "N" { t.Errorf("a chosen status was overwritten: %q / %q", filled.QSLSent, filled.EQSLSent) } }