DeleteProjectTests.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { expect } from 'chai'
  2. import nock from 'nock'
  3. import mongodb from 'mongodb-legacy'
  4. import * as ProjectHistoryApp from './helpers/ProjectHistoryApp.js'
  5. import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js'
  6. const { ObjectId } = mongodb
  7. const MockHistoryStore = () => nock('http://127.0.0.1:3100')
  8. const MockWeb = () => nock('http://127.0.0.1:3000')
  9. const fixture = path => new URL(`../fixtures/${path}`, import.meta.url)
  10. describe('Deleting project', function () {
  11. beforeEach(async function () {
  12. this.projectId = new ObjectId().toString()
  13. this.historyId = new ObjectId().toString()
  14. MockWeb()
  15. .get(`/project/${this.projectId}/details`)
  16. .reply(200, {
  17. name: 'Test Project',
  18. overleaf: { history: { id: this.historyId } },
  19. })
  20. MockHistoryStore()
  21. .get(`/api/projects/${this.historyId}/latest/history`)
  22. .replyWithFile(200, fixture('chunks/0-3.json'))
  23. MockHistoryStore().delete(`/api/projects/${this.historyId}`).reply(204)
  24. await ProjectHistoryApp.ensureRunning()
  25. })
  26. describe('when the project has no pending updates', function () {
  27. it('successfully deletes the project', async function () {
  28. await ProjectHistoryClient.deleteProject(this.projectId)
  29. })
  30. })
  31. describe('when the project has pending updates', function () {
  32. beforeEach(async function () {
  33. await ProjectHistoryClient.pushRawUpdate(this.projectId, {
  34. pathname: '/main.tex',
  35. docLines: 'hello',
  36. doc: this.docId,
  37. meta: { userId: this.userId, ts: new Date() },
  38. })
  39. await ProjectHistoryClient.setFirstOpTimestamp(this.projectId, Date.now())
  40. await ProjectHistoryClient.deleteProject(this.projectId)
  41. })
  42. it('clears pending updates', async function () {
  43. const dump = await ProjectHistoryClient.getDump(this.projectId)
  44. expect(dump.updates).to.deep.equal([])
  45. })
  46. it('clears the first op timestamp', async function () {
  47. const ts = await ProjectHistoryClient.getFirstOpTimestamp(this.projectId)
  48. expect(ts).to.be.null
  49. })
  50. })
  51. })