DiscardingUpdatesTests.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import mongodb from 'mongodb-legacy'
  2. import nock from 'nock'
  3. import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js'
  4. import * as ProjectHistoryApp from './helpers/ProjectHistoryApp.js'
  5. const { ObjectId } = mongodb
  6. const MockHistoryStore = () => nock('http://127.0.0.1:3100')
  7. const MockWeb = () => nock('http://127.0.0.1:3000')
  8. describe('DiscardingUpdates', function () {
  9. beforeEach(async function () {
  10. this.timestamp = new Date()
  11. await ProjectHistoryApp.ensureRunning()
  12. this.user_id = new ObjectId().toString()
  13. this.project_id = new ObjectId().toString()
  14. this.doc_id = new ObjectId().toString()
  15. MockHistoryStore().post('/api/projects').reply(200, {
  16. projectId: 0,
  17. })
  18. MockWeb()
  19. .get(`/project/${this.project_id}/details`)
  20. .reply(200, { name: 'Test Project' })
  21. await ProjectHistoryClient.initializeProject(this.project_id)
  22. })
  23. it('should discard updates', async function () {
  24. const update = {
  25. pathname: '/main.tex',
  26. docLines: 'a\nb',
  27. doc: this.doc_id,
  28. meta: { user_id: this.user_id, ts: new Date() },
  29. }
  30. await ProjectHistoryClient.pushRawUpdate(this.project_id, update)
  31. await ProjectHistoryClient.flushProject(this.project_id)
  32. })
  33. })