31 lines
889 B
Go
31 lines
889 B
Go
package httpapi
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestUserIDJSONAcceptsIMUserID(t *testing.T) {
|
|
var body struct {
|
|
RecorderUserID userID `json:"recorder_user_id"`
|
|
AttendeeUserIDs []userID `json:"attendee_user_ids"`
|
|
}
|
|
raw := []byte(`{"recorder_user_id":"usrag7w9xJ6hto","attendee_user_ids":["usr1RqTFgHSenM"]}`)
|
|
if err := json.Unmarshal(raw, &body); err != nil {
|
|
t.Fatalf("unmarshal: %v", err)
|
|
}
|
|
if body.RecorderUserID == 0 || len(body.AttendeeUserIDs) != 1 || body.AttendeeUserIDs[0] == 0 {
|
|
t.Fatalf("decoded zero ids: %+v", body)
|
|
}
|
|
if got := formatUserID(int64(body.RecorderUserID)); got != "usrag7w9xJ6hto" {
|
|
t.Fatalf("roundtrip recorder=%q", got)
|
|
}
|
|
}
|
|
|
|
func TestUserIDJSONRejectsNumericID(t *testing.T) {
|
|
var id userID
|
|
if err := json.Unmarshal([]byte(`1573862062872858624`), &id); err == nil {
|
|
t.Fatal("expected numeric user id to be rejected")
|
|
}
|
|
}
|