Files
mtusi2026lab6/dto/create_message_json_test.go
2026-11-18 21:37:25 +03:00

22 lines
660 B
Go

package dto
import (
"encoding/json"
"testing"
)
func TestMessageStrictFields(t *testing.T) {
for _, body := range []string{`null`, `[]`, `{}`, `{"text":null}`, `{"text":"x","attachment_ids":null}`, `{"text":"x","attachment_ids":"x"}`, `{"text":"x","extra":1}`} {
var r CreateMessageRequest
if err := json.Unmarshal([]byte(body), &r); err == nil {
t.Fatalf("accepted %s", body)
}
}
for _, body := range []string{`{"text":"x"}`, `{"text":"x","attachment_ids":[]}`, `{"text":"","attachment_ids":["id"]}`} {
var r CreateMessageRequest
if err := json.Unmarshal([]byte(body), &r); err != nil {
t.Fatalf("rejected %s: %v", body, err)
}
}
}