session_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package handlers
  2. import (
  3. "encoding/json"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/mk6i/open-oscar-server/state"
  7. )
  8. func TestBuildMyInfo_UserTypeAndService(t *testing.T) {
  9. tests := []struct {
  10. name string
  11. screenName string
  12. wantType string
  13. wantSvc string
  14. }{
  15. {"aim screen name", "mikekelly", "aim", "AIM"},
  16. {"icq uin", "123456789", "icq", "ICQ"},
  17. }
  18. for _, tt := range tests {
  19. t.Run(tt.name, func(t *testing.T) {
  20. mi := buildMyInfo(state.DisplayScreenName(tt.screenName), "online", "")
  21. assert.Equal(t, tt.wantType, mi.UserType)
  22. assert.Equal(t, tt.wantSvc, mi.Service)
  23. })
  24. }
  25. }
  26. func TestBuildMyInfo_BuddyIcon(t *testing.T) {
  27. t.Run("included when set", func(t *testing.T) {
  28. mi := buildMyInfo(state.DisplayScreenName("mikekelly"), "away", "http://x/icon")
  29. assert.Equal(t, "http://x/icon", mi.BuddyIcon)
  30. })
  31. t.Run("omitted when empty so the client merge preserves the current icon", func(t *testing.T) {
  32. mi := buildMyInfo(state.DisplayScreenName("mikekelly"), "away", "")
  33. assert.Empty(t, mi.BuddyIcon)
  34. // omitempty is what actually keeps it out of the payload.
  35. body, err := json.Marshal(mi)
  36. assert.NoError(t, err)
  37. assert.NotContains(t, string(body), "buddyIcon")
  38. })
  39. }