events_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package webapi
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. "github.com/mk6i/open-oscar-server/state"
  7. )
  8. func TestUserTypeFor(t *testing.T) {
  9. tests := []struct {
  10. name string
  11. screenName string
  12. want string
  13. }{
  14. {"uin", "123456789", userTypeICQ},
  15. {"single digit", "5", userTypeICQ},
  16. {"aim handle", "cooluser", userTypeAIM},
  17. {"aim handle with digits", "cool123", userTypeAIM},
  18. {"digits around letters", "12abc34", userTypeAIM},
  19. {"empty", "", userTypeAIM},
  20. }
  21. for _, tt := range tests {
  22. t.Run(tt.name, func(t *testing.T) {
  23. assert.Equal(t, tt.want, userTypeFor(state.NewIdentScreenName(tt.screenName)))
  24. })
  25. }
  26. }
  27. func TestServiceFor(t *testing.T) {
  28. tests := []struct {
  29. name string
  30. screenName string
  31. want string
  32. }{
  33. {"uin names icq", "123400", serviceICQ},
  34. {"aim handle is unnamed", "mike", ""},
  35. }
  36. for _, tt := range tests {
  37. t.Run(tt.name, func(t *testing.T) {
  38. assert.Equal(t, tt.want, serviceFor(state.NewIdentScreenName(tt.screenName)))
  39. })
  40. }
  41. }
  42. func TestNewServiceData_MatchesUserServiceTag(t *testing.T) {
  43. cfgs := newServiceData().ServiceConfigs
  44. require.Len(t, cfgs, 1)
  45. // The client joins a user's tag to this list by name, so the two must agree.
  46. assert.Equal(t, serviceFor(state.NewIdentScreenName("123400")), cfgs[0].Name)
  47. assert.Equal(t, "ICQ", cfgs[0].FriendlyName)
  48. assert.True(t, cfgs[0].Associated)
  49. assert.Equal(t, "connected", cfgs[0].ConnectionState)
  50. }