R-1199 reopened: a box with no list of its own reads the household's from the hub and adopts it, pushes its default once only when no household saved one; every push names its source; an empty saved list stays empty; R-1216 (D28 = A): the install page's swap sentence only when host swap is really short (shared case table); unreleased
gates / gates (push) Successful in 1m55s
gates / gates (push) Successful in 1m55s
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package notify
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/settings"
|
||||
)
|
||||
|
||||
// R-1199 reopened: the push names its source on the wire and returns the hub's "kept"; the read sends the box's own
|
||||
// customer id with its key and decodes the hub's answer. The hub side: felhom.eu hub household_prefs.go.
|
||||
func TestR1199Reopened_TheWire(t *testing.T) {
|
||||
var gotSource, gotQuery, gotAuth string
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
gotAuth = r.Header.Get("Authorization")
|
||||
if r.Method == http.MethodGet {
|
||||
gotQuery = r.URL.RawQuery
|
||||
w.Write([]byte(`{"exists":true,"household_saved":true,"email":"f@example.hu","enabled_events":["node_down"],"cooldown_hours":6}`))
|
||||
return
|
||||
}
|
||||
var body map[string]any
|
||||
json.NewDecoder(r.Body).Decode(&body)
|
||||
gotSource, _ = body["source"].(string)
|
||||
w.Write([]byte(`{"status":"kept","household_saved":true}`))
|
||||
}))
|
||||
defer srv.Close()
|
||||
sett, _ := settings.Load(filepath.Join(t.TempDir(), "settings.json"), log.New(io.Discard, "", 0))
|
||||
n := New(srv.URL, "box-key", "demo-felhom", sett, log.New(io.Discard, "", 0), false)
|
||||
|
||||
status, err := n.SyncPreferencesAs(PrefsSourceDefault, "", []string{"node_down"}, 6, false)
|
||||
if err != nil || status != "kept" || gotSource != "default" {
|
||||
t.Fatalf("push: status=%q err=%v source=%q", status, err, gotSource)
|
||||
}
|
||||
hp, err := n.FetchPreferences()
|
||||
if err != nil || !hp.HouseholdSaved || len(hp.EnabledEvents) != 1 || gotQuery != "customer_id=demo-felhom" || gotAuth != "Bearer box-key" {
|
||||
t.Fatalf("read: %+v err=%v query=%q", hp, err, gotQuery)
|
||||
}
|
||||
if err := n.SyncPreferences("f@example.hu", nil, 6, false); err != nil || gotSource != "household" {
|
||||
t.Fatalf("the page save must be the household's: err=%v source=%q", err, gotSource)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user