emails.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. const MOCK_DELAY = 1000
  2. const fakeUsersData = [
  3. {
  4. affiliation: {
  5. institution: {
  6. confirmed: true,
  7. id: 1,
  8. name: 'Overleaf',
  9. },
  10. licence: 'pro_plus',
  11. },
  12. confirmedAt: '2022-03-09T10:59:44.139Z',
  13. email: 'foo@overleaf.com',
  14. default: true,
  15. emailHasInstitutionLicence: true,
  16. },
  17. {
  18. confirmedAt: '2022-03-10T10:59:44.139Z',
  19. email: 'bar@overleaf.com',
  20. default: false,
  21. },
  22. {
  23. affiliation: {
  24. institution: {
  25. confirmed: true,
  26. id: 2,
  27. name: 'Overleaf',
  28. },
  29. licence: 'pro_plus',
  30. department: 'Art & Art History',
  31. role: 'Postdoc',
  32. },
  33. email: 'baz@overleaf.com',
  34. default: false,
  35. },
  36. {
  37. email: 'qux@overleaf.com',
  38. default: false,
  39. },
  40. ]
  41. const fakeReconfirmationUsersData = [
  42. {
  43. affiliation: {
  44. institution: {
  45. confirmed: true,
  46. isUniversity: true,
  47. id: 4,
  48. name: 'Reconfirmable Email Highlighted',
  49. },
  50. licence: 'pro_plus',
  51. inReconfirmNotificationPeriod: true,
  52. },
  53. email: 'reconfirmation-highlighted@overleaf.com',
  54. confirmedAt: '2022-03-09T10:59:44.139Z',
  55. default: false,
  56. },
  57. {
  58. affiliation: {
  59. institution: {
  60. confirmed: true,
  61. isUniversity: true,
  62. id: 4,
  63. name: 'Reconfirmable Emails Primary',
  64. },
  65. licence: 'pro_plus',
  66. inReconfirmNotificationPeriod: true,
  67. },
  68. email: 'reconfirmation-nonsso@overleaf.com',
  69. confirmedAt: '2022-03-09T10:59:44.139Z',
  70. default: true,
  71. },
  72. {
  73. affiliation: {
  74. institution: {
  75. confirmed: true,
  76. ssoEnabled: true,
  77. isUniversity: true,
  78. id: 3,
  79. name: 'Reconfirmable SSO',
  80. },
  81. licence: 'pro_plus',
  82. inReconfirmNotificationPeriod: true,
  83. },
  84. email: 'reconfirmation-sso@overleaf.com',
  85. confirmedAt: '2022-03-09T10:59:44.139Z',
  86. samlProviderId: 'reconfirmation-sso-provider-id',
  87. default: false,
  88. },
  89. {
  90. affiliation: {
  91. institution: {
  92. confirmed: true,
  93. isUniversity: true,
  94. ssoEnabled: true,
  95. id: 5,
  96. name: 'Reconfirmed SSO',
  97. },
  98. licence: 'pro_plus',
  99. },
  100. confirmedAt: '2022-03-09T10:59:44.139Z',
  101. email: 'sso@overleaf.com',
  102. samlProviderId: 'sso-reconfirmed-provider-id',
  103. default: false,
  104. },
  105. ]
  106. const fakeInstitutions = [
  107. {
  108. id: 9326,
  109. name: 'Unknown',
  110. country_code: 'al',
  111. departments: ['New department'],
  112. },
  113. ]
  114. const fakeInstitution = {
  115. id: 123,
  116. name: 'test',
  117. country_code: 'de',
  118. departments: [],
  119. team_id: null,
  120. }
  121. const bazFakeInstitution = {
  122. id: 2,
  123. name: 'Baz',
  124. country_code: 'de',
  125. departments: ['Custom department 1', 'Custom department 2'],
  126. team_id: null,
  127. }
  128. const fakeInstitutionDomain1 = [
  129. {
  130. university: {
  131. id: 1234,
  132. ssoEnabled: true,
  133. name: 'Auto Complete University',
  134. },
  135. hostname: 'autocomplete.edu',
  136. confirmed: true,
  137. },
  138. ]
  139. const fakeInstitutionDomain2 = [
  140. {
  141. university: {
  142. id: 5678,
  143. ssoEnabled: false,
  144. name: 'Fake Auto Complete University',
  145. },
  146. hostname: 'fake-autocomplete.edu',
  147. confirmed: true,
  148. },
  149. ]
  150. export function defaultSetupMocks(fetchMock) {
  151. fetchMock
  152. .get(/\/user\/emails/, fakeUsersData, { delay: MOCK_DELAY })
  153. .get(/\/institutions\/list\/2/, bazFakeInstitution, { delay: MOCK_DELAY })
  154. .get(/\/institutions\/list\/\d+/, fakeInstitution, { delay: MOCK_DELAY })
  155. .get(/\/institutions\/list\?country_code=.*/, fakeInstitutions, {
  156. delay: MOCK_DELAY,
  157. })
  158. .get(/\/institutions\/domains\?hostname=a/, fakeInstitutionDomain1)
  159. .get(/\/institutions\/domains\?hostname=f/, fakeInstitutionDomain2)
  160. .get(/\/institutions\/domains/, [])
  161. .post(/\/user\/emails\/*/, 200, {
  162. delay: MOCK_DELAY,
  163. })
  164. }
  165. export function reconfirmationSetupMocks(fetchMock) {
  166. defaultSetupMocks(fetchMock)
  167. fetchMock.get(/\/user\/emails/, fakeReconfirmationUsersData, {
  168. delay: MOCK_DELAY,
  169. overwriteRoutes: true,
  170. })
  171. }
  172. export function errorsMocks(fetchMock) {
  173. fetchMock
  174. .get(/\/user\/emails/, fakeUsersData, { delay: MOCK_DELAY })
  175. .post(/\/user\/emails\/*/, 500)
  176. }
  177. export function setDefaultMeta() {
  178. window.metaAttributesCache = window.metaAttributesCache || new Map()
  179. window.metaAttributesCache.set('ol-ExposedSettings', {
  180. ...window.metaAttributesCache.get('ol-ExposedSettings'),
  181. hasAffiliationsFeature: true,
  182. hasSamlFeature: true,
  183. samlInitPath: 'saml/init',
  184. })
  185. localStorage.setItem(
  186. 'showInstitutionalLeaversSurveyUntil',
  187. (Date.now() - 1000 * 60 * 60).toString()
  188. )
  189. }
  190. export function setReconfirmationMeta() {
  191. setDefaultMeta()
  192. window.metaAttributesCache.set(
  193. 'ol-reconfirmationRemoveEmail',
  194. 'reconfirmation-highlighted@overleaf.com'
  195. )
  196. window.metaAttributesCache.set(
  197. 'ol-reconfirmedViaSAML',
  198. 'sso-reconfirmed-provider-id'
  199. )
  200. }