DeleteProjectTests.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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(function (done) {
  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. ProjectHistoryApp.ensureRunning(done)
  25. })
  26. describe('when the project has no pending updates', function (done) {
  27. it('successfully deletes the project', function (done) {
  28. ProjectHistoryClient.deleteProject(this.projectId, done)
  29. })
  30. })
  31. describe('when the project has pending updates', function (done) {
  32. beforeEach(function (done) {
  33. ProjectHistoryClient.pushRawUpdate(
  34. this.projectId,
  35. {
  36. pathname: '/main.tex',
  37. docLines: 'hello',
  38. doc: this.docId,
  39. meta: { userId: this.userId, ts: new Date() },
  40. },
  41. err => {
  42. if (err) {
  43. return done(err)
  44. }
  45. ProjectHistoryClient.setFirstOpTimestamp(
  46. this.projectId,
  47. Date.now(),
  48. err => {
  49. if (err) {
  50. return done(err)
  51. }
  52. ProjectHistoryClient.deleteProject(this.projectId, done)
  53. }
  54. )
  55. }
  56. )
  57. })
  58. it('clears pending updates', function (done) {
  59. ProjectHistoryClient.getDump(this.projectId, (err, dump) => {
  60. if (err) {
  61. return done(err)
  62. }
  63. expect(dump.updates).to.deep.equal([])
  64. done()
  65. })
  66. })
  67. it('clears the first op timestamp', function (done) {
  68. ProjectHistoryClient.getFirstOpTimestamp(this.projectId, (err, ts) => {
  69. if (err) {
  70. return done(err)
  71. }
  72. expect(ts).to.be.null
  73. done()
  74. })
  75. })
  76. })
  77. })