DeleteProjectTests.js 2.4 KB

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