chat_nav_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package handler
  2. import (
  3. "context"
  4. "github.com/mkaminski/goaim/oscar"
  5. "github.com/mkaminski/goaim/server"
  6. "github.com/stretchr/testify/assert"
  7. "testing"
  8. "time"
  9. )
  10. func TestSendAndReceiveCreateRoom(t *testing.T) {
  11. //
  12. // build dependencies
  13. //
  14. userSess := newTestSession("user-screen-name", sessOptCannedID)
  15. cr := server.NewChatRegistry()
  16. sm := server.NewMockChatSessionManager(t)
  17. sm.EXPECT().NewSessionWithSN(userSess.ID(), userSess.ScreenName()).
  18. Return(&server.Session{})
  19. chatSessMgrFactory := func() server.ChatSessionManager {
  20. return sm
  21. }
  22. newChatRoom := func() server.ChatRoom {
  23. return server.ChatRoom{
  24. Cookie: "dummy-cookie",
  25. CreateTime: time.UnixMilli(0),
  26. }
  27. }
  28. //
  29. // send input SNAC
  30. //
  31. inputSNAC := oscar.SNAC_0x0E_0x02_ChatRoomInfoUpdate{
  32. Exchange: 1,
  33. Cookie: "create", // actual canned value sent by AIM client
  34. InstanceNumber: 2,
  35. DetailLevel: 3,
  36. TLVBlock: oscar.TLVBlock{
  37. TLVList: oscar.TLVList{
  38. oscar.NewTLV(oscar.ChatTLVRoomName, "the-chat-room-name"),
  39. },
  40. },
  41. }
  42. svc := ChatNavService{
  43. cr: cr,
  44. }
  45. outputSNAC, err := svc.CreateRoomHandler(context.Background(), userSess, newChatRoom, chatSessMgrFactory, inputSNAC)
  46. assert.NoError(t, err)
  47. //
  48. // verify chat room created by handler
  49. //
  50. expectChatRoom := server.ChatRoom{
  51. Cookie: "dummy-cookie",
  52. CreateTime: time.UnixMilli(0),
  53. DetailLevel: 3,
  54. Exchange: 1,
  55. InstanceNumber: 2,
  56. Name: "the-chat-room-name",
  57. }
  58. chatRoom, _, err := cr.Retrieve("dummy-cookie")
  59. assert.NoError(t, err)
  60. assert.Equal(t, expectChatRoom, chatRoom)
  61. //
  62. // send input SNAC
  63. //
  64. expectSNAC := oscar.XMessage{
  65. SnacFrame: oscar.SnacFrame{
  66. FoodGroup: oscar.CHAT_NAV,
  67. SubGroup: oscar.ChatNavNavInfo,
  68. },
  69. SnacOut: oscar.SNAC_0x0D_0x09_ChatNavNavInfo{
  70. TLVRestBlock: oscar.TLVRestBlock{
  71. TLVList: oscar.TLVList{
  72. oscar.NewTLV(
  73. oscar.ChatNavTLVRoomInfo,
  74. oscar.SNAC_0x0E_0x02_ChatRoomInfoUpdate{
  75. Exchange: chatRoom.Exchange,
  76. Cookie: chatRoom.Cookie,
  77. InstanceNumber: chatRoom.InstanceNumber,
  78. DetailLevel: chatRoom.DetailLevel,
  79. TLVBlock: oscar.TLVBlock{
  80. TLVList: chatRoom.TLVList(),
  81. },
  82. },
  83. ),
  84. },
  85. },
  86. },
  87. }
  88. assert.Equal(t, expectSNAC, outputSNAC)
  89. }