helpers_test.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. package http
  2. import (
  3. "context"
  4. "net/mail"
  5. "github.com/stretchr/testify/mock"
  6. "github.com/mk6i/retro-aim-server/state"
  7. "github.com/mk6i/retro-aim-server/wire"
  8. )
  9. type mockParams struct {
  10. accountManagerParams
  11. bartRetrieverParams
  12. chatRoomRetrieverParams
  13. chatSessionRetrieverParams
  14. directoryManagerParams
  15. feedBagRetrieverParams
  16. profileRetrieverParams
  17. sessionRetrieverParams
  18. userManagerParams
  19. }
  20. // accountManagerParams is a helper struct that contains mock parameters for
  21. // accountManager methods
  22. type accountManagerParams struct {
  23. EmailAddressParams
  24. RegStatusParams
  25. ConfirmStatusParams
  26. updateSuspendedStatusParams
  27. setBotStatusParams
  28. }
  29. // EmailAddressParams is the list of parameters passed at the mock
  30. // accountManager.EmailAddress call site
  31. type EmailAddressParams []struct {
  32. screenName state.IdentScreenName
  33. result *mail.Address
  34. err error
  35. }
  36. // RegStatusParams is the list of parameters passed at the mock
  37. // accountManager.RegStatus call site
  38. type RegStatusParams []struct {
  39. screenName state.IdentScreenName
  40. result uint16
  41. err error
  42. }
  43. // ConfirmStatusParams is the list of parameters passed at the mock
  44. // accountManager.ConfirmStatus call site
  45. type ConfirmStatusParams []struct {
  46. screenName state.IdentScreenName
  47. result bool
  48. err error
  49. }
  50. // updateSuspendedStatus is the list of parameters passed at the mock
  51. // accountManager.updateSuspendedStatus call site
  52. type updateSuspendedStatusParams []struct {
  53. suspendedStatus uint16
  54. screenName state.IdentScreenName
  55. err error
  56. }
  57. // setBotStatusParams is the list of parameters passed at the mock
  58. // accountManager.SetBotStatus call site
  59. type setBotStatusParams []struct {
  60. isBot bool
  61. screenName state.IdentScreenName
  62. err error
  63. }
  64. // bartRetrieverParams is a helper struct that contains mock parameters for
  65. // BuddyIconRetriever methods
  66. type bartRetrieverParams struct {
  67. bartRetrieveParams
  68. }
  69. // bartRetrieveParams is the list of parameters passed at the mock
  70. // BuddyIconRetriever.BuddyIconParams call site
  71. type bartRetrieveParams []struct {
  72. itemHash []byte
  73. result []byte
  74. err error
  75. }
  76. // chatRoomRetrieverParams is a helper struct that contains mock parameters for
  77. // ChatRoomRetriever methods
  78. type chatRoomRetrieverParams struct {
  79. allChatRoomsParams
  80. }
  81. // allChatRoomsParams is the list of parameters passed at the mock
  82. // ChatRoomRetriever.AllChatRooms call site
  83. type allChatRoomsParams []struct {
  84. exchange uint16
  85. result []state.ChatRoom
  86. err error
  87. }
  88. // chatRoomRetrieverParams is a helper struct that contains mock parameters for
  89. // ChatRoomRetriever methods
  90. type chatSessionRetrieverParams struct {
  91. chatSessionRetrieverAllSessionsParams
  92. }
  93. // chatSessionRetrieverAllSessionsParams is the list of parameters passed at the mock
  94. // ChatSessionRetriever.AllSessions call site
  95. type chatSessionRetrieverAllSessionsParams []struct {
  96. cookie string
  97. result []*state.Session
  98. }
  99. type directoryManagerParams struct {
  100. categoriesParams
  101. createCategoryParams
  102. createKeywordParams
  103. deleteCategoryParams
  104. deleteKeywordParams
  105. keywordsByCategoryParams
  106. }
  107. // categoriesParams is the list of parameters passed at the mock
  108. // DirectoryManager.Categories call site
  109. type categoriesParams []struct {
  110. result []state.Category
  111. err error
  112. }
  113. // createCategoryParams is the list of parameters passed at the mock
  114. // DirectoryManager.CreateCategory call site
  115. type createCategoryParams []struct {
  116. name string
  117. result state.Category
  118. err error
  119. }
  120. // createKeywordParams is the list of parameters passed at the mock
  121. // DirectoryManager.CreateKeyword call site
  122. type createKeywordParams []struct {
  123. name string
  124. categoryID uint8
  125. result state.Keyword
  126. err error
  127. }
  128. // deleteCategoryParams is the list of parameters passed at the mock
  129. // DirectoryManager.DeleteCategory call site
  130. type deleteCategoryParams []struct {
  131. categoryID uint8
  132. err error
  133. }
  134. // deleteKeywordParams is the list of parameters passed at the mock
  135. // DirectoryManager.DeleteKeyword call site
  136. type deleteKeywordParams []struct {
  137. id uint8
  138. err error
  139. }
  140. // keywordsByCategoryParams is the list of parameters passed at the mock
  141. // DirectoryManager.KeywordsByCategory call site
  142. type keywordsByCategoryParams []struct {
  143. categoryID uint8
  144. result []state.Keyword
  145. err error
  146. }
  147. // feedBagRetrieverParams is a helper struct that contains mock parameters for
  148. // FeedBagRetriever methods
  149. type feedBagRetrieverParams struct {
  150. buddyIconMetadataParams
  151. }
  152. // buddyIconMetadataParams is the list of parameters passed at the mock
  153. // FeedBagRetriever.BuddyIconMetadataParams call site
  154. type buddyIconMetadataParams []struct {
  155. screenName state.IdentScreenName
  156. result *wire.BARTID
  157. err error
  158. }
  159. // profileRetrieverParams is a helper struct that contains mock parameters for
  160. // ProfileRetriever methods
  161. type profileRetrieverParams struct {
  162. retrieveProfileParams
  163. }
  164. // retrieveProfileParams is the list of parameters passed at the mock
  165. // ProfileRetriever.Profile call site
  166. type retrieveProfileParams []struct {
  167. screenName state.IdentScreenName
  168. result string
  169. err error
  170. }
  171. // sessionRetrieverParams is a helper struct that contains mock parameters for
  172. // SessionRetriever methods
  173. type sessionRetrieverParams struct {
  174. sessionRetrieverAllSessionsParams
  175. retrieveSessionByNameParams
  176. }
  177. // sessionRetrieverAllSessionsParams is the list of parameters passed at the mock
  178. // SessionRetriever.AllSessions call site
  179. type sessionRetrieverAllSessionsParams []struct {
  180. result []*state.Session
  181. }
  182. // retrieveSessionParams is the list of parameters passed at the mock
  183. // SessionRetriever.RetrieveSessionByName call site
  184. type retrieveSessionByNameParams []struct {
  185. screenName state.IdentScreenName
  186. result *state.Session
  187. }
  188. // userManagerParams is a helper struct that contains mock parameters for
  189. // UserManager methods
  190. type userManagerParams struct {
  191. allUsersParams
  192. deleteUserParams
  193. getUserParams
  194. insertUserParams
  195. setUserPasswordParams
  196. }
  197. // allUsersParams is the list of parameters passed at the mock
  198. // UserManager.AllUsers call site
  199. type allUsersParams []struct {
  200. result []state.User
  201. err error
  202. }
  203. // deleteUserParams is the list of parameters passed at the mock
  204. // UserManager.DeleteUser call site
  205. type deleteUserParams []struct {
  206. screenName state.IdentScreenName
  207. err error
  208. }
  209. // getUserParams is the list of parameters passed at the mock
  210. // UserManager.User call site
  211. type getUserParams []struct {
  212. screenName state.IdentScreenName
  213. result *state.User
  214. err error
  215. }
  216. // insertUserParams is the list of parameters passed at the mock
  217. // UserManager.InsertUser call site
  218. type insertUserParams []struct {
  219. u state.User
  220. err error
  221. }
  222. // setUserPasswordParams is the list of parameters passed at the mock
  223. // UserManager.SetUserPassword call site
  224. type setUserPasswordParams []struct {
  225. screenName state.IdentScreenName
  226. newPassword string
  227. err error
  228. }
  229. // matchContext matches any instance of Context interface.
  230. func matchContext() interface{} {
  231. return mock.MatchedBy(func(ctx any) bool {
  232. _, ok := ctx.(context.Context)
  233. return ok
  234. })
  235. }