chat_nav_test.go 2.3 KB

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