TpdsUpdateTests.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* eslint-disable
  2. camelcase,
  3. max-len,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS101: Remove unnecessary use of Array.from
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * DS207: Consider shorter variations of null checks
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const { expect } = require('chai')
  15. const ProjectGetter = require('../../../app/src/Features/Project/ProjectGetter.js')
  16. const request = require('./helpers/request')
  17. const User = require('./helpers/User')
  18. describe('TpdsUpdateTests', function() {
  19. beforeEach(function(done) {
  20. this.owner = new User()
  21. return this.owner.login(error => {
  22. if (error != null) {
  23. throw error
  24. }
  25. return this.owner.createProject(
  26. 'test-project',
  27. { template: 'example' },
  28. (error, project_id) => {
  29. if (error != null) {
  30. throw error
  31. }
  32. this.project_id = project_id
  33. return done()
  34. }
  35. )
  36. })
  37. })
  38. describe('adding a file', function() {
  39. beforeEach(function(done) {
  40. return request(
  41. {
  42. method: 'POST',
  43. url: `/project/${this.project_id}/contents/test.tex`,
  44. auth: {
  45. username: 'sharelatex',
  46. password: 'password',
  47. sendImmediately: true
  48. },
  49. body: 'test one two'
  50. },
  51. (error, response, body) => {
  52. if (error != null) {
  53. throw error
  54. }
  55. expect(response.statusCode).to.equal(200)
  56. return done()
  57. }
  58. )
  59. })
  60. it('should have added the file', function(done) {
  61. return ProjectGetter.getProject(this.project_id, (error, project) => {
  62. if (error != null) {
  63. throw error
  64. }
  65. const projectFolder = project.rootFolder[0]
  66. const file = projectFolder.docs.find(e => e.name === 'test.tex')
  67. expect(file).to.exist
  68. return done()
  69. })
  70. })
  71. })
  72. describe('deleting a file', function() {
  73. beforeEach(function(done) {
  74. return request(
  75. {
  76. method: 'DELETE',
  77. url: `/project/${this.project_id}/contents/main.tex`,
  78. auth: {
  79. username: 'sharelatex',
  80. password: 'password',
  81. sendImmediately: true
  82. }
  83. },
  84. (error, response, body) => {
  85. if (error != null) {
  86. throw error
  87. }
  88. expect(response.statusCode).to.equal(200)
  89. return done()
  90. }
  91. )
  92. })
  93. it('should have deleted the file', function(done) {
  94. return ProjectGetter.getProject(this.project_id, (error, project) => {
  95. if (error != null) {
  96. throw error
  97. }
  98. const projectFolder = project.rootFolder[0]
  99. for (let doc of Array.from(projectFolder.docs)) {
  100. if (doc.name === 'main.tex') {
  101. throw new Error('expected main.tex to have been deleted')
  102. }
  103. }
  104. return done()
  105. })
  106. })
  107. })
  108. describe('update a new file', function() {
  109. beforeEach(function(done) {
  110. return request(
  111. {
  112. method: 'POST',
  113. url: `/user/${this.owner._id}/update/test-project/other.tex`,
  114. auth: {
  115. username: 'sharelatex',
  116. password: 'password',
  117. sendImmediately: true
  118. },
  119. body: 'test one two'
  120. },
  121. (error, response, body) => {
  122. if (error != null) {
  123. throw error
  124. }
  125. expect(response.statusCode).to.equal(200)
  126. return done()
  127. }
  128. )
  129. })
  130. it('should have added the file', function(done) {
  131. return ProjectGetter.getProject(this.project_id, (error, project) => {
  132. if (error != null) {
  133. throw error
  134. }
  135. const projectFolder = project.rootFolder[0]
  136. const file = projectFolder.docs.find(e => e.name === 'other.tex')
  137. expect(file).to.exist
  138. return done()
  139. })
  140. })
  141. })
  142. describe('update when the project is archived', function() {
  143. beforeEach(function(done) {
  144. this.owner.request(
  145. {
  146. url: `/Project/${this.project_id}/archive`,
  147. method: 'post'
  148. },
  149. (err, response, body) => {
  150. expect(err).to.not.exist
  151. return request(
  152. {
  153. method: 'POST',
  154. url: `/user/${this.owner._id}/update/test-project/test.tex`,
  155. auth: {
  156. username: 'sharelatex',
  157. password: 'password',
  158. sendImmediately: true
  159. },
  160. body: 'test one two'
  161. },
  162. (error, response, body) => {
  163. if (error != null) {
  164. throw error
  165. }
  166. expect(response.statusCode).to.equal(409)
  167. return done()
  168. }
  169. )
  170. }
  171. )
  172. })
  173. it('should not have created a new project', function(done) {
  174. ProjectGetter.findAllUsersProjects(
  175. this.owner._id,
  176. 'name',
  177. (err, projects) => {
  178. expect(err).to.not.exist
  179. expect(projects.owned.length).to.equal(1)
  180. done()
  181. }
  182. )
  183. })
  184. it('should not have added the file', function(done) {
  185. return ProjectGetter.getProject(this.project_id, (error, project) => {
  186. if (error != null) {
  187. throw error
  188. }
  189. const projectFolder = project.rootFolder[0]
  190. const file = projectFolder.docs.find(e => e.name === 'test.tex')
  191. expect(file).to.not.exist
  192. return done()
  193. })
  194. })
  195. })
  196. })