helpers_test.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. package http
  2. import (
  3. "context"
  4. "net/mail"
  5. "github.com/stretchr/testify/mock"
  6. "github.com/mk6i/open-oscar-server/state"
  7. "github.com/mk6i/open-oscar-server/wire"
  8. )
  9. type mockParams struct {
  10. accountManagerParams
  11. bartAssetManagerParams
  12. buddyBroadcasterParams
  13. chatRoomDeleterParams
  14. chatRoomRetrieverParams
  15. chatSessionRetrieverParams
  16. directoryManagerParams
  17. feedBagRetrieverParams
  18. feedbagManagerParams
  19. messageRelayerParams
  20. profileRetrieverParams
  21. sessionRetrieverParams
  22. userManagerParams
  23. }
  24. // accountManagerParams is a helper struct that contains mock parameters for
  25. // accountManager methods
  26. type accountManagerParams struct {
  27. EmailAddressParams
  28. RegStatusParams
  29. ConfirmStatusParams
  30. updateSuspendedStatusParams
  31. setBotStatusParams
  32. }
  33. // EmailAddressParams is the list of parameters passed at the mock
  34. // accountManager.EmailAddress call site
  35. type EmailAddressParams []struct {
  36. screenName state.IdentScreenName
  37. result *mail.Address
  38. err error
  39. }
  40. // RegStatusParams is the list of parameters passed at the mock
  41. // accountManager.RegStatus call site
  42. type RegStatusParams []struct {
  43. screenName state.IdentScreenName
  44. result uint16
  45. err error
  46. }
  47. // ConfirmStatusParams is the list of parameters passed at the mock
  48. // accountManager.ConfirmStatus call site
  49. type ConfirmStatusParams []struct {
  50. screenName state.IdentScreenName
  51. result bool
  52. err error
  53. }
  54. // updateSuspendedStatus is the list of parameters passed at the mock
  55. // accountManager.updateSuspendedStatus call site
  56. type updateSuspendedStatusParams []struct {
  57. suspendedStatus uint16
  58. screenName state.IdentScreenName
  59. err error
  60. }
  61. // setBotStatusParams is the list of parameters passed at the mock
  62. // accountManager.SetBotStatus call site
  63. type setBotStatusParams []struct {
  64. isBot bool
  65. screenName state.IdentScreenName
  66. err error
  67. }
  68. // bartAssetManagerParams is a helper struct that contains mock parameters for
  69. // BARTAssetManager methods
  70. type bartAssetManagerParams struct {
  71. bartItemParams
  72. insertBARTItemParams
  73. listBARTItemsParams
  74. deleteBARTItemParams
  75. }
  76. // bartItemParams is the list of parameters passed at the mock
  77. // BARTAssetManager.BARTItem call site
  78. type bartItemParams []struct {
  79. hash []byte
  80. result []byte
  81. err error
  82. }
  83. // insertBARTItemParams is the list of parameters passed at the mock
  84. // BARTAssetManager.InsertBARTItem call site
  85. type insertBARTItemParams []struct {
  86. hash []byte
  87. blob []byte
  88. itemType uint16
  89. err error
  90. }
  91. // listBARTItemsParams is the list of parameters passed at the mock
  92. // BARTAssetManager.ListBARTItems call site
  93. type listBARTItemsParams []struct {
  94. itemType uint16
  95. result []state.BARTItem
  96. err error
  97. }
  98. // deleteBARTItemParams is the list of parameters passed at the mock
  99. // BARTAssetManager.DeleteBARTItem call site
  100. type deleteBARTItemParams []struct {
  101. hash []byte
  102. err error
  103. }
  104. // buddyBroadcasterParams is a helper struct that contains mock parameters for
  105. // BuddyBroadcaster methods
  106. type buddyBroadcasterParams struct {
  107. broadcastVisibilityParams
  108. }
  109. // broadcastVisibilityParams is the list of parameters passed at the mock
  110. // BuddyBroadcaster.BroadcastVisibility call site
  111. type broadcastVisibilityParams []struct {
  112. you *state.SessionInstance
  113. filter []state.IdentScreenName
  114. sendDepartures bool
  115. err error
  116. }
  117. // chatRoomRetrieverParams is a helper struct that contains mock parameters for
  118. // ChatRoomRetriever methods
  119. type chatRoomRetrieverParams struct {
  120. allChatRoomsParams
  121. }
  122. // allChatRoomsParams is the list of parameters passed at the mock
  123. // ChatRoomRetriever.AllChatRooms call site
  124. type allChatRoomsParams []struct {
  125. exchange uint16
  126. result []state.ChatRoom
  127. err error
  128. }
  129. // chatRoomDeleterParams is a helper struct that contains mock parameters for
  130. // ChatRoomDeleter methods
  131. type chatRoomDeleterParams struct {
  132. deleteChatRoomsParams
  133. }
  134. // deleteChatRoomsParams is the list of parameters passed at the mock
  135. // ChatRoomDeleter.DeleteChatRooms call site
  136. type deleteChatRoomsParams []struct {
  137. exchange uint16
  138. names []string
  139. err error
  140. }
  141. // chatSessionRetrieverParams is a helper struct that contains mock parameters for
  142. // ChatSessionRetriever methods
  143. type chatSessionRetrieverParams struct {
  144. chatSessionRetrieverAllSessionsParams
  145. }
  146. // chatSessionRetrieverAllSessionsParams is the list of parameters passed at the mock
  147. // ChatSessionRetriever.AllSessions call site
  148. type chatSessionRetrieverAllSessionsParams []struct {
  149. cookie string
  150. result []*state.Session
  151. }
  152. type directoryManagerParams struct {
  153. categoriesParams
  154. createCategoryParams
  155. createKeywordParams
  156. deleteCategoryParams
  157. deleteKeywordParams
  158. keywordsByCategoryParams
  159. }
  160. // categoriesParams is the list of parameters passed at the mock
  161. // DirectoryManager.Categories call site
  162. type categoriesParams []struct {
  163. result []state.Category
  164. err error
  165. }
  166. // createCategoryParams is the list of parameters passed at the mock
  167. // DirectoryManager.CreateCategory call site
  168. type createCategoryParams []struct {
  169. name string
  170. result state.Category
  171. err error
  172. }
  173. // createKeywordParams is the list of parameters passed at the mock
  174. // DirectoryManager.CreateKeyword call site
  175. type createKeywordParams []struct {
  176. name string
  177. categoryID uint8
  178. result state.Keyword
  179. err error
  180. }
  181. // deleteCategoryParams is the list of parameters passed at the mock
  182. // DirectoryManager.DeleteCategory call site
  183. type deleteCategoryParams []struct {
  184. categoryID uint8
  185. err error
  186. }
  187. // deleteKeywordParams is the list of parameters passed at the mock
  188. // DirectoryManager.DeleteKeyword call site
  189. type deleteKeywordParams []struct {
  190. id uint8
  191. err error
  192. }
  193. // keywordsByCategoryParams is the list of parameters passed at the mock
  194. // DirectoryManager.KeywordsByCategory call site
  195. type keywordsByCategoryParams []struct {
  196. categoryID uint8
  197. result []state.Keyword
  198. err error
  199. }
  200. // feedBagRetrieverParams is a helper struct that contains mock parameters for
  201. // FeedBagRetriever methods
  202. type feedBagRetrieverParams struct {
  203. buddyIconMetadataParams
  204. }
  205. // buddyIconMetadataParams is the list of parameters passed at the mock
  206. // FeedBagRetriever.BuddyIconMetadataParams call site
  207. type buddyIconMetadataParams []struct {
  208. screenName state.IdentScreenName
  209. result *wire.BARTID
  210. err error
  211. }
  212. // feedbagManagerParams is a helper struct that contains mock parameters for
  213. // FeedbagManager methods
  214. type feedbagManagerParams struct {
  215. feedbagParams
  216. feedbagUpsertParams
  217. feedbagDeleteParams
  218. }
  219. // feedbagParams is the list of parameters passed at the mock
  220. // FeedbagManager.Feedbag call site
  221. type feedbagParams []struct {
  222. screenName state.IdentScreenName
  223. result []wire.FeedbagItem
  224. err error
  225. }
  226. // feedbagUpsertParams is the list of parameters passed at the mock
  227. // FeedbagManager.FeedbagUpsert call site
  228. type feedbagUpsertParams []struct {
  229. screenName state.IdentScreenName
  230. items []wire.FeedbagItem
  231. err error
  232. }
  233. // feedbagDeleteParams is the list of parameters passed at the mock
  234. // FeedbagManager.FeedbagDelete call site
  235. type feedbagDeleteParams []struct {
  236. screenName state.IdentScreenName
  237. items []wire.FeedbagItem
  238. err error
  239. }
  240. // messageRelayerParams is a helper struct that contains mock parameters for
  241. // MessageRelayer methods
  242. type messageRelayerParams struct {
  243. relayToScreenNameParams
  244. }
  245. // relayToScreenNameParams is the list of parameters passed at the mock
  246. // MessageRelayer.RelayToScreenName call site
  247. type relayToScreenNameParams []struct {
  248. screenName state.IdentScreenName
  249. msg wire.SNACMessage
  250. }
  251. // profileRetrieverParams is a helper struct that contains mock parameters for
  252. // ProfileRetriever methods
  253. type profileRetrieverParams struct {
  254. retrieveProfileParams
  255. }
  256. // retrieveProfileParams is the list of parameters passed at the mock
  257. // ProfileRetriever.Profile call site
  258. type retrieveProfileParams []struct {
  259. screenName state.IdentScreenName
  260. result state.UserProfile
  261. err error
  262. }
  263. // sessionRetrieverParams is a helper struct that contains mock parameters for
  264. // SessionRetriever methods
  265. type sessionRetrieverParams struct {
  266. retrieveSessionByNameParams
  267. }
  268. // retrieveSessionByNameParams is the list of parameters passed at the mock
  269. // SessionRetriever.RetrieveSession call site
  270. type retrieveSessionByNameParams []struct {
  271. screenName state.IdentScreenName
  272. result *state.Session
  273. }
  274. // userManagerParams is a helper struct that contains mock parameters for
  275. // UserManager methods
  276. type userManagerParams struct {
  277. allUsersParams
  278. deleteUserParams
  279. getUserParams
  280. setUserPasswordParams
  281. }
  282. // allUsersParams is the list of parameters passed at the mock
  283. // UserManager.AllUsers call site
  284. type allUsersParams []struct {
  285. result []state.User
  286. err error
  287. }
  288. // deleteUserParams is the list of parameters passed at the mock
  289. // UserManager.DeleteUser call site
  290. type deleteUserParams []struct {
  291. screenName state.IdentScreenName
  292. err error
  293. }
  294. // getUserParams is the list of parameters passed at the mock
  295. // UserManager.User call site
  296. type getUserParams []struct {
  297. screenName state.IdentScreenName
  298. result *state.User
  299. err error
  300. }
  301. // setUserPasswordParams is the list of parameters passed at the mock
  302. // UserManager.SetUserPassword call site
  303. type setUserPasswordParams []struct {
  304. screenName state.IdentScreenName
  305. newPassword string
  306. err error
  307. }
  308. // matchContext matches any instance of Context interface.
  309. func matchContext() interface{} {
  310. return mock.MatchedBy(func(ctx any) bool {
  311. _, ok := ctx.(context.Context)
  312. return ok
  313. })
  314. }