helpers_test.go 11 KB

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