HistoryTests.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* eslint-disable
  2. camelcase,
  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 { db, ObjectId } = require('../../../app/src/infrastructure/mongojs')
  16. const MockV1HistoryApi = require('./helpers/MockV1HistoryApi')
  17. const User = require('./helpers/User')
  18. describe('History', function() {
  19. beforeEach(function(done) {
  20. this.owner = new User()
  21. return this.owner.login(done)
  22. })
  23. describe('zip download of version', function() {
  24. it('should stream the zip file of a version', function(done) {
  25. return this.owner.createProject(
  26. 'example-project',
  27. (error, project_id) => {
  28. this.project_id = project_id
  29. if (error != null) {
  30. return done(error)
  31. }
  32. this.v1_history_id = 42
  33. return db.projects.update(
  34. {
  35. _id: ObjectId(this.project_id)
  36. },
  37. {
  38. $set: {
  39. 'overleaf.history.id': this.v1_history_id
  40. }
  41. },
  42. error => {
  43. if (error != null) {
  44. return done(error)
  45. }
  46. return this.owner.request(
  47. `/project/${this.project_id}/version/42/zip`,
  48. (error, response, body) => {
  49. if (error != null) {
  50. return done(error)
  51. }
  52. expect(response.statusCode).to.equal(200)
  53. expect(response.headers['content-type']).to.equal(
  54. 'application/zip'
  55. )
  56. expect(response.headers['content-disposition']).to.equal(
  57. 'attachment; filename="example-project%20(Version%2042).zip"'
  58. )
  59. expect(body).to.equal(
  60. `Mock zip for ${this.v1_history_id} at version 42`
  61. )
  62. return done()
  63. }
  64. )
  65. }
  66. )
  67. }
  68. )
  69. })
  70. it('should return 402 for non-v2-history project', function(done) {
  71. return this.owner.createProject('non-v2-project', (error, project_id) => {
  72. this.project_id = project_id
  73. if (error != null) {
  74. return done(error)
  75. }
  76. return db.projects.update(
  77. {
  78. _id: ObjectId(this.project_id)
  79. },
  80. {
  81. $unset: {
  82. 'overleaf.history.id': true
  83. }
  84. },
  85. error => {
  86. if (error != null) {
  87. return done(error)
  88. }
  89. return this.owner.request(
  90. `/project/${this.project_id}/version/42/zip`,
  91. (error, response, body) => {
  92. if (error != null) {
  93. return done(error)
  94. }
  95. expect(response.statusCode).to.equal(402)
  96. return done()
  97. }
  98. )
  99. }
  100. )
  101. })
  102. })
  103. })
  104. })