DiscardingUpdatesTests.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 'assert'
  18. import { ObjectId } from 'mongodb'
  19. import nock from 'nock'
  20. import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js'
  21. import * as ProjectHistoryApp from './helpers/ProjectHistoryApp.js'
  22. const MockHistoryStore = () => nock('http://localhost:3100')
  23. const MockWeb = () => nock('http://localhost:3000')
  24. describe('DiscardingUpdates', function () {
  25. beforeEach(function (done) {
  26. this.timestamp = new Date()
  27. return ProjectHistoryApp.ensureRunning(error => {
  28. if (error != null) {
  29. throw error
  30. }
  31. this.user_id = ObjectId().toString()
  32. this.project_id = ObjectId().toString()
  33. this.doc_id = ObjectId().toString()
  34. MockHistoryStore().post('/api/projects').reply(200, {
  35. projectId: 0,
  36. })
  37. MockWeb()
  38. .get(`/project/${this.project_id}/details`)
  39. .reply(200, { name: 'Test Project' })
  40. return ProjectHistoryClient.initializeProject(this.project_id, done)
  41. })
  42. })
  43. return it('should discard updates', function (done) {
  44. return async.series(
  45. [
  46. cb => {
  47. const update = {
  48. pathname: '/main.tex',
  49. docLines: 'a\nb',
  50. doc: this.doc_id,
  51. meta: { user_id: this.user_id, ts: new Date() },
  52. }
  53. return ProjectHistoryClient.pushRawUpdate(this.project_id, update, cb)
  54. },
  55. cb => {
  56. return ProjectHistoryClient.flushProject(this.project_id, cb)
  57. },
  58. ],
  59. error => {
  60. if (error != null) {
  61. throw error
  62. }
  63. return done()
  64. }
  65. )
  66. })
  67. })