forked from mtusi2026/mtusi2026lab6
22 lines
660 B
Go
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)
|
|
}
|
|
}
|
|
}
|