feat: complete IM P0 and P1 reliability work
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/tinode/chat/server/store/types"
|
||||
@@ -11,3 +12,30 @@ func TestForTenantRejectsZero(t *testing.T) {
|
||||
t.Fatalf("ForTenant(0) = (%v, %v), want (nil, malformed)", scoped, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateMessageHeadersProductContract(t *testing.T) {
|
||||
valid := []types.KVMap{
|
||||
{"x-im-schema": float64(1), "x-im-type": "text"},
|
||||
{"x-im-schema": json.Number("1"), "x-im-type": "voice"},
|
||||
{"x-im-schema": "1", "x-im-type": "contact_card"},
|
||||
{"x-im-schema": 1, "type": "audio", "x-im-type": "voice"},
|
||||
{"type": "system"},
|
||||
}
|
||||
for _, head := range valid {
|
||||
if err := validateMessageHeaders(head); err != nil {
|
||||
t.Fatalf("validateMessageHeaders(%v) = %v, want nil", head, err)
|
||||
}
|
||||
}
|
||||
|
||||
invalid := []types.KVMap{
|
||||
{"x-im-schema": float64(2), "x-im-type": "text"},
|
||||
{"x-im-schema": true, "x-im-type": "text"},
|
||||
{"x-im-schema": float64(1), "x-im-type": "unknown"},
|
||||
{"type": "text", "x-im-type": "image"},
|
||||
}
|
||||
for _, head := range invalid {
|
||||
if err := validateMessageHeaders(head); err != types.ErrMalformed {
|
||||
t.Fatalf("validateMessageHeaders(%v) = %v, want malformed", head, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user