helpers_test.go 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. package foodgroup
  2. import (
  3. "context"
  4. "net/mail"
  5. "net/netip"
  6. "time"
  7. "github.com/stretchr/testify/mock"
  8. "github.com/mk6i/open-oscar-server/state"
  9. "github.com/mk6i/open-oscar-server/wire"
  10. )
  11. // mockParams is a helper struct that centralizes mock function call parameters
  12. // in one place for a table test
  13. type mockParams struct {
  14. accountManagerParams
  15. bartItemManagerParams
  16. buddyBroadcasterParams
  17. contactPreAuthorizerParams
  18. buddyAddedNotifierDeduperParams
  19. relationshipFetcherParams
  20. chatMessageRelayerParams
  21. chatRoomRegistryParams
  22. cookieBakerParams
  23. feedbagManagerParams
  24. icqUserFinderParams
  25. icqUserUpdaterParams
  26. clientSideBuddyListManagerParams
  27. messageRelayerParams
  28. offlineMessageManagerParams
  29. profileManagerParams
  30. sessionRegistryParams
  31. sessionRetrieverParams
  32. userManagerParams
  33. }
  34. // contactPreAuthorizerParams is a helper struct that contains mock parameters for
  35. // ContactPreAuthorizer methods
  36. type contactPreAuthorizerParams struct {
  37. recordPreAuthParams
  38. requiresAuthorizationParams
  39. }
  40. // recordPreAuthParams is the list of parameters passed at the mock
  41. // ContactPreAuthorizer.RecordPreAuth call site
  42. type recordPreAuthParams []struct {
  43. owner state.IdentScreenName
  44. buddy state.IdentScreenName
  45. err error
  46. }
  47. // requiresAuthorizationParams is the list of parameters passed at the mock
  48. // ContactPreAuthorizer.RequiresAuthorization call site
  49. type requiresAuthorizationParams []struct {
  50. owner state.IdentScreenName
  51. requester state.IdentScreenName
  52. result bool
  53. err error
  54. }
  55. // buddyAddedNotifierDeduperParams is a helper struct that contains mock parameters
  56. // for BuddyAddedNotifierDeduper methods.
  57. type buddyAddedNotifierDeduperParams struct {
  58. hasBuddyAddedNotificationParams
  59. recordBuddyAddedNotificationParams
  60. }
  61. // hasBuddyAddedNotificationParams is the list of parameters passed at the mock
  62. // BuddyAddedNotifierDeduper.HasBuddyAddedNotification call site.
  63. type hasBuddyAddedNotificationParams []struct {
  64. granter state.IdentScreenName
  65. requester state.IdentScreenName
  66. result bool
  67. err error
  68. }
  69. // recordBuddyAddedNotificationParams is the list of parameters passed at the mock
  70. // BuddyAddedNotifierDeduper.RecordBuddyAddedNotification call site.
  71. type recordBuddyAddedNotificationParams []struct {
  72. granter state.IdentScreenName
  73. requester state.IdentScreenName
  74. err error
  75. }
  76. // relationshipFetcherParams is a helper struct that contains mock parameters
  77. // for RelationshipFetcher methods
  78. type relationshipFetcherParams struct {
  79. allRelationshipsParams
  80. relationshipParams
  81. }
  82. // allRelationshipsParams is the list of parameters passed at the mock
  83. // RelationshipFetcher.AllRelationships call site
  84. type allRelationshipsParams []struct {
  85. screenName state.IdentScreenName
  86. filter []state.IdentScreenName
  87. result []state.Relationship
  88. err error
  89. }
  90. // relationshipParams is the list of parameters passed at the mock
  91. // RelationshipFetcher.Relationship call site
  92. type relationshipParams []struct {
  93. me state.IdentScreenName
  94. them state.IdentScreenName
  95. result state.Relationship
  96. err error
  97. }
  98. // offlineMessageManagerParams is a helper struct that contains mock parameters for
  99. // OfflineMessageManager methods
  100. type offlineMessageManagerParams struct {
  101. deleteMessagesParams
  102. retrieveMessagesParams
  103. saveMessageParams
  104. setOfflineMsgCountParams
  105. }
  106. // deleteMessagesParams is the list of parameters passed at the mock
  107. // OfflineMessageManager.DeleteMessages call site
  108. type deleteMessagesParams []struct {
  109. recipIn state.IdentScreenName
  110. err error
  111. }
  112. // deleteMessagesParams is the list of parameters passed at the mock
  113. // OfflineMessageManager.RetrieveMessages call site
  114. type retrieveMessagesParams []struct {
  115. recipIn state.IdentScreenName
  116. messagesOut []state.OfflineMessage
  117. err error
  118. }
  119. // deleteMessagesParams is the list of parameters passed at the mock
  120. // OfflineMessageManager.SaveMessage call site
  121. type saveMessageParams []struct {
  122. offlineMessageIn state.OfflineMessage
  123. countOut int
  124. err error
  125. }
  126. // setOfflineMsgCountParams is the list of parameters passed at the mock
  127. // OfflineMessageManager.SetOfflineMsgCount call site
  128. type setOfflineMsgCountParams []struct {
  129. screenName state.IdentScreenName
  130. count int
  131. err error
  132. }
  133. // sessionRetrieverParams is a helper struct that contains mock parameters for
  134. // SessionRetriever methods
  135. type sessionRetrieverParams struct {
  136. retrieveSessionParams
  137. }
  138. // retrieveSessionParams is the list of parameters passed at the mock
  139. // SessionRetriever.RetrieveSession call site
  140. type retrieveSessionParams []struct {
  141. screenName state.IdentScreenName
  142. result *state.Session
  143. }
  144. // icqUserFinderParams is a helper struct that contains mock parameters for
  145. // ICQUserFinder methods
  146. type icqUserFinderParams struct {
  147. findByDetailsParams
  148. findByEmailParams
  149. findByInterestsParams
  150. findByUINParams
  151. searchICQUsersParams
  152. }
  153. // findByUINParams is the list of parameters passed at the mock
  154. // ICQUserFinder.FindByUIN call site
  155. type findByUINParams []struct {
  156. UIN uint32
  157. result state.User
  158. err error
  159. }
  160. // findByEmailParams is the list of parameters passed at the mock
  161. // ICQUserFinder.FindByEmail call site
  162. type findByEmailParams []struct {
  163. email string
  164. result state.User
  165. err error
  166. }
  167. // setBasicInfoParams is the list of parameters passed at the mock
  168. // ICQUserFinder.FindByDetails call site
  169. type findByDetailsParams []struct {
  170. firstName string
  171. lastName string
  172. nickName string
  173. result []state.User
  174. err error
  175. }
  176. // setBasicInfoParams is the list of parameters passed at the mock
  177. // ICQUserFinder.FindByInterests call site
  178. type findByInterestsParams []struct {
  179. code uint16
  180. keywords []string
  181. result []state.User
  182. err error
  183. }
  184. // searchICQUsersParams is the list of parameters passed at the mock
  185. // ICQUserFinder.SearchICQUsers call site.
  186. type searchICQUsersParams []struct {
  187. criteria state.ICQUserSearchCriteria
  188. result []state.User
  189. err error
  190. }
  191. // icqUserUpdaterParams is a helper struct that contains mock parameters for
  192. // ICQUserUpdater methods
  193. type icqUserUpdaterParams struct {
  194. setAffiliationsParams
  195. setBasicInfoParams
  196. setFullInfoParams
  197. setInterestsParams
  198. setMoreInfoParams
  199. setPermissionsParams
  200. setUserNotesParams
  201. setWorkInfoParams
  202. }
  203. // setAffiliationsParams is the list of parameters passed at the mock
  204. // ICQUserUpdater.SetAffiliations call site
  205. type setAffiliationsParams []struct {
  206. name state.IdentScreenName
  207. data state.ICQAffiliations
  208. err error
  209. }
  210. // setInterestsParams is the list of parameters passed at the mock
  211. // ICQUserUpdater.SetInterests call site
  212. type setInterestsParams []struct {
  213. name state.IdentScreenName
  214. data state.ICQInterests
  215. err error
  216. }
  217. // setUserNotesParams is the list of parameters passed at the mock
  218. // ICQUserUpdater.SetUserNotes call site
  219. type setUserNotesParams []struct {
  220. name state.IdentScreenName
  221. data state.ICQUserNotes
  222. err error
  223. }
  224. // setBasicInfoParams is the list of parameters passed at the mock
  225. // ICQUserUpdater.SetBasicInfo call site
  226. type setBasicInfoParams []struct {
  227. name state.IdentScreenName
  228. data state.ICQBasicInfo
  229. err error
  230. }
  231. // setFullInfoParams is the list of parameters passed at the mock
  232. // ICQUserUpdater.SetICQInfo call site
  233. type setFullInfoParams []struct {
  234. name state.IdentScreenName
  235. info state.ICQInfo
  236. err error
  237. }
  238. // setWorkInfoParams is the list of parameters passed at the mock
  239. // ICQUserUpdater.SetWorkInfo call site
  240. type setWorkInfoParams []struct {
  241. name state.IdentScreenName
  242. data state.ICQWorkInfo
  243. err error
  244. }
  245. // setMoreInfoParams is the list of parameters passed at the mock
  246. // ICQUserUpdater.SetMoreInfo call site
  247. type setMoreInfoParams []struct {
  248. name state.IdentScreenName
  249. data state.ICQMoreInfo
  250. err error
  251. }
  252. // setPermissionsParams is the list of parameters passed at the mock
  253. // ICQUserUpdater.SetPermissions call site
  254. type setPermissionsParams []struct {
  255. name state.IdentScreenName
  256. data state.ICQPermissions
  257. err error
  258. }
  259. // bartItemManagerParams is a helper struct that contains mock parameters for
  260. // BARTItemManager methods
  261. type bartItemManagerParams struct {
  262. bartItemManagerRetrieveParams
  263. bartItemManagerUpsertParams
  264. buddyIconMetadataParams
  265. }
  266. // bartItemManagerRetrieveParams is the list of parameters passed at the mock
  267. // BARTItemManager.BuddyIcon call site
  268. type bartItemManagerRetrieveParams []struct {
  269. itemHash []byte
  270. result []byte
  271. err error
  272. }
  273. // bartItemManagerUpsertParams is the list of parameters passed at the mock
  274. // BARTItemManager.SetBuddyIcon call site
  275. type bartItemManagerUpsertParams []struct {
  276. itemHash []byte
  277. payload []byte
  278. bartType uint16
  279. err error
  280. }
  281. // buddyIconMetadataParams is the list of parameters passed at the mock
  282. // BARTItemManager.BuddyIconMetadata call site
  283. type buddyIconMetadataParams []struct {
  284. screenName state.IdentScreenName
  285. result *wire.BARTID
  286. err error
  287. }
  288. // userManagerParams is a helper struct that contains mock parameters for
  289. // UserManager methods
  290. type userManagerParams struct {
  291. getUserParams
  292. }
  293. // getUserParams is the list of parameters passed at the mock
  294. // UserManager.User call site
  295. type getUserParams []struct {
  296. screenName state.IdentScreenName
  297. result *state.User
  298. err error
  299. }
  300. // sessionRegistryParams is a helper struct that contains mock parameters for
  301. // SessionRegistry methods
  302. type sessionRegistryParams struct {
  303. addSessionParams
  304. removeSessionParams
  305. }
  306. // addSessionParams is the list of parameters passed at the mock
  307. // SessionRegistry.AddSession call site
  308. type addSessionParams []struct {
  309. screenName state.DisplayScreenName
  310. doMultiSess bool
  311. result *state.SessionInstance
  312. err error
  313. }
  314. // removeSessionParams is the list of parameters passed at the mock
  315. // SessionRegistry.RemoveSession call site
  316. type removeSessionParams []struct {
  317. screenName state.IdentScreenName
  318. }
  319. // feedbagManagerParams is a helper struct that contains mock parameters for
  320. // FeedbagManager methods
  321. type feedbagManagerParams struct {
  322. adjacentUsersParams
  323. feedbagUpsertParams
  324. feedbagParams
  325. feedbagLastModifiedParams
  326. feedbagDeleteParams
  327. useParams
  328. }
  329. // adjacentUsersParams is the list of parameters passed at the mock
  330. // FeedbagManager.AdjacentUsers call site
  331. type adjacentUsersParams []struct {
  332. screenName state.IdentScreenName
  333. users []state.IdentScreenName
  334. err error
  335. }
  336. // feedbagUpsertParams is the list of parameters passed at the mock
  337. // FeedbagManager.FeedbagUpsert call site
  338. type feedbagUpsertParams []struct {
  339. screenName state.IdentScreenName
  340. items []wire.FeedbagItem
  341. }
  342. // useParams is the list of parameters passed at the mock
  343. // FeedbagManager.Use call site
  344. type useParams []struct {
  345. screenName state.IdentScreenName
  346. }
  347. // feedbagParams is the list of parameters passed at the mock
  348. // FeedbagManager.Feedbag call site
  349. type feedbagParams []struct {
  350. screenName state.IdentScreenName
  351. results []wire.FeedbagItem
  352. err error
  353. }
  354. // feedbagLastModifiedParams is the list of parameters passed at the mock
  355. // FeedbagManager.FeedbagLastModified call site
  356. type feedbagLastModifiedParams []struct {
  357. screenName state.IdentScreenName
  358. result time.Time
  359. }
  360. // feedbagDeleteParams is the list of parameters passed at the mock
  361. // FeedbagManager.FeedbagDelete call site
  362. type feedbagDeleteParams []struct {
  363. screenName state.IdentScreenName
  364. items []wire.FeedbagItem
  365. }
  366. // messageRelayerParams is a helper struct that contains mock parameters for
  367. // MessageRelayer methods
  368. type messageRelayerParams struct {
  369. relayToScreenNamesParams
  370. relayToScreenNameParams
  371. relayToOtherInstancesParams
  372. relayToScreenNameActiveOnlyParams
  373. relayToSelfParams
  374. }
  375. // relayToSelfParams is the list of parameters passed at the mock
  376. // MessageRelayer.RelayToSelf call site
  377. type relayToSelfParams []struct {
  378. screenName state.IdentScreenName
  379. message wire.SNACMessage
  380. }
  381. // relayToScreenNamesParams is the list of parameters passed at the mock
  382. // MessageRelayer.RelayToScreenNames call site
  383. type relayToScreenNamesParams []struct {
  384. screenNames []state.IdentScreenName
  385. message wire.SNACMessage
  386. }
  387. // relayToScreenNameParams is the list of parameters passed at the mock
  388. // MessageRelayer.RelayToScreenName call site
  389. type relayToScreenNameParams []struct {
  390. screenName state.IdentScreenName
  391. message wire.SNACMessage
  392. }
  393. // relayToOtherInstancesParams is the list of parameters passed at the mock
  394. // MessageRelayer.RelayToOtherInstances call site
  395. type relayToOtherInstancesParams []struct {
  396. screenName state.IdentScreenName
  397. message wire.SNACMessage
  398. }
  399. // relayToScreenNameActiveOnlyParams is the list of parameters passed at the mock
  400. // MessageRelayer.RelayToScreenNameActiveOnly call site
  401. type relayToScreenNameActiveOnlyParams []struct {
  402. screenName state.IdentScreenName
  403. message wire.SNACMessage
  404. }
  405. // profileManagerParams is a helper struct that contains mock parameters for
  406. // ProfileManager methods
  407. type profileManagerParams struct {
  408. findByAIMEmailParams
  409. findByAIMKeywordParams
  410. findByAIMNameAndAddrParams
  411. getUserParams
  412. interestListParams
  413. retrieveProfileParams
  414. setDirectoryInfoParams
  415. setKeywordsParams
  416. setProfileParams
  417. }
  418. // findByAIMEmailParams is the list of parameters passed at the mock
  419. // ProfileManager.FindByAIMEmail call site
  420. type findByAIMEmailParams []struct {
  421. email string
  422. result state.User
  423. err error
  424. }
  425. // findByAIMKeywordParams is the list of parameters passed at the mock
  426. // ProfileManager.FindByAIMKeyword call site
  427. type findByAIMKeywordParams []struct {
  428. keyword string
  429. result []state.User
  430. err error
  431. }
  432. // findByAIMNameAndAddrParams is the list of parameters passed at the mock
  433. // ProfileManager.FindByAIMNameAndAddr call site
  434. type findByAIMNameAndAddrParams []struct {
  435. info state.AIMNameAndAddr
  436. result []state.User
  437. err error
  438. }
  439. // interestListParams is the list of parameters passed at the mock
  440. // ProfileManager.InterestList call site
  441. type interestListParams []struct {
  442. result []wire.ODirKeywordListItem
  443. err error
  444. }
  445. // setDirectoryInfoParams is the list of parameters passed at the mock
  446. // ProfileManager.SetDirectoryInfo call site
  447. type setDirectoryInfoParams []struct {
  448. screenName state.IdentScreenName
  449. info state.AIMNameAndAddr
  450. err error
  451. }
  452. // retrieveProfileParams is the list of parameters passed at the mock
  453. // ProfileManager.Profile call site
  454. type retrieveProfileParams []struct {
  455. screenName state.IdentScreenName
  456. result state.UserProfile
  457. err error
  458. }
  459. // setProfileParams is the list of parameters passed at the mock
  460. // ProfileManager.SetProfile call site
  461. type setProfileParams []struct {
  462. screenName state.IdentScreenName
  463. body state.UserProfile
  464. }
  465. // setKeywordsParams is the list of parameters passed at the mock
  466. // ProfileManager.SetKeywords call site
  467. type setKeywordsParams []struct {
  468. screenName state.IdentScreenName
  469. keywords [5]string
  470. err error
  471. }
  472. // chatMessageRelayerParams is a helper struct that contains mock parameters
  473. // for ChatMessageRelayer methods
  474. type chatMessageRelayerParams struct {
  475. chatAllSessionsParams
  476. chatRelayToAllExceptParams
  477. chatRelayToScreenNameParams
  478. }
  479. // chatAllSessionsParams is the list of parameters passed at the mock
  480. // ChatMessageRelayer.AllSessions call site
  481. type chatAllSessionsParams []struct {
  482. cookie string
  483. sessions []*state.Session
  484. err error
  485. }
  486. // chatRelayToAllExceptParams is the list of parameters passed at the mock
  487. // ChatMessageRelayer.RelayToAllExcept call site
  488. type chatRelayToAllExceptParams []struct {
  489. cookie string
  490. screenName state.IdentScreenName
  491. message wire.SNACMessage
  492. err error
  493. }
  494. // chatRelayToScreenNameParams is the list of parameters passed at the mock
  495. // ChatMessageRelayer.RelayToScreenName call site
  496. type chatRelayToScreenNameParams []struct {
  497. cookie string
  498. screenName state.IdentScreenName
  499. message wire.SNACMessage
  500. err error
  501. }
  502. // clientSideBuddyListManagerParams is a helper struct that contains mock
  503. // parameters for ClientSideBuddyListManager methods
  504. type clientSideBuddyListManagerParams struct {
  505. addBuddyParams
  506. deleteBuddyParams
  507. denyBuddyParams
  508. permitBuddyParams
  509. removeDenyBuddyParams
  510. removePermitBuddyParams
  511. setPDModeParams
  512. }
  513. // legacyBuddiesParams is the list of parameters passed at the mock
  514. // ClientSideBuddyListManager.AddBuddy call site
  515. type addBuddyParams []struct {
  516. me state.IdentScreenName
  517. them state.IdentScreenName
  518. err error
  519. }
  520. // legacyBuddiesParams is the list of parameters passed at the mock
  521. // ClientSideBuddyListManager.RemoveBuddy call site
  522. type deleteBuddyParams []struct {
  523. me state.IdentScreenName
  524. them state.IdentScreenName
  525. err error
  526. }
  527. // deleteUserParams is the list of parameters passed at the mock
  528. // ClientSideBuddyListManager.RemoveBuddy call site
  529. type denyBuddyParams []struct {
  530. me state.IdentScreenName
  531. them state.IdentScreenName
  532. err error
  533. }
  534. // permitBuddyParams is the list of parameters passed at the mock
  535. // ClientSideBuddyListManager.PermitBuddy call site
  536. type permitBuddyParams []struct {
  537. me state.IdentScreenName
  538. them state.IdentScreenName
  539. err error
  540. }
  541. // removeDenyBuddyParams is the list of parameters passed at the mock
  542. // ClientSideBuddyListManager.RemoveDenyBuddy call site
  543. type removeDenyBuddyParams []struct {
  544. me state.IdentScreenName
  545. them state.IdentScreenName
  546. err error
  547. }
  548. // removePermitBuddyParams is the list of parameters passed at the mock
  549. // ClientSideBuddyListManager.RemovePermitBuddy call site
  550. type removePermitBuddyParams []struct {
  551. me state.IdentScreenName
  552. them state.IdentScreenName
  553. err error
  554. }
  555. // setPDModeParams is the list of parameters passed at the mock
  556. // ClientSideBuddyListManager.SetPDMode call site
  557. type setPDModeParams []struct {
  558. userScreenName state.IdentScreenName
  559. pdMode wire.FeedbagPDMode
  560. err error
  561. }
  562. // cookieBakerParams is a helper struct that contains mock parameters for
  563. // CookieBaker methods
  564. type cookieBakerParams struct {
  565. cookieIssueParams
  566. }
  567. // cookieIssueParams is the list of parameters passed at the mock
  568. // CookieBaker.Issue call site
  569. type cookieIssueParams []struct {
  570. dataIn []byte
  571. cookieOut []byte
  572. err error
  573. }
  574. // accountManagerParams is a helper struct that contains mock parameters for
  575. // accountManager methods
  576. type accountManagerParams struct {
  577. accountManagerUpdateDisplayScreenNameParams
  578. accountManagerUpdateEmailAddressParams
  579. accountManagerEmailAddressParams
  580. accountManagerUpdateRegStatusParams
  581. accountManagerRegStatusParams
  582. accountManagerUpdateConfirmStatusParams
  583. accountManagerConfirmStatusParams
  584. accountManagerUserParams
  585. accountManagerSetUserPasswordParams
  586. }
  587. // accountManagerUpdateDisplayScreenNameParams is the list of parameters passed at the mock
  588. // accountManager.UpdateDisplayScreenName call site
  589. type accountManagerUpdateDisplayScreenNameParams []struct {
  590. displayScreenName state.DisplayScreenName
  591. err error
  592. }
  593. // accountManagerUpdateEmailAddressParams is the list of parameters passed at the mock
  594. // accountManager.UpdateEmailAddress call site
  595. type accountManagerUpdateEmailAddressParams []struct {
  596. emailAddress *mail.Address
  597. screenName state.IdentScreenName
  598. err error
  599. }
  600. // accountManagerEmailAddressParams is the list of parameters passed at the mock
  601. // accountManager.EmailAddress call site
  602. type accountManagerEmailAddressParams []struct {
  603. screenName state.IdentScreenName
  604. emailAddress *mail.Address
  605. err error
  606. }
  607. // accountManagerUpdateRegStatusParams is the list of parameters passed at the mock
  608. // accountManager.UpdateRegStatus call site
  609. type accountManagerUpdateRegStatusParams []struct {
  610. regStatus uint16
  611. screenName state.IdentScreenName
  612. err error
  613. }
  614. // accountManagerRegStatusParams is the list of parameters passed at the mock
  615. // accountManager.RegStatus call site
  616. type accountManagerRegStatusParams []struct {
  617. screenName state.IdentScreenName
  618. regStatus uint16
  619. err error
  620. }
  621. // accountManagerUpdateConfirmStatusParams is the list of parameters passed at the mock
  622. // accountManager.UpdateConfirmStatus call site
  623. type accountManagerUpdateConfirmStatusParams []struct {
  624. confirmStatus bool
  625. screenName state.IdentScreenName
  626. err error
  627. }
  628. // accountManagerConfirmStatusParams is the list of parameters passed at the mock
  629. // accountManager.ConfirmStatus call site
  630. type accountManagerConfirmStatusParams []struct {
  631. screenName state.IdentScreenName
  632. confirmStatus bool
  633. err error
  634. }
  635. // accountManagerUserParams is the list of parameters passed at the mock
  636. // accountManager.User call site
  637. type accountManagerUserParams []struct {
  638. screenName state.IdentScreenName
  639. result *state.User
  640. err error
  641. }
  642. // accountManagerSetUserPasswordParams is the list of parameters passed at the mock
  643. // accountManager.SetUserPassword call site
  644. type accountManagerSetUserPasswordParams []struct {
  645. screenName state.IdentScreenName
  646. password string
  647. err error
  648. }
  649. // buddyBroadcasterParams is a helper struct that contains mock parameters for
  650. // buddyBroadcaster methods
  651. type buddyBroadcasterParams struct {
  652. broadcastBuddyArrivedParams
  653. broadcastBuddyDepartedParams
  654. broadcastVisibilityParams
  655. }
  656. // broadcastVisibilityParams is the list of parameters passed at the mock
  657. // buddyBroadcaster.BroadcastVisibility call site
  658. type broadcastVisibilityParams []struct {
  659. from state.IdentScreenName
  660. filter []state.IdentScreenName
  661. doSendDepartures bool
  662. err error
  663. }
  664. // broadcastBuddyArrivedParams is the list of parameters passed at the mock
  665. // buddyBroadcaster.BroadcastBuddyArrived call site
  666. type broadcastBuddyArrivedParams []struct {
  667. screenName state.DisplayScreenName
  668. err error
  669. bodyMatcher func(snac wire.TLVUserInfo) bool
  670. }
  671. // broadcastBuddyDepartedParams is the list of parameters passed at the mock
  672. // buddyBroadcaster.BroadcastBuddyDeparted call site
  673. type broadcastBuddyDepartedParams []struct {
  674. screenName state.IdentScreenName
  675. err error
  676. }
  677. // chatRoomRegistryParams is a helper struct that contains mock parameters for
  678. // ChatRoomRegistry methods
  679. type chatRoomRegistryParams struct {
  680. chatRoomByCookieParams
  681. chatRoomByNameParams
  682. createChatRoomParams
  683. }
  684. // chatRoomByCookieParams is the list of parameters passed at the mock
  685. // ChatRoomRegistry.ChatRoomByCookie call site
  686. type chatRoomByCookieParams []struct {
  687. cookie string
  688. room state.ChatRoom
  689. err error
  690. }
  691. // chatRoomByCookieParams is the list of parameters passed at the mock
  692. // ChatRoomRegistry.ChatRoomByName call site
  693. type chatRoomByNameParams []struct {
  694. exchange uint16
  695. name string
  696. room state.ChatRoom
  697. err error
  698. }
  699. // createChatRoomParams is the list of parameters passed at the mock
  700. // ChatRoomRegistry.CreateChatRoom call site
  701. type createChatRoomParams []struct {
  702. room *state.ChatRoom
  703. err error
  704. }
  705. // sessOptWarning sets a warning level on the session object
  706. func sessOptWarning(level int16) func(instance *state.SessionInstance) {
  707. return func(instance *state.SessionInstance) {
  708. instance.Session().SetWarning(uint16(level))
  709. }
  710. }
  711. // sessOptCannedAwayMessage sets a canned away message ("this is my away
  712. // message!") on the session object
  713. func sessOptCannedAwayMessage(instance *state.SessionInstance) {
  714. instance.SetAwayMessage("this is my away message!")
  715. }
  716. // sessOptUserInfoFlag sets a user info flag on the session object
  717. func sessOptUserInfoFlag(flag uint16) func(instance *state.SessionInstance) {
  718. return func(instance *state.SessionInstance) {
  719. instance.SetUserInfoFlag(flag)
  720. }
  721. }
  722. // sessOptCannedSignonTime sets a canned sign-on time (1696790127565) on the
  723. // session object
  724. func sessOptCannedSignonTime(instance *state.SessionInstance) {
  725. instance.Session().SetSignonTime(time.UnixMilli(1696790127565))
  726. }
  727. // sessOptChatRoomCookie sets cookie on the session object
  728. func sessOptChatRoomCookie(cookie string) func(instance *state.SessionInstance) {
  729. return func(instance *state.SessionInstance) {
  730. instance.Session().SetChatRoomCookie(cookie)
  731. }
  732. }
  733. // sessOptBot sets the bot flag to true on the session
  734. // object
  735. func sessOptBot(instance *state.SessionInstance) {
  736. instance.SetUserInfoFlag(wire.OServiceUserFlagBot)
  737. }
  738. // sessOptInvisible sets the invisible flag to true on the session
  739. // object
  740. func sessOptInvisible(instance *state.SessionInstance) {
  741. instance.SetUserStatusBitmask(wire.OServiceUserStatusInvisible)
  742. }
  743. // sessOptIdle sets the idle flag to dur on the session object
  744. func sessOptIdle(dur time.Duration) func(instance *state.SessionInstance) {
  745. return func(instance *state.SessionInstance) {
  746. instance.SetIdle(dur)
  747. }
  748. }
  749. // sessOptSignonComplete sets the sign on complete flag to true
  750. func sessOptSignonComplete(instance *state.SessionInstance) {
  751. instance.SetSignonComplete()
  752. }
  753. // sessOptContactsInit sets the contacts-init flag to true
  754. func sessOptContactsInit(instance *state.SessionInstance) {
  755. instance.SetContactsInit()
  756. }
  757. // sessOptCaps sets caps
  758. func sessOptUIN(UIN uint32) func(instance *state.SessionInstance) {
  759. return func(instance *state.SessionInstance) {
  760. instance.Session().SetUIN(UIN)
  761. }
  762. }
  763. // sessOptCaps sets caps
  764. func sessOptWantTypingEvents(instance *state.SessionInstance) {
  765. instance.Session().SetTypingEventsEnabled(true)
  766. }
  767. // sessOptMultiConnFlag sets the multi-connection flag on the session instance
  768. func sessOptMultiConnFlag(flag wire.MultiConnFlag) func(instance *state.SessionInstance) {
  769. return func(instance *state.SessionInstance) {
  770. instance.SetMultiConnFlag(flag)
  771. }
  772. }
  773. // sessOptSetFoodGroupVersion sets food group versions
  774. func sessOptSetFoodGroupVersion(foodGroup uint16, version uint16) func(instance *state.SessionInstance) {
  775. return func(instance *state.SessionInstance) {
  776. var versions [wire.MDir + 1]uint16
  777. versions[foodGroup] = version
  778. instance.SetFoodGroupVersions(versions)
  779. }
  780. }
  781. // sessOptSetRateClasses sets rate limit classes
  782. func sessOptSetRateClasses(classes wire.RateLimitClasses) func(instance *state.SessionInstance) {
  783. return func(instance *state.SessionInstance) {
  784. instance.Session().SetRateClasses(time.Now(), classes)
  785. }
  786. }
  787. // sessOptMemberSince sets the member since timestamp on the session object.
  788. func sessOptMemberSince(t time.Time) func(instance *state.SessionInstance) {
  789. return func(instance *state.SessionInstance) {
  790. instance.Session().SetMemberSince(t)
  791. }
  792. }
  793. // sessOptSignonTime sets the sign-on time on the session object.
  794. func sessOptSignonTime(t time.Time) func(instance *state.SessionInstance) {
  795. return func(instance *state.SessionInstance) {
  796. instance.Session().SetSignonTime(t)
  797. }
  798. }
  799. // sessOptProfile sets profile
  800. func sessOptProfile(profile state.UserProfile) func(instance *state.SessionInstance) {
  801. return func(instance *state.SessionInstance) {
  802. instance.SetProfile(profile)
  803. }
  804. }
  805. // sessOptKerberosAuth indicates the session signed on
  806. func sessOptKerberosAuth(instance *state.SessionInstance) {
  807. instance.SetKerberosAuth(true)
  808. }
  809. // sessClientID sets the client ID
  810. func sessClientID(clientID string) func(instance *state.SessionInstance) {
  811. return func(instance *state.SessionInstance) {
  812. instance.SetClientID(clientID)
  813. }
  814. }
  815. // sessRemoteAddr sets the client's ip address / port
  816. func sessRemoteAddr(remoteAddr netip.AddrPort) func(instance *state.SessionInstance) {
  817. return func(instance *state.SessionInstance) {
  818. instance.SetRemoteAddr(&remoteAddr)
  819. }
  820. }
  821. // sessOptAllInactive makes all instances in the session group inactive (away/idle/closed)
  822. func sessOptAllInactive(instance *state.SessionInstance) {
  823. // Set away message to make instance inactive
  824. instance.SetAwayMessage("away message")
  825. // Also set idle to ensure it's inactive
  826. instance.SetIdle(time.Hour)
  827. }
  828. // sessOptSomeActive ensures some instances are active (not all inactive)
  829. func sessOptSomeActive(instance *state.SessionInstance) {
  830. // Don't set away message or idle - keep instance active
  831. // This simulates a multisession scenario where at least one instance is active
  832. }
  833. // sessOptClosed makes the session instance closed (inactive)
  834. func sessOptClosed(instance *state.SessionInstance) {
  835. instance.CloseInstance()
  836. }
  837. // sessOptMixedStates simulates a multisession scenario with mixed states
  838. // This would require multiple instances, but for testing purposes we'll just
  839. // keep the instance active to simulate having some active sessions
  840. func sessOptMixedStates(instance *state.SessionInstance) {
  841. // Keep instance active to simulate mixed states scenario
  842. // In a real multisession scenario, this would have multiple instances
  843. // with some active and some inactive
  844. }
  845. // sessOptFeedbagEnabled marks the instance as using the feedbag buddy list this sign-on.
  846. func sessOptFeedbagEnabled(instance *state.SessionInstance) {
  847. instance.Session().SetUsesFeedbag()
  848. }
  849. // sessBuddyIcon sets session buddy icon
  850. func sessOptBuddyIcon(icon wire.BARTID) func(instance *state.SessionInstance) {
  851. return func(instance *state.SessionInstance) {
  852. instance.Session().SetBuddyIcon(icon)
  853. }
  854. }
  855. // sessOptOfflineMsgCount sets the offline message count on the session object.
  856. func sessOptOfflineMsgCount(count int) func(instance *state.SessionInstance) {
  857. return func(instance *state.SessionInstance) {
  858. instance.Session().SetOfflineMsgCount(count)
  859. }
  860. }
  861. // newTestInstance creates a session object with 0 or more functional options
  862. // applied
  863. func newTestInstance(screenName state.DisplayScreenName, options ...func(instance *state.SessionInstance)) *state.SessionInstance {
  864. session := state.NewSession()
  865. session.SetIdentScreenName(screenName.IdentScreenName())
  866. session.SetDisplayScreenName(screenName)
  867. session.SetRateClasses(time.Now(), wire.DefaultRateLimitClasses())
  868. instance := session.AddInstance()
  869. for _, op := range options {
  870. op(instance)
  871. }
  872. return instance
  873. }
  874. // matchSession matches a mock call based session ident screen name.
  875. func matchSession(mustMatch state.IdentScreenName) interface{} {
  876. return mock.MatchedBy(func(s *state.SessionInstance) bool {
  877. return mustMatch == s.IdentScreenName()
  878. })
  879. }
  880. // matchUserSession matches a mock call for *state.Session by ident screen name.
  881. func matchUserSession(mustMatch state.IdentScreenName) interface{} {
  882. return mock.MatchedBy(func(s *state.Session) bool {
  883. return mustMatch == s.IdentScreenName()
  884. })
  885. }
  886. // matchContext matches any instance of Context interface.
  887. func matchContext() interface{} {
  888. return mock.MatchedBy(func(ctx any) bool {
  889. _, ok := ctx.(context.Context)
  890. return ok
  891. })
  892. }