Something went wrong. Try again.
An ATProto Powered Reputation Network
Something went wrong. Try again.
1.5 kB · 46 lines
Go
at master
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647package microcosm
import ( "context" "encoding/json" "net/http" "net/http/httptest" "strings" "testing"
"provenance/internal/domain")
func TestRecordComments(t *testing.T) { for _, comment := range []string{"", "Reference text.\nUnicode: 日本語 <script>"} { record := validRecord() record.Comment = comment server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(map[string]any{"uri": "at://" + author + "/" + domain.Collection + "/" + domain.RecordKey(subject, "work"), "cid": recordCID, "value": record}) })) client, err := New("ws://127.0.0.1:1/subscribe", server.URL) if err != nil { t.Fatal(err) } for _, payload := range []any{record, nil} { change, err := client.decode(context.Background(), commit(t, Create, payload), nil) if err != nil || change.Vouch == nil || change.Vouch.Comment != comment { t.Fatalf("comment round trip: %+v %v", change, err) } } server.Close() }}
func TestOversizedComment(t *testing.T) { record := validRecord() record.Comment = strings.Repeat("界", domain.MaxCommentLength+1) client, err := New("ws://127.0.0.1:1/subscribe", "https://slingshot.example.com") if err != nil { t.Fatal(err) } change, err := client.decode(context.Background(), commit(t, Update, record), nil) if err != nil || change.Kind != domain.RecordChange || change.Vouch != nil { t.Fatalf("invalid comment entered the index: %+v %v", change, err) }}