ReferalConnect.test.mjs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. const modulePath = new URL(
  2. '../../../../app/src/Features/Referal/ReferalConnect.mjs',
  3. import.meta.url
  4. ).pathname
  5. describe('Referal connect middle wear', function () {
  6. beforeEach(async function (ctx) {
  7. ctx.connect = (await import(modulePath)).default
  8. })
  9. it('should take a referal query string and put it on the session if it exists', async function (ctx) {
  10. await new Promise(resolve => {
  11. const req = {
  12. query: { referal: '12345' },
  13. session: {},
  14. }
  15. ctx.connect.use(req, {}, () => {
  16. req.session.referal_id.should.equal(req.query.referal)
  17. resolve()
  18. })
  19. })
  20. })
  21. it('should not change the referal_id on the session if not in query', async function (ctx) {
  22. await new Promise(resolve => {
  23. const req = {
  24. query: {},
  25. session: { referal_id: 'same' },
  26. }
  27. ctx.connect.use(req, {}, () => {
  28. req.session.referal_id.should.equal('same')
  29. resolve()
  30. })
  31. })
  32. })
  33. it('should take a facebook referal query string and put it on the session if it exists', async function (ctx) {
  34. await new Promise(resolve => {
  35. const req = {
  36. query: { fb_ref: '12345' },
  37. session: {},
  38. }
  39. ctx.connect.use(req, {}, () => {
  40. req.session.referal_id.should.equal(req.query.fb_ref)
  41. resolve()
  42. })
  43. })
  44. })
  45. it('should map the facebook medium into the session', async function (ctx) {
  46. await new Promise(resolve => {
  47. const req = {
  48. query: { rm: 'fb' },
  49. session: {},
  50. }
  51. ctx.connect.use(req, {}, () => {
  52. req.session.referal_medium.should.equal('facebook')
  53. resolve()
  54. })
  55. })
  56. })
  57. it('should map the twitter medium into the session', async function (ctx) {
  58. await new Promise(resolve => {
  59. const req = {
  60. query: { rm: 't' },
  61. session: {},
  62. }
  63. ctx.connect.use(req, {}, () => {
  64. req.session.referal_medium.should.equal('twitter')
  65. resolve()
  66. })
  67. })
  68. })
  69. it('should map the google plus medium into the session', async function (ctx) {
  70. await new Promise(resolve => {
  71. const req = {
  72. query: { rm: 'gp' },
  73. session: {},
  74. }
  75. ctx.connect.use(req, {}, () => {
  76. req.session.referal_medium.should.equal('google_plus')
  77. resolve()
  78. })
  79. })
  80. })
  81. it('should map the email medium into the session', async function (ctx) {
  82. await new Promise(resolve => {
  83. const req = {
  84. query: { rm: 'e' },
  85. session: {},
  86. }
  87. ctx.connect.use(req, {}, () => {
  88. req.session.referal_medium.should.equal('email')
  89. resolve()
  90. })
  91. })
  92. })
  93. it('should map the direct medium into the session', async function (ctx) {
  94. await new Promise(resolve => {
  95. const req = {
  96. query: { rm: 'd' },
  97. session: {},
  98. }
  99. ctx.connect.use(req, {}, () => {
  100. req.session.referal_medium.should.equal('direct')
  101. resolve()
  102. })
  103. })
  104. })
  105. it('should map the bonus source into the session', async function (ctx) {
  106. await new Promise(resolve => {
  107. const req = {
  108. query: { rs: 'b' },
  109. session: {},
  110. }
  111. ctx.connect.use(req, {}, () => {
  112. req.session.referal_source.should.equal('bonus')
  113. resolve()
  114. })
  115. })
  116. })
  117. it('should map the public share source into the session', async function (ctx) {
  118. await new Promise(resolve => {
  119. const req = {
  120. query: { rs: 'ps' },
  121. session: {},
  122. }
  123. ctx.connect.use(req, {}, () => {
  124. req.session.referal_source.should.equal('public_share')
  125. resolve()
  126. })
  127. })
  128. })
  129. it('should map the collaborator invite into the session', async function (ctx) {
  130. await new Promise(resolve => {
  131. const req = {
  132. query: { rs: 'ci' },
  133. session: {},
  134. }
  135. ctx.connect.use(req, {}, () => {
  136. req.session.referal_source.should.equal('collaborator_invite')
  137. resolve()
  138. })
  139. })
  140. })
  141. })