DiscardingUpdatesTests.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* eslint-disable
  2. no-undef,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * DS207: Consider shorter variations of null checks
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. import async from 'async'
  14. import sinon from 'sinon'
  15. import { expect } from 'chai'
  16. import Settings from '@overleaf/settings'
  17. import assert from 'node:assert'
  18. import mongodb from 'mongodb-legacy'
  19. import nock from 'nock'
  20. import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js'
  21. import * as ProjectHistoryApp from './helpers/ProjectHistoryApp.js'
  22. const { ObjectId } = mongodb
  23. const MockHistoryStore = () => nock('http://127.0.0.1:3100')
  24. const MockWeb = () => nock('http://127.0.0.1:3000')
  25. describe('DiscardingUpdates', function () {
  26. beforeEach(function (done) {
  27. this.timestamp = new Date()
  28. return ProjectHistoryApp.ensureRunning(error => {
  29. if (error != null) {
  30. throw error
  31. }
  32. this.user_id = new ObjectId().toString()
  33. this.project_id = new ObjectId().toString()
  34. this.doc_id = new ObjectId().toString()
  35. MockHistoryStore().post('/api/projects').reply(200, {
  36. projectId: 0,
  37. })
  38. MockWeb()
  39. .get(`/project/${this.project_id}/details`)
  40. .reply(200, { name: 'Test Project' })
  41. return ProjectHistoryClient.initializeProject(this.project_id, done)
  42. })
  43. })
  44. return it('should discard updates', function (done) {
  45. return async.series(
  46. [
  47. cb => {
  48. const update = {
  49. pathname: '/main.tex',
  50. docLines: 'a\nb',
  51. doc: this.doc_id,
  52. meta: { user_id: this.user_id, ts: new Date() },
  53. }
  54. return ProjectHistoryClient.pushRawUpdate(this.project_id, update, cb)
  55. },
  56. cb => {
  57. return ProjectHistoryClient.flushProject(this.project_id, cb)
  58. },
  59. ],
  60. error => {
  61. if (error != null) {
  62. throw error
  63. }
  64. return done()
  65. }
  66. )
  67. })
  68. })