ProjectInviteTests.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. /* eslint-disable
  2. handle-callback-err,
  3. max-len,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * DS207: Consider shorter variations of null checks
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const { expect } = require('chai')
  15. const Async = require('async')
  16. const User = require('./helpers/User')
  17. const request = require('./helpers/request')
  18. const settings = require('settings-sharelatex')
  19. const CollaboratorsEmailHandler = require('../../../app/src/Features/Collaborators/CollaboratorsEmailHandler')
  20. const createInvite = function(sendingUser, projectId, email, callback) {
  21. if (callback == null) {
  22. callback = function(err, invite) {}
  23. }
  24. return sendingUser.getCsrfToken(function(err) {
  25. if (err) {
  26. return callback(err)
  27. }
  28. return sendingUser.request.post(
  29. {
  30. uri: `/project/${projectId}/invite`,
  31. json: {
  32. email,
  33. privileges: 'readAndWrite'
  34. }
  35. },
  36. function(err, response, body) {
  37. if (err) {
  38. return callback(err)
  39. }
  40. expect(response.statusCode).to.equal(200)
  41. return callback(null, body.invite)
  42. }
  43. )
  44. })
  45. }
  46. const createProject = function(owner, projectName, callback) {
  47. if (callback == null) {
  48. callback = function(err, projectId, project) {}
  49. }
  50. return owner.createProject(projectName, function(err, projectId) {
  51. if (err) {
  52. throw err
  53. }
  54. const fakeProject = {
  55. _id: projectId,
  56. name: projectName,
  57. owner_ref: owner
  58. }
  59. return callback(err, projectId, fakeProject)
  60. })
  61. }
  62. const createProjectAndInvite = function(owner, projectName, email, callback) {
  63. if (callback == null) {
  64. callback = function(err, project, invite) {}
  65. }
  66. return createProject(owner, projectName, function(err, projectId, project) {
  67. if (err) {
  68. return callback(err)
  69. }
  70. return createInvite(owner, projectId, email, function(err, invite) {
  71. if (err) {
  72. return callback(err)
  73. }
  74. const link = CollaboratorsEmailHandler._buildInviteUrl(project, invite)
  75. return callback(null, project, invite, link)
  76. })
  77. })
  78. }
  79. const revokeInvite = function(sendingUser, projectId, inviteId, callback) {
  80. if (callback == null) {
  81. callback = function(err) {}
  82. }
  83. return sendingUser.getCsrfToken(function(err) {
  84. if (err) {
  85. return callback(err)
  86. }
  87. return sendingUser.request.delete(
  88. {
  89. uri: `/project/${projectId}/invite/${inviteId}`
  90. },
  91. function(err, response, body) {
  92. if (err) {
  93. return callback(err)
  94. }
  95. return callback(null)
  96. }
  97. )
  98. })
  99. }
  100. // Actions
  101. const tryFollowInviteLink = function(user, link, callback) {
  102. if (callback == null) {
  103. callback = function(err, response, body) {}
  104. }
  105. return user.request.get(
  106. {
  107. uri: link,
  108. baseUrl: null
  109. },
  110. callback
  111. )
  112. }
  113. const tryAcceptInvite = function(user, invite, callback) {
  114. if (callback == null) {
  115. callback = function(err, response, body) {}
  116. }
  117. return user.request.post(
  118. {
  119. uri: `/project/${invite.projectId}/invite/token/${invite.token}/accept`,
  120. json: {
  121. token: invite.token
  122. }
  123. },
  124. callback
  125. )
  126. }
  127. const tryRegisterUser = function(user, email, callback) {
  128. if (callback == null) {
  129. callback = function(err, response, body) {}
  130. }
  131. return user.getCsrfToken(error => {
  132. if (error != null) {
  133. return callback(error)
  134. }
  135. return user.request.post(
  136. {
  137. url: '/register',
  138. json: {
  139. email,
  140. password: 'some_weird_password'
  141. }
  142. },
  143. callback
  144. )
  145. })
  146. }
  147. const tryFollowLoginLink = function(user, loginLink, callback) {
  148. if (callback == null) {
  149. callback = function(err, response, body) {}
  150. }
  151. return user.getCsrfToken(error => {
  152. if (error != null) {
  153. return callback(error)
  154. }
  155. return user.request.get(loginLink, callback)
  156. })
  157. }
  158. const tryLoginUser = function(user, callback) {
  159. if (callback == null) {
  160. callback = function(err, response, body) {}
  161. }
  162. return user.getCsrfToken(error => {
  163. if (error != null) {
  164. return callback(error)
  165. }
  166. return user.request.post(
  167. {
  168. url: '/login',
  169. json: {
  170. email: user.email,
  171. password: user.password
  172. }
  173. },
  174. callback
  175. )
  176. })
  177. }
  178. const tryGetInviteList = function(user, projectId, callback) {
  179. if (callback == null) {
  180. callback = function(err, response, body) {}
  181. }
  182. return user.getCsrfToken(error => {
  183. if (error != null) {
  184. return callback(error)
  185. }
  186. return user.request.get(
  187. {
  188. url: `/project/${projectId}/invites`,
  189. json: true
  190. },
  191. callback
  192. )
  193. })
  194. }
  195. const tryJoinProject = function(user, projectId, callback) {
  196. if (callback == null) {
  197. callback = function(err, response, body) {}
  198. }
  199. return user.getCsrfToken(error => {
  200. if (error != null) {
  201. return callback(error)
  202. }
  203. return user.request.post(
  204. {
  205. url: `/project/${projectId}/join`,
  206. qs: { user_id: user._id },
  207. auth: {
  208. user: settings.apis.web.user,
  209. pass: settings.apis.web.pass,
  210. sendImmediately: true
  211. },
  212. json: true,
  213. jar: false
  214. },
  215. callback
  216. )
  217. })
  218. }
  219. // Expectations
  220. const expectProjectAccess = function(user, projectId, callback) {
  221. // should have access to project
  222. if (callback == null) {
  223. callback = function(err, result) {}
  224. }
  225. return user.openProject(projectId, err => {
  226. expect(err).to.be.oneOf([null, undefined])
  227. return callback()
  228. })
  229. }
  230. const expectNoProjectAccess = function(user, projectId, callback) {
  231. // should not have access to project page
  232. if (callback == null) {
  233. callback = function(err, result) {}
  234. }
  235. return user.openProject(projectId, err => {
  236. expect(err).to.be.instanceof(Error)
  237. return callback()
  238. })
  239. }
  240. const expectInvitePage = function(user, link, callback) {
  241. // view invite
  242. if (callback == null) {
  243. callback = function(err, result) {}
  244. }
  245. return tryFollowInviteLink(user, link, function(err, response, body) {
  246. expect(err).to.be.oneOf([null, undefined])
  247. expect(response.statusCode).to.equal(200)
  248. expect(body).to.match(new RegExp('<title>Project Invite - .*</title>'))
  249. return callback()
  250. })
  251. }
  252. const expectInvalidInvitePage = function(user, link, callback) {
  253. // view invalid invite
  254. if (callback == null) {
  255. callback = function(err, result) {}
  256. }
  257. return tryFollowInviteLink(user, link, function(err, response, body) {
  258. expect(err).to.be.oneOf([null, undefined])
  259. expect(response.statusCode).to.equal(200)
  260. expect(body).to.match(new RegExp('<title>Invalid Invite - .*</title>'))
  261. return callback()
  262. })
  263. }
  264. const expectInviteRedirectToRegister = function(user, link, callback) {
  265. // view invite, redirect to `/register`
  266. if (callback == null) {
  267. callback = function(err, result) {}
  268. }
  269. return tryFollowInviteLink(user, link, function(err, response, body) {
  270. expect(err).to.be.oneOf([null, undefined])
  271. expect(response.statusCode).to.equal(302)
  272. expect(response.headers.location).to.match(new RegExp('^/register.*$'))
  273. // follow redirect to register page and extract the redirectUrl from form
  274. return user.request.get(response.headers.location, (err, response, body) =>
  275. callback(null)
  276. )
  277. })
  278. }
  279. const expectLoginPage = function(user, callback) {
  280. if (callback == null) {
  281. callback = function(err, result) {}
  282. }
  283. return tryFollowLoginLink(user, '/login', function(err, response, body) {
  284. expect(err).to.be.oneOf([null, undefined])
  285. expect(response.statusCode).to.equal(200)
  286. expect(body).to.match(new RegExp('<title>Login - .*</title>'))
  287. return callback(null)
  288. })
  289. }
  290. const expectLoginRedirectToInvite = function(user, link, callback) {
  291. if (callback == null) {
  292. callback = function(err, result) {}
  293. }
  294. return tryLoginUser(user, function(err, response, body) {
  295. expect(err).to.be.oneOf([null, undefined])
  296. expect(response.statusCode).to.equal(200)
  297. return callback(null, null)
  298. })
  299. }
  300. const expectRegistrationRedirectToInvite = function(
  301. user,
  302. email,
  303. link,
  304. callback
  305. ) {
  306. if (callback == null) {
  307. callback = function(err, result) {}
  308. }
  309. return tryRegisterUser(user, email, function(err, response, body) {
  310. expect(err).to.be.oneOf([null, undefined])
  311. expect(response.statusCode).to.equal(200)
  312. return callback(null, null)
  313. })
  314. }
  315. const expectInviteRedirectToProject = function(user, link, invite, callback) {
  316. // view invite, redirect straight to project
  317. if (callback == null) {
  318. callback = function(err, result) {}
  319. }
  320. return tryFollowInviteLink(user, link, function(err, response, body) {
  321. expect(err).to.be.oneOf([null, undefined])
  322. expect(response.statusCode).to.equal(302)
  323. expect(response.headers.location).to.equal(`/project/${invite.projectId}`)
  324. return callback()
  325. })
  326. }
  327. const expectAcceptInviteAndRedirect = function(user, invite, callback) {
  328. // should accept the invite and redirect to project
  329. if (callback == null) {
  330. callback = function(err, result) {}
  331. }
  332. return tryAcceptInvite(user, invite, (err, response, body) => {
  333. expect(err).to.be.oneOf([null, undefined])
  334. expect(response.statusCode).to.equal(302)
  335. expect(response.headers.location).to.equal(`/project/${invite.projectId}`)
  336. return callback()
  337. })
  338. }
  339. const expectInviteListCount = function(user, projectId, count, callback) {
  340. if (callback == null) {
  341. callback = function(err) {}
  342. }
  343. return tryGetInviteList(user, projectId, function(err, response, body) {
  344. expect(err).to.be.oneOf([null, undefined])
  345. expect(response.statusCode).to.equal(200)
  346. expect(body).to.have.all.keys(['invites'])
  347. expect(body.invites.length).to.equal(count)
  348. return callback()
  349. })
  350. }
  351. const expectInvitesInJoinProjectCount = function(
  352. user,
  353. projectId,
  354. count,
  355. callback
  356. ) {
  357. if (callback == null) {
  358. callback = function(err, result) {}
  359. }
  360. return tryJoinProject(user, projectId, function(err, response, body) {
  361. expect(err).to.be.oneOf([null, undefined])
  362. expect(response.statusCode).to.equal(200)
  363. expect(body.project).to.contain.keys(['invites'])
  364. expect(body.project.invites.length).to.equal(count)
  365. return callback()
  366. })
  367. }
  368. describe('ProjectInviteTests', function() {
  369. before(function(done) {
  370. this.sendingUser = new User()
  371. this.user = new User()
  372. this.site_admin = new User({ email: 'admin@example.com' })
  373. this.email = 'smoketestuser@example.com'
  374. this.projectName = 'sharing test'
  375. return Async.series(
  376. [
  377. cb => this.user.ensureUserExists(cb),
  378. cb => this.sendingUser.login(cb),
  379. cb => this.sendingUser.setFeatures({ collaborators: 10 }, cb)
  380. ],
  381. done
  382. )
  383. })
  384. describe('creating invites', function() {
  385. beforeEach(function(done) {
  386. this.projectName = 'wat'
  387. this.projectId = null
  388. this.fakeProject = null
  389. return done()
  390. })
  391. describe('creating two invites', function() {
  392. beforeEach(function(done) {
  393. return Async.series(
  394. [
  395. cb => {
  396. return createProject(
  397. this.sendingUser,
  398. this.projectName,
  399. (err, projectId, project) => {
  400. this.projectId = projectId
  401. this.fakeProject = project
  402. return cb()
  403. }
  404. )
  405. }
  406. ],
  407. done
  408. )
  409. })
  410. afterEach(function(done) {
  411. return Async.series(
  412. [
  413. cb => this.sendingUser.deleteProject(this.projectId, cb),
  414. cb => this.sendingUser.deleteProject(this.projectId, cb)
  415. ],
  416. done
  417. )
  418. })
  419. it('should allow the project owner to create and remove invites', function(done) {
  420. this.invite = null
  421. return Async.series(
  422. [
  423. cb => expectProjectAccess(this.sendingUser, this.projectId, cb),
  424. cb =>
  425. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  426. // create invite, check invite list count
  427. cb => {
  428. return createInvite(
  429. this.sendingUser,
  430. this.projectId,
  431. this.email,
  432. (err, invite) => {
  433. if (err) {
  434. return cb(err)
  435. }
  436. this.invite = invite
  437. return cb()
  438. }
  439. )
  440. },
  441. cb =>
  442. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  443. cb =>
  444. revokeInvite(
  445. this.sendingUser,
  446. this.projectId,
  447. this.invite._id,
  448. cb
  449. ),
  450. cb =>
  451. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  452. // and a second time
  453. cb => {
  454. return createInvite(
  455. this.sendingUser,
  456. this.projectId,
  457. this.email,
  458. (err, invite) => {
  459. if (err) {
  460. return cb(err)
  461. }
  462. this.invite = invite
  463. return cb()
  464. }
  465. )
  466. },
  467. cb =>
  468. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  469. // check the joinProject view
  470. cb =>
  471. expectInvitesInJoinProjectCount(
  472. this.sendingUser,
  473. this.projectId,
  474. 1,
  475. cb
  476. ),
  477. // revoke invite
  478. cb =>
  479. revokeInvite(
  480. this.sendingUser,
  481. this.projectId,
  482. this.invite._id,
  483. cb
  484. ),
  485. cb =>
  486. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  487. cb =>
  488. expectInvitesInJoinProjectCount(
  489. this.sendingUser,
  490. this.projectId,
  491. 0,
  492. cb
  493. )
  494. ],
  495. done
  496. )
  497. })
  498. it('should allow the project owner to create many invites at once', function(done) {
  499. this.inviteOne = null
  500. this.inviteTwo = null
  501. return Async.series(
  502. [
  503. cb => expectProjectAccess(this.sendingUser, this.projectId, cb),
  504. cb =>
  505. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  506. // create first invite
  507. cb => {
  508. return createInvite(
  509. this.sendingUser,
  510. this.projectId,
  511. this.email,
  512. (err, invite) => {
  513. if (err) {
  514. return cb(err)
  515. }
  516. this.inviteOne = invite
  517. return cb()
  518. }
  519. )
  520. },
  521. cb =>
  522. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  523. // and a second
  524. cb => {
  525. return createInvite(
  526. this.sendingUser,
  527. this.projectId,
  528. this.email,
  529. (err, invite) => {
  530. if (err) {
  531. return cb(err)
  532. }
  533. this.inviteTwo = invite
  534. return cb()
  535. }
  536. )
  537. },
  538. // should have two
  539. cb =>
  540. expectInviteListCount(this.sendingUser, this.projectId, 2, cb),
  541. cb =>
  542. expectInvitesInJoinProjectCount(
  543. this.sendingUser,
  544. this.projectId,
  545. 2,
  546. cb
  547. ),
  548. // revoke first
  549. cb =>
  550. revokeInvite(
  551. this.sendingUser,
  552. this.projectId,
  553. this.inviteOne._id,
  554. cb
  555. ),
  556. cb =>
  557. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  558. // revoke second
  559. cb =>
  560. revokeInvite(
  561. this.sendingUser,
  562. this.projectId,
  563. this.inviteTwo._id,
  564. cb
  565. ),
  566. cb => expectInviteListCount(this.sendingUser, this.projectId, 0, cb)
  567. ],
  568. done
  569. )
  570. })
  571. })
  572. })
  573. describe('clicking the invite link', function() {
  574. beforeEach(function(done) {
  575. this.projectId = null
  576. this.fakeProject = null
  577. return done()
  578. })
  579. describe('user is logged in already', function() {
  580. beforeEach(function(done) {
  581. return Async.series(
  582. [
  583. cb => {
  584. return createProjectAndInvite(
  585. this.sendingUser,
  586. this.projectName,
  587. this.email,
  588. (err, project, invite, link) => {
  589. this.projectId = project._id
  590. this.fakeProject = project
  591. this.invite = invite
  592. this.link = link
  593. return cb()
  594. }
  595. )
  596. },
  597. cb => {
  598. return this.user.login(err => {
  599. if (err) {
  600. throw err
  601. }
  602. return cb()
  603. })
  604. }
  605. ],
  606. done
  607. )
  608. })
  609. afterEach(function(done) {
  610. return Async.series(
  611. [
  612. cb => this.sendingUser.deleteProject(this.projectId, cb),
  613. cb => this.sendingUser.deleteProject(this.projectId, cb),
  614. cb =>
  615. revokeInvite(
  616. this.sendingUser,
  617. this.projectId,
  618. this.invite._id,
  619. cb
  620. )
  621. ],
  622. done
  623. )
  624. })
  625. describe('user is already a member of the project', function() {
  626. beforeEach(function(done) {
  627. return Async.series(
  628. [
  629. cb => expectInvitePage(this.user, this.link, cb),
  630. cb => expectAcceptInviteAndRedirect(this.user, this.invite, cb),
  631. cb => expectProjectAccess(this.user, this.invite.projectId, cb)
  632. ],
  633. done
  634. )
  635. })
  636. describe('when user clicks on the invite a second time', function() {
  637. it('should just redirect to the project page', function(done) {
  638. return Async.series(
  639. [
  640. cb => expectProjectAccess(this.user, this.invite.projectId, cb),
  641. cb =>
  642. expectInviteRedirectToProject(
  643. this.user,
  644. this.link,
  645. this.invite,
  646. cb
  647. ),
  648. cb => expectProjectAccess(this.user, this.invite.projectId, cb)
  649. ],
  650. done
  651. )
  652. })
  653. describe('when the user recieves another invite to the same project', () =>
  654. it('should redirect to the project page', function(done) {
  655. return Async.series(
  656. [
  657. cb => {
  658. return createInvite(
  659. this.sendingUser,
  660. this.projectId,
  661. this.email,
  662. (err, invite) => {
  663. if (err) {
  664. throw err
  665. }
  666. this.secondInvite = invite
  667. this.secondLink = CollaboratorsEmailHandler._buildInviteUrl(
  668. this.fakeProject,
  669. invite
  670. )
  671. return cb()
  672. }
  673. )
  674. },
  675. cb =>
  676. expectInviteRedirectToProject(
  677. this.user,
  678. this.secondLink,
  679. this.secondInvite,
  680. cb
  681. ),
  682. cb =>
  683. expectProjectAccess(this.user, this.invite.projectId, cb),
  684. cb =>
  685. revokeInvite(
  686. this.sendingUser,
  687. this.projectId,
  688. this.secondInvite._id,
  689. cb
  690. )
  691. ],
  692. done
  693. )
  694. }))
  695. })
  696. })
  697. describe('user is not a member of the project', function() {
  698. it('should not grant access if the user does not accept the invite', function(done) {
  699. return Async.series(
  700. [
  701. cb => expectInvitePage(this.user, this.link, cb),
  702. cb => expectNoProjectAccess(this.user, this.invite.projectId, cb)
  703. ],
  704. done
  705. )
  706. })
  707. it('should render the invalid-invite page if the token is invalid', function(done) {
  708. return Async.series(
  709. [
  710. cb => {
  711. const link = this.link.replace(
  712. this.invite.token,
  713. 'not_a_real_token'
  714. )
  715. return expectInvalidInvitePage(this.user, link, cb)
  716. },
  717. cb => expectNoProjectAccess(this.user, this.invite.projectId, cb),
  718. cb => expectNoProjectAccess(this.user, this.invite.projectId, cb)
  719. ],
  720. done
  721. )
  722. })
  723. it('should allow the user to accept the invite and access the project', function(done) {
  724. return Async.series(
  725. [
  726. cb => expectInvitePage(this.user, this.link, cb),
  727. cb => expectAcceptInviteAndRedirect(this.user, this.invite, cb),
  728. cb => expectProjectAccess(this.user, this.invite.projectId, cb)
  729. ],
  730. done
  731. )
  732. })
  733. })
  734. })
  735. describe('user is not logged in initially', function() {
  736. before(function(done) {
  737. return this.user.logout(done)
  738. })
  739. beforeEach(function(done) {
  740. return Async.series(
  741. [
  742. cb => {
  743. return createProjectAndInvite(
  744. this.sendingUser,
  745. this.projectName,
  746. this.email,
  747. (err, project, invite, link) => {
  748. this.projectId = project._id
  749. this.fakeProject = project
  750. this.invite = invite
  751. this.link = link
  752. return cb()
  753. }
  754. )
  755. }
  756. ],
  757. done
  758. )
  759. })
  760. afterEach(function(done) {
  761. return Async.series(
  762. [
  763. cb => this.sendingUser.deleteProject(this.projectId, cb),
  764. cb => this.sendingUser.deleteProject(this.projectId, cb),
  765. cb =>
  766. revokeInvite(
  767. this.sendingUser,
  768. this.projectId,
  769. this.invite._id,
  770. cb
  771. )
  772. ],
  773. done
  774. )
  775. })
  776. describe('registration prompt workflow with valid token', function() {
  777. it('should redirect to the register page', function(done) {
  778. return Async.series(
  779. [cb => expectInviteRedirectToRegister(this.user, this.link, cb)],
  780. done
  781. )
  782. })
  783. it('should allow user to accept the invite if the user registers a new account', function(done) {
  784. return Async.series(
  785. [
  786. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  787. cb =>
  788. expectRegistrationRedirectToInvite(
  789. this.user,
  790. 'some_email@example.com',
  791. this.link,
  792. cb
  793. ),
  794. cb => expectInvitePage(this.user, this.link, cb),
  795. cb => expectAcceptInviteAndRedirect(this.user, this.invite, cb),
  796. cb => expectProjectAccess(this.user, this.invite.projectId, cb)
  797. ],
  798. done
  799. )
  800. })
  801. })
  802. describe('registration prompt workflow with non-valid token', function() {
  803. before(function(done) {
  804. return this.user.logout(done)
  805. })
  806. it('should redirect to the register page', function(done) {
  807. return Async.series(
  808. [
  809. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  810. cb => expectNoProjectAccess(this.user, this.invite.projectId, cb)
  811. ],
  812. done
  813. )
  814. })
  815. it('should display invalid-invite if the user registers a new account', function(done) {
  816. const badLink = this.link.replace(
  817. this.invite.token,
  818. 'not_a_real_token'
  819. )
  820. return Async.series(
  821. [
  822. cb => expectInviteRedirectToRegister(this.user, badLink, cb),
  823. cb =>
  824. expectRegistrationRedirectToInvite(
  825. this.user,
  826. 'some_email@example.com',
  827. badLink,
  828. cb
  829. ),
  830. cb => expectInvalidInvitePage(this.user, badLink, cb),
  831. cb => expectNoProjectAccess(this.user, this.invite.projectId, cb)
  832. ],
  833. done
  834. )
  835. })
  836. })
  837. describe('login workflow with valid token', function() {
  838. before(function(done) {
  839. return this.user.logout(done)
  840. })
  841. it('should redirect to the register page', function(done) {
  842. return Async.series(
  843. [
  844. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  845. cb => expectNoProjectAccess(this.user, this.invite.projectId, cb)
  846. ],
  847. done
  848. )
  849. })
  850. it('should allow the user to login to view the invite', function(done) {
  851. return Async.series(
  852. [
  853. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  854. cb => expectLoginPage(this.user, cb),
  855. cb => expectLoginRedirectToInvite(this.user, this.link, cb),
  856. cb => expectInvitePage(this.user, this.link, cb),
  857. cb => expectNoProjectAccess(this.user, this.invite.projectId, cb)
  858. ],
  859. done
  860. )
  861. })
  862. it('should allow user to accept the invite if the user registers a new account', function(done) {
  863. return Async.series(
  864. [
  865. cb => expectInvitePage(this.user, this.link, cb),
  866. cb => expectAcceptInviteAndRedirect(this.user, this.invite, cb),
  867. cb => expectProjectAccess(this.user, this.invite.projectId, cb)
  868. ],
  869. done
  870. )
  871. })
  872. })
  873. describe('login workflow with non-valid token', function() {
  874. before(function(done) {
  875. return this.user.logout(done)
  876. })
  877. it('should redirect to the register page', function(done) {
  878. return Async.series(
  879. [
  880. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  881. cb => expectNoProjectAccess(this.user, this.invite.projectId, cb)
  882. ],
  883. done
  884. )
  885. })
  886. it('should show the invalid-invite page once the user has logged in', function(done) {
  887. const badLink = this.link.replace(
  888. this.invite.token,
  889. 'not_a_real_token'
  890. )
  891. return Async.series(
  892. [
  893. cb => {
  894. return expectInviteRedirectToRegister(this.user, badLink, cb)
  895. },
  896. cb => {
  897. return expectLoginPage(this.user, cb)
  898. },
  899. cb => expectLoginRedirectToInvite(this.user, badLink, cb),
  900. cb => expectInvalidInvitePage(this.user, badLink, cb),
  901. cb => expectNoProjectAccess(this.user, this.invite.projectId, cb)
  902. ],
  903. done
  904. )
  905. })
  906. })
  907. })
  908. })
  909. })