emails.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. },
  16. {
  17. confirmedAt: '2022-03-10T10:59:44.139Z',
  18. email: 'bar@overleaf.com',
  19. default: false,
  20. },
  21. {
  22. affiliation: {
  23. institution: {
  24. confirmed: true,
  25. id: 2,
  26. name: 'Overleaf',
  27. },
  28. licence: 'pro_plus',
  29. department: 'Art & Art History',
  30. role: 'Postdoc',
  31. },
  32. email: 'baz@overleaf.com',
  33. default: false,
  34. },
  35. {
  36. email: 'qux@overleaf.com',
  37. default: false,
  38. },
  39. ]
  40. const fakeInstitutions = [
  41. {
  42. id: 9326,
  43. name: 'Unknown',
  44. country_code: 'al',
  45. departments: ['New department'],
  46. },
  47. ]
  48. const fakeInstitution = {
  49. id: 123,
  50. name: 'test',
  51. country_code: 'de',
  52. departments: [],
  53. team_id: null,
  54. }
  55. const bazFakeInstitution = {
  56. id: 2,
  57. name: 'Baz',
  58. country_code: 'de',
  59. departments: ['Custom department 1', 'Custom department 2'],
  60. team_id: null,
  61. }
  62. const fakeInstitutionDomain1 = [
  63. {
  64. university: {
  65. id: 1234,
  66. ssoEnabled: true,
  67. name: 'Auto Complete University',
  68. },
  69. hostname: 'autocomplete.edu',
  70. confirmed: true,
  71. },
  72. ]
  73. const fakeInstitutionDomain2 = [
  74. {
  75. university: {
  76. id: 5678,
  77. ssoEnabled: false,
  78. name: 'Fake Auto Complete University',
  79. },
  80. hostname: 'fake-autocomplete.edu',
  81. confirmed: true,
  82. },
  83. ]
  84. export function defaultSetupMocks(fetchMock) {
  85. fetchMock
  86. .get(/\/user\/emails/, fakeUsersData, { delay: MOCK_DELAY })
  87. .get(/\/institutions\/list\/2/, bazFakeInstitution, { delay: MOCK_DELAY })
  88. .get(/\/institutions\/list\/\d+/, fakeInstitution, { delay: MOCK_DELAY })
  89. .get(/\/institutions\/list\?country_code=.*/, fakeInstitutions, {
  90. delay: MOCK_DELAY,
  91. })
  92. .get(/\/institutions\/domains\?hostname=a/, fakeInstitutionDomain1)
  93. .get(/\/institutions\/domains\?hostname=f/, fakeInstitutionDomain2)
  94. .post(/\/user\/emails\/*/, 200, {
  95. delay: MOCK_DELAY,
  96. })
  97. }
  98. export function errorsMocks(fetchMock) {
  99. fetchMock
  100. .get(/\/user\/emails/, fakeUsersData, { delay: MOCK_DELAY })
  101. .post(/\/user\/emails\/*/, 500)
  102. }
  103. export function setDefaultMeta() {
  104. window.metaAttributesCache = window.metaAttributesCache || new Map()
  105. window.metaAttributesCache.set('ol-ExposedSettings', {
  106. ...window.metaAttributesCache.get('ol-ExposedSettings'),
  107. hasAffiliationsFeature: true,
  108. hasSamlFeature: true,
  109. samlInitPath: 'saml/init',
  110. })
  111. }