emails.js 4.8 KB

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