| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- package handler
- import (
- "bytes"
- "log/slog"
- "testing"
- "github.com/mk6i/retro-aim-server/state"
- "github.com/mk6i/retro-aim-server/wire"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/mock"
- )
- func TestChatNavHandler_CreateRoom(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.ChatNav,
- SubGroup: wire.ChatNavCreateRoom,
- },
- Body: wire.SNAC_0x0E_0x02_ChatRoomInfoUpdate{
- Exchange: 1,
- },
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.ChatNav,
- SubGroup: wire.ChatNavNavInfo,
- },
- Body: wire.SNAC_0x0D_0x09_ChatNavNavInfo{},
- }
- sess := state.NewSession()
- svc := newMockChatNavService(t)
- svc.EXPECT().
- CreateRoom(mock.Anything, sess, input.Frame, input.Body).
- Return(output, nil)
- h := NewChatNavHandler(svc, slog.Default())
- ss := newMockResponseWriter(t)
- ss.EXPECT().
- SendSNAC(output.Frame, output.Body).
- Return(nil)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.CreateRoom(nil, sess, input.Frame, buf, ss))
- }
- func TestChatNavHandler_CreateRoom_ReadErr(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.ChatNav,
- SubGroup: wire.ChatNavCreateRoom,
- },
- Body: wire.SNAC_0x0E_0x02_ChatRoomInfoUpdate{
- Exchange: 1,
- },
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.ChatNav,
- SubGroup: wire.ChatNavNavInfo,
- },
- Body: wire.SNAC_0x0D_0x09_ChatNavNavInfo{},
- }
- sess := state.NewSession()
- svc := newMockChatNavService(t)
- svc.EXPECT().
- CreateRoom(mock.Anything, sess, input.Frame, input.Body).
- Return(output, nil)
- h := NewChatNavHandler(svc, slog.Default())
- ss := newMockResponseWriter(t)
- ss.EXPECT().
- SendSNAC(output.Frame, output.Body).
- Return(nil)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.CreateRoom(nil, sess, input.Frame, buf, ss))
- }
- func TestChatNavHandler_RequestChatRights(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.ChatNav,
- SubGroup: wire.ChatNavRequestChatRights,
- },
- Body: struct{}{},
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.ChatNav,
- SubGroup: wire.ChatNavNavInfo,
- },
- Body: wire.SNAC_0x0D_0x09_ChatNavNavInfo{},
- }
- svc := newMockChatNavService(t)
- svc.EXPECT().
- RequestChatRights(mock.Anything, input.Frame).
- Return(output)
- h := NewChatNavHandler(svc, slog.Default())
- ss := newMockResponseWriter(t)
- ss.EXPECT().
- SendSNAC(output.Frame, output.Body).
- Return(nil)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.RequestChatRights(nil, nil, input.Frame, buf, ss))
- }
- func TestChatNavHandler_RequestRoomInfo(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.ChatNav,
- SubGroup: wire.ChatNavRequestRoomInfo,
- },
- Body: wire.SNAC_0x0D_0x04_ChatNavRequestRoomInfo{
- Exchange: 1,
- },
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.ChatNav,
- SubGroup: wire.ChatNavNavInfo,
- },
- Body: wire.SNAC_0x0D_0x09_ChatNavNavInfo{},
- }
- svc := newMockChatNavService(t)
- svc.EXPECT().
- RequestRoomInfo(mock.Anything, input.Frame, input.Body).
- Return(output, nil)
- h := NewChatNavHandler(svc, slog.Default())
- ss := newMockResponseWriter(t)
- ss.EXPECT().
- SendSNAC(output.Frame, output.Body).
- Return(nil)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.RequestRoomInfo(nil, nil, input.Frame, buf, ss))
- }
- func TestChatNavHandler_RequestExchangeInfo(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.ChatNav,
- SubGroup: wire.ChatNavRequestExchangeInfo,
- },
- Body: wire.SNAC_0x0D_0x03_ChatNavRequestExchangeInfo{
- Exchange: 4,
- },
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.ChatNav,
- SubGroup: wire.ChatNavNavInfo,
- },
- Body: wire.SNAC_0x0D_0x09_ChatNavNavInfo{},
- }
- svc := newMockChatNavService(t)
- svc.EXPECT().
- ExchangeInfo(mock.Anything, input.Frame, input.Body).
- Return(output, nil)
- h := NewChatNavHandler(svc, slog.Default())
- ss := newMockResponseWriter(t)
- ss.EXPECT().
- SendSNAC(output.Frame, output.Body).
- Return(nil)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.RequestExchangeInfo(nil, nil, input.Frame, buf, ss))
- }
|