SizeCheckTests.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. const { expect } = require('chai')
  2. const Settings = require('@overleaf/settings')
  3. const MockWebApi = require('./helpers/MockWebApi')
  4. const DocUpdaterClient = require('./helpers/DocUpdaterClient')
  5. const DocUpdaterApp = require('./helpers/DocUpdaterApp')
  6. describe('SizeChecks', function () {
  7. before(function (done) {
  8. DocUpdaterApp.ensureRunning(done)
  9. })
  10. beforeEach(function () {
  11. this.version = 0
  12. this.update = {
  13. doc: this.doc_id,
  14. op: [
  15. {
  16. i: 'insert some more lines that will bring it above the limit\n',
  17. p: 42,
  18. },
  19. ],
  20. v: this.version,
  21. }
  22. this.project_id = DocUpdaterClient.randomId()
  23. this.doc_id = DocUpdaterClient.randomId()
  24. })
  25. describe('when a doc is above the doc size limit already', function () {
  26. beforeEach(function () {
  27. this.lines = ['0123456789'.repeat(Settings.max_doc_length / 10 + 1)]
  28. MockWebApi.insertDoc(this.project_id, this.doc_id, {
  29. lines: this.lines,
  30. v: this.version,
  31. })
  32. })
  33. it('should error when fetching the doc', function (done) {
  34. DocUpdaterClient.getDoc(this.project_id, this.doc_id, (error, res) => {
  35. if (error) return done(error)
  36. expect(res.statusCode).to.equal(500)
  37. done()
  38. })
  39. })
  40. describe('when trying to update', function () {
  41. beforeEach(function (done) {
  42. const update = {
  43. doc: this.doc_id,
  44. op: this.update.op,
  45. v: this.version,
  46. }
  47. DocUpdaterClient.sendUpdate(
  48. this.project_id,
  49. this.doc_id,
  50. update,
  51. error => {
  52. if (error != null) {
  53. throw error
  54. }
  55. setTimeout(done, 200)
  56. }
  57. )
  58. })
  59. it('should still error when fetching the doc', function (done) {
  60. DocUpdaterClient.getDoc(this.project_id, this.doc_id, (error, res) => {
  61. if (error) return done(error)
  62. expect(res.statusCode).to.equal(500)
  63. done()
  64. })
  65. })
  66. })
  67. })
  68. describe('when a doc is just below the doc size limit', function () {
  69. beforeEach(function () {
  70. this.lines = ['0123456789'.repeat(Settings.max_doc_length / 10 - 1)]
  71. MockWebApi.insertDoc(this.project_id, this.doc_id, {
  72. lines: this.lines,
  73. v: this.version,
  74. })
  75. })
  76. it('should be able to fetch the doc', function (done) {
  77. DocUpdaterClient.getDoc(
  78. this.project_id,
  79. this.doc_id,
  80. (error, res, doc) => {
  81. if (error) return done(error)
  82. expect(doc.lines).to.deep.equal(this.lines)
  83. done()
  84. }
  85. )
  86. })
  87. describe('when trying to update', function () {
  88. beforeEach(function (done) {
  89. const update = {
  90. doc: this.doc_id,
  91. op: this.update.op,
  92. v: this.version,
  93. }
  94. DocUpdaterClient.sendUpdate(
  95. this.project_id,
  96. this.doc_id,
  97. update,
  98. error => {
  99. if (error != null) {
  100. throw error
  101. }
  102. setTimeout(done, 200)
  103. }
  104. )
  105. })
  106. it('should not update the doc', function (done) {
  107. DocUpdaterClient.getDoc(
  108. this.project_id,
  109. this.doc_id,
  110. (error, res, doc) => {
  111. if (error) return done(error)
  112. expect(doc.lines).to.deep.equal(this.lines)
  113. done()
  114. }
  115. )
  116. })
  117. })
  118. })
  119. })