package channel import ( "encoding/json" "strings" "testing" ) func TestTheSubjectsNameTheirPublisher(t *testing.T) { for got, want := range map[string]string{ ChannelSubject(Show, "telegram"): "mesh.seat.channel.accept.show.telegram", IntakeSubject(Chosen, "desktop"): "mesh.seat.intake.event.choice.desktop", ProofSubject(CodeProof, "telegram"): "mesh.seat.intake.proof.code.telegram", } { if got != want { t.Errorf("%s, want %s", got, want) } } } // A message's note travels beside its body, and is left out of the encoding when empty, so a channel older // than it reads every message it read before. func TestAMessageCarriesItsNoteApart(t *testing.T) { raw, _ := json.Marshal(Message{Handle: "h", Title: "t", Body: "b", Note: "Asked by x."}) if !strings.Contains(string(raw), `"note":"Asked by x."`) { t.Fatalf("the note is not encoded: %s", raw) } raw, _ = json.Marshal(Message{Handle: "h", Title: "t"}) if strings.Contains(string(raw), "note") { t.Fatalf("an empty note is encoded: %s", raw) } }