buddy_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package handler
  2. import (
  3. "bytes"
  4. "log/slog"
  5. "testing"
  6. "github.com/mk6i/retro-aim-server/wire"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/stretchr/testify/mock"
  9. )
  10. func TestBuddyHandler_RightsQuery(t *testing.T) {
  11. input := wire.SNACMessage{
  12. Frame: wire.SNACFrame{
  13. FoodGroup: wire.Buddy,
  14. SubGroup: wire.BuddyRightsQuery,
  15. },
  16. Body: wire.SNAC_0x03_0x02_BuddyRightsQuery{
  17. TLVRestBlock: wire.TLVRestBlock{
  18. TLVList: wire.TLVList{
  19. wire.NewTLV(0x01, uint16(1000)),
  20. },
  21. },
  22. },
  23. }
  24. output := wire.SNACMessage{
  25. Frame: wire.SNACFrame{
  26. FoodGroup: wire.Buddy,
  27. SubGroup: wire.BuddyRightsReply,
  28. },
  29. Body: wire.SNAC_0x03_0x03_BuddyRightsReply{
  30. TLVRestBlock: wire.TLVRestBlock{
  31. TLVList: wire.TLVList{
  32. wire.NewTLV(0x01, uint16(1000)),
  33. },
  34. },
  35. },
  36. }
  37. svc := newMockBuddyService(t)
  38. svc.EXPECT().
  39. RightsQuery(mock.Anything, input.Frame).
  40. Return(output)
  41. h := NewBuddyHandler(slog.Default(), svc)
  42. responseWriter := newMockResponseWriter(t)
  43. responseWriter.EXPECT().
  44. SendSNAC(output.Frame, output.Body).
  45. Return(nil)
  46. buf := &bytes.Buffer{}
  47. assert.NoError(t, wire.Marshal(input.Body, buf))
  48. assert.NoError(t, h.RightsQuery(nil, nil, input.Frame, buf, responseWriter))
  49. }