webapi_event_converter_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package handlers
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/mk6i/open-oscar-server/server/webapi/types"
  6. )
  7. // The AMF3 converter re-flattens PresenceEvent through an explicit allowlist, so a
  8. // field absent from that allowlist never reaches an AMF3 client. buddyIcon must be
  9. // on it.
  10. func TestConvertEventForAMF3_PresenceCarriesBuddyIcon(t *testing.T) {
  11. t.Run("buddyIcon is included when set", func(t *testing.T) {
  12. out := ConvertEventForAMF3(types.Event{
  13. Type: types.EventTypePresence,
  14. Data: types.PresenceEvent{
  15. AimID: "mikekelly",
  16. State: "online",
  17. UserType: "aim",
  18. BuddyIcon: "http://api.example.com/expressions/get?t=mikekelly&type=buddyIcon&bartId=dead",
  19. },
  20. })
  21. eventData := out["eventData"].(map[string]interface{})
  22. assert.Equal(t,
  23. "http://api.example.com/expressions/get?t=mikekelly&type=buddyIcon&bartId=dead",
  24. eventData["buddyIcon"])
  25. })
  26. t.Run("buddyIcon is omitted when empty", func(t *testing.T) {
  27. out := ConvertEventForAMF3(types.Event{
  28. Type: types.EventTypePresence,
  29. Data: types.PresenceEvent{AimID: "mikekelly", State: "offline", UserType: "aim"},
  30. })
  31. eventData := out["eventData"].(map[string]interface{})
  32. _, ok := eventData["buddyIcon"]
  33. assert.False(t, ok)
  34. })
  35. }