ProjectStructureTests.js 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  1. /* eslint-disable
  2. camelcase,
  3. max-len,
  4. no-path-concat,
  5. no-return-assign,
  6. no-unused-vars,
  7. */
  8. // TODO: This file was created by bulk-decaffeinate.
  9. // Fix any style issues and re-enable lint.
  10. /*
  11. * decaffeinate suggestions:
  12. * DS102: Remove unnecessary code created because of implicit returns
  13. * DS207: Consider shorter variations of null checks
  14. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  15. */
  16. const async = require('async')
  17. const { expect } = require('chai')
  18. const mkdirp = require('mkdirp')
  19. const { ObjectId } = require('mongojs')
  20. const Path = require('path')
  21. const fs = require('fs')
  22. const Settings = require('settings-sharelatex')
  23. const _ = require('underscore')
  24. const ProjectGetter = require('../../../app/src/Features/Project/ProjectGetter.js')
  25. const MockDocUpdaterApi = require('./helpers/MockDocUpdaterApi')
  26. const MockFileStoreApi = require('./helpers/MockFileStoreApi')
  27. const MockProjectHistoryApi = require('./helpers/MockProjectHistoryApi')
  28. const request = require('./helpers/request')
  29. const User = require('./helpers/User')
  30. describe('ProjectStructureChanges', function() {
  31. let example_project_id = null
  32. let example_doc_id = null
  33. let example_file_id = null
  34. let example_folder_id_1 = null
  35. let example_folder_id_2 = null
  36. before(function(done) {
  37. this.owner = new User()
  38. return this.owner.login(done)
  39. })
  40. describe('creating a project from the example template', function() {
  41. before(function(done) {
  42. MockDocUpdaterApi.clearProjectStructureUpdates()
  43. return this.owner.createProject(
  44. 'example-project',
  45. { template: 'example' },
  46. (error, project_id) => {
  47. if (error != null) {
  48. throw error
  49. }
  50. example_project_id = project_id
  51. return done()
  52. }
  53. )
  54. })
  55. it('should version creating a doc', function() {
  56. const {
  57. docUpdates: updates,
  58. version
  59. } = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id)
  60. expect(updates.length).to.equal(2)
  61. _.each(updates, update => {
  62. expect(update.userId).to.equal(this.owner._id)
  63. return expect(update.docLines).to.be.a('string')
  64. })
  65. expect(_.where(updates, { pathname: '/main.tex' }).length).to.equal(1)
  66. expect(_.where(updates, { pathname: '/references.bib' }).length).to.equal(
  67. 1
  68. )
  69. return expect(version).to.equal(3)
  70. })
  71. it('should version creating a file', function() {
  72. const {
  73. fileUpdates: updates,
  74. version
  75. } = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id)
  76. expect(updates.length).to.equal(1)
  77. const update = updates[0]
  78. expect(update.userId).to.equal(this.owner._id)
  79. expect(update.pathname).to.equal('/universe.jpg')
  80. expect(update.url).to.be.a('string')
  81. return expect(version).to.equal(3)
  82. })
  83. })
  84. describe('duplicating a project', function() {
  85. before(function(done) {
  86. MockDocUpdaterApi.clearProjectStructureUpdates()
  87. return this.owner.request.post(
  88. {
  89. uri: `/Project/${example_project_id}/clone`,
  90. json: {
  91. projectName: 'new.tex'
  92. }
  93. },
  94. (error, res, body) => {
  95. if (error != null) {
  96. throw error
  97. }
  98. if (res.statusCode < 200 || res.statusCode >= 300) {
  99. throw new Error(`failed to add doc ${res.statusCode}`)
  100. }
  101. this.dup_project_id = body.project_id
  102. return done()
  103. }
  104. )
  105. })
  106. it('should version the docs created', function() {
  107. const {
  108. docUpdates: updates,
  109. version
  110. } = MockDocUpdaterApi.getProjectStructureUpdates(this.dup_project_id)
  111. expect(updates.length).to.equal(2)
  112. _.each(updates, update => {
  113. expect(update.userId).to.equal(this.owner._id)
  114. return expect(update.docLines).to.be.a('string')
  115. })
  116. expect(_.where(updates, { pathname: '/main.tex' }).length).to.equal(1)
  117. expect(_.where(updates, { pathname: '/references.bib' }).length).to.equal(
  118. 1
  119. )
  120. return expect(version).to.equal(3)
  121. })
  122. it('should version the files created', function() {
  123. const {
  124. fileUpdates: updates,
  125. version
  126. } = MockDocUpdaterApi.getProjectStructureUpdates(this.dup_project_id)
  127. expect(updates.length).to.equal(1)
  128. const update = updates[0]
  129. expect(update.userId).to.equal(this.owner._id)
  130. expect(update.pathname).to.equal('/universe.jpg')
  131. expect(update.url).to.be.a('string')
  132. return expect(version).to.equal(3)
  133. })
  134. })
  135. describe('adding a doc', function() {
  136. before(function(done) {
  137. MockDocUpdaterApi.clearProjectStructureUpdates()
  138. return ProjectGetter.getProject(example_project_id, (error, project) => {
  139. if (error != null) {
  140. throw error
  141. }
  142. this.project_0 = project
  143. return this.owner.request.post(
  144. {
  145. uri: `project/${example_project_id}/doc`,
  146. json: {
  147. name: 'new.tex',
  148. parent_folder_id: project.rootFolder[0]._id
  149. }
  150. },
  151. (error, res, body) => {
  152. if (error != null) {
  153. throw error
  154. }
  155. if (res.statusCode < 200 || res.statusCode >= 300) {
  156. throw new Error(`failed to add doc ${res.statusCode}`)
  157. }
  158. example_doc_id = body._id
  159. return ProjectGetter.getProject(
  160. example_project_id,
  161. (error, newProject) => {
  162. if (error != null) {
  163. throw error
  164. }
  165. this.project_1 = newProject
  166. return done()
  167. }
  168. )
  169. }
  170. )
  171. })
  172. })
  173. it('should version the doc added', function() {
  174. const {
  175. docUpdates: updates,
  176. version
  177. } = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id)
  178. expect(updates.length).to.equal(1)
  179. const update = updates[0]
  180. expect(update.userId).to.equal(this.owner._id)
  181. expect(update.pathname).to.equal('/new.tex')
  182. expect(update.docLines).to.be.a('string')
  183. return expect(version).to.equal(this.project_0.version + 1)
  184. })
  185. it('should increment the project structure version number', function() {
  186. return expect(this.project_1.version).to.equal(this.project_0.version + 1)
  187. })
  188. })
  189. describe('uploading a project', function() {
  190. before(function(done) {
  191. let req
  192. MockDocUpdaterApi.clearProjectStructureUpdates()
  193. const zip_file = fs.createReadStream(
  194. Path.resolve(__dirname + '/../files/test_project.zip')
  195. )
  196. this.test_project_name = 'wombat'
  197. return (req = this.owner.request.post(
  198. {
  199. uri: 'project/new/upload',
  200. formData: {
  201. qqfile: zip_file
  202. }
  203. },
  204. (error, res, body) => {
  205. if (error != null) {
  206. throw error
  207. }
  208. if (res.statusCode < 200 || res.statusCode >= 300) {
  209. throw new Error(`failed to upload project ${res.statusCode}`)
  210. }
  211. this.uploaded_project_id = JSON.parse(body).project_id
  212. return done()
  213. }
  214. ))
  215. })
  216. it('should version the docs created', function() {
  217. const {
  218. docUpdates: updates,
  219. version
  220. } = MockDocUpdaterApi.getProjectStructureUpdates(this.uploaded_project_id)
  221. expect(updates.length).to.equal(1)
  222. const update = updates[0]
  223. expect(update.userId).to.equal(this.owner._id)
  224. expect(update.pathname).to.equal('/main.tex')
  225. expect(update.docLines).to.equal('Test')
  226. return expect(version).to.equal(2)
  227. })
  228. it('should version the files created', function() {
  229. const {
  230. fileUpdates: updates,
  231. version
  232. } = MockDocUpdaterApi.getProjectStructureUpdates(this.uploaded_project_id)
  233. expect(updates.length).to.equal(1)
  234. const update = updates[0]
  235. expect(update.userId).to.equal(this.owner._id)
  236. expect(update.pathname).to.equal('/1pixel.png')
  237. expect(update.url).to.be.a('string')
  238. return expect(version).to.equal(2)
  239. })
  240. })
  241. describe('uploading a project with a name', function() {
  242. before(function(done) {
  243. let req
  244. MockDocUpdaterApi.clearProjectStructureUpdates()
  245. const zip_file = fs.createReadStream(
  246. Path.resolve(__dirname + '/../files/test_project_with_name.zip')
  247. )
  248. this.test_project_name = 'wombat'
  249. return (req = this.owner.request.post(
  250. {
  251. uri: 'project/new/upload',
  252. formData: {
  253. qqfile: zip_file
  254. }
  255. },
  256. (error, res, body) => {
  257. if (error != null) {
  258. throw error
  259. }
  260. if (res.statusCode < 200 || res.statusCode >= 300) {
  261. throw new Error(`failed to upload project ${res.statusCode}`)
  262. }
  263. this.uploaded_project_id = JSON.parse(body).project_id
  264. return done()
  265. }
  266. ))
  267. })
  268. it('should set the project name from the zip contents', function(done) {
  269. return ProjectGetter.getProject(
  270. this.uploaded_project_id,
  271. (error, project) => {
  272. expect(error).not.to.exist
  273. expect(project.name).to.equal(this.test_project_name)
  274. return done()
  275. }
  276. )
  277. })
  278. })
  279. describe('uploading a project with an invalid name', function() {
  280. before(function(done) {
  281. let req
  282. MockDocUpdaterApi.clearProjectStructureUpdates()
  283. const zip_file = fs.createReadStream(
  284. Path.resolve(__dirname + '/../files/test_project_with_invalid_name.zip')
  285. )
  286. this.test_project_match = /^bad[^\\]+name$/
  287. return (req = this.owner.request.post(
  288. {
  289. uri: 'project/new/upload',
  290. formData: {
  291. qqfile: zip_file
  292. }
  293. },
  294. (error, res, body) => {
  295. if (error != null) {
  296. throw error
  297. }
  298. if (res.statusCode < 200 || res.statusCode >= 300) {
  299. throw new Error(`failed to upload project ${res.statusCode}`)
  300. }
  301. this.uploaded_project_id = JSON.parse(body).project_id
  302. return done()
  303. }
  304. ))
  305. })
  306. it('should set the project name from the zip contents', function(done) {
  307. return ProjectGetter.getProject(
  308. this.uploaded_project_id,
  309. (error, project) => {
  310. expect(error).not.to.exist
  311. expect(project.name).to.match(this.test_project_match)
  312. return done()
  313. }
  314. )
  315. })
  316. })
  317. describe('uploading an empty zipfile', function() {
  318. let zipFile = null
  319. before(function(done) {
  320. MockDocUpdaterApi.clearProjectStructureUpdates()
  321. zipFile = fs.createReadStream(
  322. Path.resolve(__dirname + '/../files/test_project_empty.zip')
  323. )
  324. done()
  325. })
  326. it('should fail with 422 error', function(done) {
  327. this.owner.request.post(
  328. {
  329. uri: 'project/new/upload',
  330. formData: {
  331. qqfile: zipFile
  332. }
  333. },
  334. (error, res) => {
  335. if (error != null) {
  336. throw error
  337. }
  338. expect(res.statusCode).to.equal(422)
  339. done()
  340. }
  341. )
  342. })
  343. })
  344. describe('uploading a zipfile containing only empty directories', function() {
  345. let zipFile = null
  346. before(function(done) {
  347. MockDocUpdaterApi.clearProjectStructureUpdates()
  348. zipFile = fs.createReadStream(
  349. Path.resolve(__dirname + '/../files/test_project_with_empty_folder.zip')
  350. )
  351. done()
  352. })
  353. it('should fail with 422 error', function(done) {
  354. this.owner.request.post(
  355. {
  356. uri: 'project/new/upload',
  357. formData: {
  358. qqfile: zipFile
  359. }
  360. },
  361. (error, res) => {
  362. if (error != null) {
  363. throw error
  364. }
  365. expect(res.statusCode).to.equal(422)
  366. done()
  367. }
  368. )
  369. })
  370. })
  371. describe('uploading a project with a shared top-level folder', function() {
  372. before(function(done) {
  373. MockDocUpdaterApi.clearProjectStructureUpdates()
  374. const zip_file = fs.createReadStream(
  375. Path.resolve(
  376. __dirname + '/../files/test_project_with_shared_top_level_folder.zip'
  377. )
  378. )
  379. return this.owner.request.post(
  380. {
  381. uri: 'project/new/upload',
  382. formData: {
  383. qqfile: zip_file
  384. }
  385. },
  386. (error, res, body) => {
  387. if (error != null) {
  388. throw error
  389. }
  390. if (res.statusCode < 200 || res.statusCode >= 300) {
  391. throw new Error(`failed to upload project ${res.statusCode}`)
  392. }
  393. this.uploaded_project_id = JSON.parse(body).project_id
  394. return done()
  395. }
  396. )
  397. })
  398. it('should not create the top-level folder', function(done) {
  399. return ProjectGetter.getProject(this.uploaded_project_id, function(
  400. error,
  401. project
  402. ) {
  403. expect(error).not.to.exist
  404. expect(project.rootFolder[0].folders.length).to.equal(0)
  405. expect(project.rootFolder[0].docs.length).to.equal(2)
  406. return done()
  407. })
  408. })
  409. })
  410. describe('uploading a project with backslashes in the path names', function() {
  411. before(function(done) {
  412. MockDocUpdaterApi.clearProjectStructureUpdates()
  413. const zip_file = fs.createReadStream(
  414. Path.resolve(
  415. __dirname + '/../files/test_project_with_backslash_in_filename.zip'
  416. )
  417. )
  418. return this.owner.request.post(
  419. {
  420. uri: 'project/new/upload',
  421. formData: {
  422. qqfile: zip_file
  423. }
  424. },
  425. (error, res, body) => {
  426. if (error != null) {
  427. throw error
  428. }
  429. if (res.statusCode < 200 || res.statusCode >= 300) {
  430. throw new Error(`failed to upload project ${res.statusCode}`)
  431. }
  432. this.uploaded_project_id = JSON.parse(body).project_id
  433. return done()
  434. }
  435. )
  436. })
  437. it('should treat the backslash as a directory separator', function(done) {
  438. return ProjectGetter.getProject(this.uploaded_project_id, function(
  439. error,
  440. project
  441. ) {
  442. expect(error).not.to.exist
  443. expect(project.rootFolder[0].folders[0].name).to.equal('styles')
  444. expect(project.rootFolder[0].folders[0].docs[0].name).to.equal('ao.sty')
  445. return done()
  446. })
  447. })
  448. })
  449. describe('uploading a project with files in different encodings', function() {
  450. before(function(done) {
  451. MockDocUpdaterApi.clearProjectStructureUpdates()
  452. const zip_file = fs.createReadStream(
  453. Path.resolve(__dirname + '/../files/charsets/charsets.zip')
  454. )
  455. return this.owner.request.post(
  456. {
  457. uri: 'project/new/upload',
  458. formData: {
  459. qqfile: zip_file
  460. }
  461. },
  462. (error, res, body) => {
  463. if (error != null) {
  464. throw error
  465. }
  466. if (res.statusCode < 200 || res.statusCode >= 300) {
  467. throw new Error(`failed to upload project ${res.statusCode}`)
  468. }
  469. this.uploaded_project_id = JSON.parse(body).project_id
  470. return done()
  471. }
  472. )
  473. })
  474. it('should correctly parse windows-1252', function() {
  475. const {
  476. docUpdates: updates
  477. } = MockDocUpdaterApi.getProjectStructureUpdates(this.uploaded_project_id)
  478. const update = _.find(
  479. updates,
  480. update => update.pathname === '/test-german-windows-1252.tex'
  481. )
  482. return expect(update.docLines).to.contain(
  483. 'Der schnelle braune Fuchs sprang träge über den Hund.'
  484. )
  485. })
  486. it('should correctly parse German utf8', function() {
  487. const {
  488. docUpdates: updates
  489. } = MockDocUpdaterApi.getProjectStructureUpdates(this.uploaded_project_id)
  490. const update = _.find(
  491. updates,
  492. update => update.pathname === '/test-german-utf8x.tex'
  493. )
  494. return expect(update.docLines).to.contain(
  495. 'Der schnelle braune Fuchs sprang träge über den Hund.'
  496. )
  497. })
  498. it('should correctly parse little-endian utf16', function() {
  499. const {
  500. docUpdates: updates
  501. } = MockDocUpdaterApi.getProjectStructureUpdates(this.uploaded_project_id)
  502. const update = _.find(
  503. updates,
  504. update => update.pathname === '/test-greek-utf16-le-bom.tex'
  505. )
  506. return expect(update.docLines).to.contain(
  507. 'Η γρήγορη καστανή αλεπού πήδηξε χαλαρά πάνω από το σκυλί.'
  508. )
  509. })
  510. it('should correctly parse Greek utf8', function() {
  511. const {
  512. docUpdates: updates
  513. } = MockDocUpdaterApi.getProjectStructureUpdates(this.uploaded_project_id)
  514. const update = _.find(
  515. updates,
  516. update => update.pathname === '/test-greek-utf8x.tex'
  517. )
  518. return expect(update.docLines).to.contain(
  519. 'Η γρήγορη καστανή αλεπού πήδηξε χαλαρά πάνω από το σκυλί.'
  520. )
  521. })
  522. })
  523. describe('uploading a file', function() {
  524. beforeEach(function(done) {
  525. MockDocUpdaterApi.clearProjectStructureUpdates()
  526. return ProjectGetter.getProject(example_project_id, (error, project) => {
  527. if (error != null) {
  528. throw error
  529. }
  530. this.root_folder_id = project.rootFolder[0]._id.toString()
  531. this.project_0 = project
  532. return done()
  533. })
  534. })
  535. it('should version a newly uploaded file', function(done) {
  536. let req
  537. const image_file = fs.createReadStream(
  538. Path.resolve(__dirname + '/../files/1pixel.png')
  539. )
  540. return (req = this.owner.request.post(
  541. {
  542. uri: `project/${example_project_id}/upload`,
  543. qs: {
  544. folder_id: this.root_folder_id
  545. },
  546. formData: {
  547. qqfile: {
  548. value: image_file,
  549. options: {
  550. filename: '1pixel.png',
  551. contentType: 'image/png'
  552. }
  553. }
  554. }
  555. },
  556. (error, res, body) => {
  557. if (error != null) {
  558. throw error
  559. }
  560. if (res.statusCode < 200 || res.statusCode >= 300) {
  561. throw new Error(`failed to upload file ${res.statusCode}`)
  562. }
  563. example_file_id = JSON.parse(body).entity_id
  564. const {
  565. fileUpdates: updates,
  566. version
  567. } = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id)
  568. expect(updates.length).to.equal(1)
  569. const update = updates[0]
  570. expect(update.userId).to.equal(this.owner._id)
  571. expect(update.pathname).to.equal('/1pixel.png')
  572. expect(update.url).to.be.a('string')
  573. this.original_file_url = update.url
  574. expect(version).to.equal(this.project_0.version + 1)
  575. return ProjectGetter.getProject(
  576. example_project_id,
  577. (error, newProject) => {
  578. if (error != null) {
  579. throw error
  580. }
  581. this.project_1 = newProject
  582. // uploading a new file does change the project structure
  583. expect(this.project_1.version).to.equal(
  584. this.project_0.version + 1
  585. )
  586. return done()
  587. }
  588. )
  589. }
  590. ))
  591. })
  592. it('should version a replacement file', function(done) {
  593. let req
  594. const image_file = fs.createReadStream(
  595. Path.resolve(__dirname + '/../files/2pixel.png')
  596. )
  597. return (req = this.owner.request.post(
  598. {
  599. uri: `project/${example_project_id}/upload`,
  600. qs: {
  601. folder_id: this.root_folder_id
  602. },
  603. formData: {
  604. qqfile: {
  605. value: image_file,
  606. options: {
  607. filename: '1pixel.png',
  608. contentType: 'image/png'
  609. }
  610. }
  611. }
  612. },
  613. (error, res, body) => {
  614. if (error != null) {
  615. throw error
  616. }
  617. if (res.statusCode < 200 || res.statusCode >= 300) {
  618. throw new Error(`failed to upload file ${res.statusCode}`)
  619. }
  620. example_file_id = JSON.parse(body).entity_id
  621. const {
  622. fileUpdates: updates,
  623. version
  624. } = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id)
  625. expect(updates.length).to.equal(2)
  626. let update = updates[0]
  627. expect(update.userId).to.equal(this.owner._id)
  628. expect(update.pathname).to.equal('/1pixel.png')
  629. // expect(update.url).to.be.a('string');
  630. update = updates[1]
  631. expect(update.userId).to.equal(this.owner._id)
  632. expect(update.pathname).to.equal('/1pixel.png')
  633. expect(update.url).to.be.a('string')
  634. expect(version).to.equal(this.project_0.version + 1)
  635. return ProjectGetter.getProject(
  636. example_project_id,
  637. (error, newProject) => {
  638. if (error != null) {
  639. throw error
  640. }
  641. this.project_1 = newProject
  642. // replacing a file should update the project structure
  643. expect(this.project_1.version).to.equal(
  644. this.project_0.version + 1
  645. )
  646. return done()
  647. }
  648. )
  649. }
  650. ))
  651. })
  652. })
  653. describe('moving entities', function() {
  654. before(function(done) {
  655. return this.owner.request.post(
  656. {
  657. uri: `project/${example_project_id}/folder`,
  658. json: {
  659. name: 'foo'
  660. }
  661. },
  662. (error, res, body) => {
  663. if (error != null) {
  664. throw error
  665. }
  666. example_folder_id_1 = body._id
  667. return done()
  668. }
  669. )
  670. })
  671. beforeEach(function(done) {
  672. MockDocUpdaterApi.clearProjectStructureUpdates()
  673. return ProjectGetter.getProject(example_project_id, (error, project) => {
  674. if (error != null) {
  675. throw error
  676. }
  677. this.root_folder_id = project.rootFolder[0]._id.toString()
  678. this.project_0 = project
  679. return done()
  680. })
  681. })
  682. it('should version moving a doc', function(done) {
  683. return this.owner.request.post(
  684. {
  685. uri: `project/${example_project_id}/Doc/${example_doc_id}/move`,
  686. json: {
  687. folder_id: example_folder_id_1
  688. }
  689. },
  690. (error, res, body) => {
  691. if (error != null) {
  692. throw error
  693. }
  694. if (res.statusCode < 200 || res.statusCode >= 300) {
  695. throw new Error(`failed to move doc ${res.statusCode}`)
  696. }
  697. const {
  698. docUpdates: updates,
  699. version
  700. } = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id)
  701. expect(updates.length).to.equal(1)
  702. const update = updates[0]
  703. expect(update.userId).to.equal(this.owner._id)
  704. expect(update.pathname).to.equal('/new.tex')
  705. expect(update.newPathname).to.equal('/foo/new.tex')
  706. expect(version).to.equal(this.project_0.version + 2)
  707. return ProjectGetter.getProject(
  708. example_project_id,
  709. (error, newProject) => {
  710. if (error != null) {
  711. throw error
  712. }
  713. this.project_1 = newProject
  714. // replacing a file should update the project structure
  715. expect(this.project_1.version).to.equal(
  716. this.project_0.version + 2
  717. ) // 2 because it's a delete and then add
  718. return done()
  719. }
  720. )
  721. }
  722. )
  723. })
  724. it('should version moving a file', function(done) {
  725. return this.owner.request.post(
  726. {
  727. uri: `project/${example_project_id}/File/${example_file_id}/move`,
  728. json: {
  729. folder_id: example_folder_id_1
  730. }
  731. },
  732. (error, res, body) => {
  733. if (error != null) {
  734. throw error
  735. }
  736. if (res.statusCode < 200 || res.statusCode >= 300) {
  737. throw new Error(`failed to move file ${res.statusCode}`)
  738. }
  739. const {
  740. fileUpdates: updates,
  741. version
  742. } = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id)
  743. expect(updates.length).to.equal(1)
  744. const update = updates[0]
  745. expect(update.userId).to.equal(this.owner._id)
  746. expect(update.pathname).to.equal('/1pixel.png')
  747. expect(update.newPathname).to.equal('/foo/1pixel.png')
  748. expect(version).to.equal(this.project_0.version + 2)
  749. return ProjectGetter.getProject(
  750. example_project_id,
  751. (error, newProject) => {
  752. if (error != null) {
  753. throw error
  754. }
  755. this.project_1 = newProject
  756. // replacing a file should update the project structure
  757. expect(this.project_1.version).to.equal(
  758. this.project_0.version + 2
  759. ) // 2 because it's a delete and then add
  760. return done()
  761. }
  762. )
  763. }
  764. )
  765. })
  766. it('should version moving a folder', function(done) {
  767. return this.owner.request.post(
  768. {
  769. uri: `project/${example_project_id}/folder`,
  770. json: {
  771. name: 'bar'
  772. }
  773. },
  774. (error, res, body) => {
  775. if (error != null) {
  776. throw error
  777. }
  778. example_folder_id_2 = body._id
  779. return this.owner.request.post(
  780. {
  781. uri: `project/${example_project_id}/Folder/${example_folder_id_1}/move`,
  782. json: {
  783. folder_id: example_folder_id_2
  784. }
  785. },
  786. (error, res, body) => {
  787. if (error != null) {
  788. throw error
  789. }
  790. if (res.statusCode < 200 || res.statusCode >= 300) {
  791. throw new Error(`failed to move folder ${res.statusCode}`)
  792. }
  793. let {
  794. docUpdates: updates,
  795. version
  796. } = MockDocUpdaterApi.getProjectStructureUpdates(
  797. example_project_id
  798. )
  799. expect(updates.length).to.equal(1)
  800. let update = updates[0]
  801. expect(update.userId).to.equal(this.owner._id)
  802. expect(update.pathname).to.equal('/foo/new.tex')
  803. expect(update.newPathname).to.equal('/bar/foo/new.tex')
  804. expect(version).to.equal(this.project_0.version + 3)
  805. ;({
  806. fileUpdates: updates,
  807. version
  808. } = MockDocUpdaterApi.getProjectStructureUpdates(
  809. example_project_id
  810. ))
  811. expect(updates.length).to.equal(1)
  812. update = updates[0]
  813. expect(update.userId).to.equal(this.owner._id)
  814. expect(update.pathname).to.equal('/foo/1pixel.png')
  815. expect(update.newPathname).to.equal('/bar/foo/1pixel.png')
  816. expect(version).to.equal(this.project_0.version + 3)
  817. return ProjectGetter.getProject(
  818. example_project_id,
  819. (error, newProject) => {
  820. if (error != null) {
  821. throw error
  822. }
  823. this.project_1 = newProject
  824. // replacing a file should update the project structure
  825. expect(this.project_1.version).to.equal(
  826. this.project_0.version + 3
  827. ) // because folder and 2 files move
  828. return done()
  829. }
  830. )
  831. }
  832. )
  833. }
  834. )
  835. })
  836. })
  837. describe('renaming entities', function() {
  838. beforeEach(function(done) {
  839. MockDocUpdaterApi.clearProjectStructureUpdates()
  840. return ProjectGetter.getProject(example_project_id, (error, project) => {
  841. if (error != null) {
  842. throw error
  843. }
  844. this.root_folder_id = project.rootFolder[0]._id.toString()
  845. this.project_0 = project
  846. return done()
  847. })
  848. })
  849. it('should version renaming a doc', function(done) {
  850. return this.owner.request.post(
  851. {
  852. uri: `project/${example_project_id}/Doc/${example_doc_id}/rename`,
  853. json: {
  854. name: 'new_renamed.tex'
  855. }
  856. },
  857. (error, res, body) => {
  858. if (error != null) {
  859. throw error
  860. }
  861. if (res.statusCode < 200 || res.statusCode >= 300) {
  862. throw new Error(`failed to move doc ${res.statusCode}`)
  863. }
  864. const {
  865. docUpdates: updates,
  866. version
  867. } = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id)
  868. expect(updates.length).to.equal(1)
  869. const update = updates[0]
  870. expect(update.userId).to.equal(this.owner._id)
  871. expect(update.pathname).to.equal('/bar/foo/new.tex')
  872. expect(update.newPathname).to.equal('/bar/foo/new_renamed.tex')
  873. expect(version).to.equal(this.project_0.version + 1)
  874. return ProjectGetter.getProject(
  875. example_project_id,
  876. (error, newProject) => {
  877. if (error != null) {
  878. throw error
  879. }
  880. this.project_1 = newProject
  881. // replacing a file should update the project structure
  882. expect(this.project_1.version).to.equal(
  883. this.project_0.version + 1
  884. )
  885. return done()
  886. }
  887. )
  888. }
  889. )
  890. })
  891. it('should version renaming a file', function(done) {
  892. return this.owner.request.post(
  893. {
  894. uri: `project/${example_project_id}/File/${example_file_id}/rename`,
  895. json: {
  896. name: '1pixel_renamed.png'
  897. }
  898. },
  899. (error, res, body) => {
  900. if (error != null) {
  901. throw error
  902. }
  903. if (res.statusCode < 200 || res.statusCode >= 300) {
  904. throw new Error(`failed to move file ${res.statusCode}`)
  905. }
  906. const {
  907. fileUpdates: updates,
  908. version
  909. } = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id)
  910. expect(updates.length).to.equal(1)
  911. const update = updates[0]
  912. expect(update.userId).to.equal(this.owner._id)
  913. expect(update.pathname).to.equal('/bar/foo/1pixel.png')
  914. expect(update.newPathname).to.equal('/bar/foo/1pixel_renamed.png')
  915. expect(version).to.equal(this.project_0.version + 1)
  916. return ProjectGetter.getProject(
  917. example_project_id,
  918. (error, newProject) => {
  919. if (error != null) {
  920. throw error
  921. }
  922. this.project_1 = newProject
  923. // replacing a file should update the project structure
  924. expect(this.project_1.version).to.equal(
  925. this.project_0.version + 1
  926. )
  927. return done()
  928. }
  929. )
  930. }
  931. )
  932. })
  933. it('should version renaming a folder', function(done) {
  934. return this.owner.request.post(
  935. {
  936. uri: `project/${example_project_id}/Folder/${example_folder_id_1}/rename`,
  937. json: {
  938. name: 'foo_renamed'
  939. }
  940. },
  941. (error, res, body) => {
  942. if (error != null) {
  943. throw error
  944. }
  945. if (res.statusCode < 200 || res.statusCode >= 300) {
  946. throw new Error(`failed to move folder ${res.statusCode}`)
  947. }
  948. let {
  949. docUpdates: updates,
  950. version
  951. } = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id)
  952. expect(updates.length).to.equal(1)
  953. let update = updates[0]
  954. expect(update.userId).to.equal(this.owner._id)
  955. expect(update.pathname).to.equal('/bar/foo/new_renamed.tex')
  956. expect(update.newPathname).to.equal(
  957. '/bar/foo_renamed/new_renamed.tex'
  958. )
  959. expect(version).to.equal(this.project_0.version + 1)
  960. ;({
  961. fileUpdates: updates,
  962. version
  963. } = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id))
  964. expect(updates.length).to.equal(1)
  965. update = updates[0]
  966. expect(update.userId).to.equal(this.owner._id)
  967. expect(update.pathname).to.equal('/bar/foo/1pixel_renamed.png')
  968. expect(update.newPathname).to.equal(
  969. '/bar/foo_renamed/1pixel_renamed.png'
  970. )
  971. expect(version).to.equal(this.project_0.version + 1)
  972. return ProjectGetter.getProject(
  973. example_project_id,
  974. (error, newProject) => {
  975. if (error != null) {
  976. throw error
  977. }
  978. this.project_1 = newProject
  979. // replacing a file should update the project structure
  980. expect(this.project_1.version).to.equal(
  981. this.project_0.version + 1
  982. )
  983. return done()
  984. }
  985. )
  986. }
  987. )
  988. })
  989. })
  990. describe('deleting entities', function() {
  991. beforeEach(function(done) {
  992. MockDocUpdaterApi.clearProjectStructureUpdates()
  993. return ProjectGetter.getProject(example_project_id, (error, project) => {
  994. if (error != null) {
  995. throw error
  996. }
  997. this.root_folder_id = project.rootFolder[0]._id.toString()
  998. this.project_0 = project
  999. return done()
  1000. })
  1001. })
  1002. it('should version deleting a folder', function(done) {
  1003. return this.owner.request.delete(
  1004. {
  1005. uri: `project/${example_project_id}/Folder/${example_folder_id_2}`
  1006. },
  1007. (error, res, body) => {
  1008. if (error != null) {
  1009. throw error
  1010. }
  1011. if (res.statusCode < 200 || res.statusCode >= 300) {
  1012. throw new Error(`failed to delete folder ${res.statusCode}`)
  1013. }
  1014. let {
  1015. docUpdates: updates,
  1016. version
  1017. } = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id)
  1018. expect(updates.length).to.equal(1)
  1019. let update = updates[0]
  1020. expect(update.userId).to.equal(this.owner._id)
  1021. expect(update.pathname).to.equal('/bar/foo_renamed/new_renamed.tex')
  1022. expect(update.newPathname).to.equal('')
  1023. expect(version).to.equal(this.project_0.version + 1)
  1024. ;({
  1025. fileUpdates: updates,
  1026. version
  1027. } = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id))
  1028. expect(updates.length).to.equal(1)
  1029. update = updates[0]
  1030. expect(update.userId).to.equal(this.owner._id)
  1031. expect(update.pathname).to.equal(
  1032. '/bar/foo_renamed/1pixel_renamed.png'
  1033. )
  1034. expect(update.newPathname).to.equal('')
  1035. expect(version).to.equal(this.project_0.version + 1)
  1036. return ProjectGetter.getProject(
  1037. example_project_id,
  1038. (error, newProject) => {
  1039. if (error != null) {
  1040. throw error
  1041. }
  1042. this.project_1 = newProject
  1043. // replacing a file should update the project structure
  1044. expect(this.project_1.version).to.equal(
  1045. this.project_0.version + 1
  1046. )
  1047. return done()
  1048. }
  1049. )
  1050. }
  1051. )
  1052. })
  1053. })
  1054. describe('tpds', function() {
  1055. before(function(done) {
  1056. this.tpds_project_name = `tpds-project-${new ObjectId().toString()}`
  1057. return this.owner.createProject(
  1058. this.tpds_project_name,
  1059. (error, project_id) => {
  1060. if (error != null) {
  1061. throw error
  1062. }
  1063. this.tpds_project_id = project_id
  1064. return mkdirp(Settings.path.dumpFolder, done)
  1065. }
  1066. )
  1067. })
  1068. beforeEach(function(done) {
  1069. MockDocUpdaterApi.clearProjectStructureUpdates()
  1070. return ProjectGetter.getProject(
  1071. this.tpds_project_id,
  1072. (error, project) => {
  1073. if (error != null) {
  1074. throw error
  1075. }
  1076. this.root_folder_id = project.rootFolder[0]._id.toString()
  1077. this.project_0 = project
  1078. return done()
  1079. }
  1080. )
  1081. })
  1082. it('should version adding a doc', function(done) {
  1083. const tex_file = fs.createReadStream(
  1084. Path.resolve(__dirname + '/../files/test.tex')
  1085. )
  1086. const req = this.owner.request.post({
  1087. uri: `/user/${this.owner._id}/update/${
  1088. this.tpds_project_name
  1089. }/test.tex`,
  1090. auth: {
  1091. user: _.keys(Settings.httpAuthUsers)[0],
  1092. pass: _.values(Settings.httpAuthUsers)[0],
  1093. sendImmediately: true
  1094. }
  1095. })
  1096. tex_file.on('error', function(err) {
  1097. throw err
  1098. })
  1099. req.on('error', function(err) {
  1100. throw err
  1101. })
  1102. req.on('response', res => {
  1103. if (res.statusCode < 200 || res.statusCode >= 300) {
  1104. throw new Error(`failed to upload file ${res.statusCode}`)
  1105. }
  1106. const {
  1107. docUpdates: updates,
  1108. version
  1109. } = MockDocUpdaterApi.getProjectStructureUpdates(this.tpds_project_id)
  1110. expect(updates.length).to.equal(1)
  1111. const update = updates[0]
  1112. expect(update.userId).to.equal(this.owner._id)
  1113. expect(update.pathname).to.equal('/test.tex')
  1114. expect(update.docLines).to.equal('Test')
  1115. expect(version).to.equal(this.project_0.version + 1)
  1116. return ProjectGetter.getProject(
  1117. this.tpds_project_id,
  1118. (error, newProject) => {
  1119. if (error != null) {
  1120. throw error
  1121. }
  1122. this.project_1 = newProject
  1123. // replacing a file should update the project structure
  1124. expect(this.project_1.version).to.equal(this.project_0.version + 1)
  1125. return done()
  1126. }
  1127. )
  1128. })
  1129. return tex_file.pipe(req)
  1130. })
  1131. it('should version adding a new file', function(done) {
  1132. const image_file = fs.createReadStream(
  1133. Path.resolve(__dirname + '/../files/1pixel.png')
  1134. )
  1135. const req = this.owner.request.post({
  1136. uri: `/user/${this.owner._id}/update/${
  1137. this.tpds_project_name
  1138. }/1pixel.png`,
  1139. auth: {
  1140. user: _.keys(Settings.httpAuthUsers)[0],
  1141. pass: _.values(Settings.httpAuthUsers)[0],
  1142. sendImmediately: true
  1143. }
  1144. })
  1145. image_file.on('error', function(err) {
  1146. throw err
  1147. })
  1148. req.on('error', function(err) {
  1149. throw err
  1150. })
  1151. req.on('response', res => {
  1152. if (res.statusCode < 200 || res.statusCode >= 300) {
  1153. throw new Error(`failed to upload file ${res.statusCode}`)
  1154. }
  1155. const {
  1156. fileUpdates: updates,
  1157. version
  1158. } = MockDocUpdaterApi.getProjectStructureUpdates(this.tpds_project_id)
  1159. expect(updates.length).to.equal(1)
  1160. const update = updates[0]
  1161. expect(update.userId).to.equal(this.owner._id)
  1162. expect(update.pathname).to.equal('/1pixel.png')
  1163. expect(update.url).to.be.a('string')
  1164. expect(version).to.equal(this.project_0.version + 1)
  1165. return ProjectGetter.getProject(
  1166. this.tpds_project_id,
  1167. (error, newProject) => {
  1168. if (error != null) {
  1169. throw error
  1170. }
  1171. this.project_1 = newProject
  1172. // replacing a file should update the project structure
  1173. expect(this.project_1.version).to.equal(this.project_0.version + 1)
  1174. return done()
  1175. }
  1176. )
  1177. })
  1178. return image_file.pipe(req)
  1179. })
  1180. it('should version replacing a file', function(done) {
  1181. const image_file = fs.createReadStream(
  1182. Path.resolve(__dirname + '/../files/2pixel.png')
  1183. )
  1184. const req = this.owner.request.post({
  1185. uri: `/user/${this.owner._id}/update/${
  1186. this.tpds_project_name
  1187. }/1pixel.png`,
  1188. auth: {
  1189. user: _.keys(Settings.httpAuthUsers)[0],
  1190. pass: _.values(Settings.httpAuthUsers)[0],
  1191. sendImmediately: true
  1192. }
  1193. })
  1194. image_file.on('error', function(err) {
  1195. throw err
  1196. })
  1197. req.on('error', function(err) {
  1198. throw err
  1199. })
  1200. req.on('response', res => {
  1201. if (res.statusCode < 200 || res.statusCode >= 300) {
  1202. throw new Error(`failed to upload file ${res.statusCode}`)
  1203. }
  1204. const {
  1205. fileUpdates: updates,
  1206. version
  1207. } = MockDocUpdaterApi.getProjectStructureUpdates(this.tpds_project_id)
  1208. expect(updates.length).to.equal(2)
  1209. let update = updates[0]
  1210. expect(update.userId).to.equal(this.owner._id)
  1211. expect(update.pathname).to.equal('/1pixel.png')
  1212. // expect(update.url).to.be.a('string');
  1213. update = updates[1]
  1214. expect(update.userId).to.equal(this.owner._id)
  1215. expect(update.pathname).to.equal('/1pixel.png')
  1216. expect(update.url).to.be.a('string')
  1217. expect(version).to.equal(this.project_0.version + 1)
  1218. return ProjectGetter.getProject(
  1219. this.tpds_project_id,
  1220. (error, newProject) => {
  1221. if (error != null) {
  1222. throw error
  1223. }
  1224. this.project_1 = newProject
  1225. // replacing a file should update the project structure
  1226. expect(this.project_1.version).to.equal(this.project_0.version + 1)
  1227. return done()
  1228. }
  1229. )
  1230. })
  1231. return image_file.pipe(req)
  1232. })
  1233. it('should version deleting a doc', function(done) {
  1234. let req
  1235. return (req = this.owner.request.delete(
  1236. {
  1237. uri: `/user/${this.owner._id}/update/${
  1238. this.tpds_project_name
  1239. }/test.tex`,
  1240. auth: {
  1241. user: _.keys(Settings.httpAuthUsers)[0],
  1242. pass: _.values(Settings.httpAuthUsers)[0],
  1243. sendImmediately: true
  1244. }
  1245. },
  1246. (error, res, body) => {
  1247. if (error != null) {
  1248. throw error
  1249. }
  1250. if (res.statusCode < 200 || res.statusCode >= 300) {
  1251. throw new Error(`failed to delete doc ${res.statusCode}`)
  1252. }
  1253. const {
  1254. docUpdates: updates,
  1255. version
  1256. } = MockDocUpdaterApi.getProjectStructureUpdates(this.tpds_project_id)
  1257. expect(updates.length).to.equal(1)
  1258. const update = updates[0]
  1259. expect(update.userId).to.equal(this.owner._id)
  1260. expect(update.pathname).to.equal('/test.tex')
  1261. expect(update.newPathname).to.equal('')
  1262. expect(version).to.equal(this.project_0.version + 1)
  1263. return ProjectGetter.getProject(
  1264. this.tpds_project_id,
  1265. (error, newProject) => {
  1266. if (error != null) {
  1267. throw error
  1268. }
  1269. this.project_1 = newProject
  1270. // replacing a file should update the project structure
  1271. expect(this.project_1.version).to.equal(
  1272. this.project_0.version + 1
  1273. )
  1274. return done()
  1275. }
  1276. )
  1277. }
  1278. ))
  1279. })
  1280. })
  1281. describe('uploading a document', function() {
  1282. beforeEach(function(done) {
  1283. MockDocUpdaterApi.clearProjectStructureUpdates()
  1284. return ProjectGetter.getProject(example_project_id, (error, project) => {
  1285. if (error != null) {
  1286. throw error
  1287. }
  1288. this.root_folder_id = project.rootFolder[0]._id.toString()
  1289. this.project_0 = project
  1290. return done()
  1291. })
  1292. })
  1293. describe('with an unusual character set', function() {
  1294. it('should correctly handle utf16-le data', function(done) {
  1295. let req
  1296. const document_file = fs.createReadStream(
  1297. Path.resolve(
  1298. __dirname + '/../files/charsets/test-greek-utf16-le-bom.tex'
  1299. )
  1300. )
  1301. return (req = this.owner.request.post(
  1302. {
  1303. uri: `project/${example_project_id}/upload`,
  1304. qs: {
  1305. folder_id: this.root_folder_id
  1306. },
  1307. formData: {
  1308. qqfile: {
  1309. value: document_file,
  1310. options: {
  1311. filename: 'test-greek-utf16-le-bom.tex',
  1312. contentType: 'text/x-tex'
  1313. }
  1314. }
  1315. }
  1316. },
  1317. (error, res, body) => {
  1318. if (error != null) {
  1319. throw error
  1320. }
  1321. if (res.statusCode < 200 || res.statusCode >= 300) {
  1322. throw new Error(`failed to upload file ${res.statusCode}`)
  1323. }
  1324. example_file_id = JSON.parse(body).entity_id
  1325. const {
  1326. docUpdates: updates
  1327. } = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id)
  1328. const update = updates[0]
  1329. expect(update.pathname).to.equal('/test-greek-utf16-le-bom.tex')
  1330. expect(update.docLines).to.contain(
  1331. 'Η γρήγορη καστανή αλεπού πήδηξε χαλαρά πάνω από το σκυλί.'
  1332. )
  1333. return done()
  1334. }
  1335. ))
  1336. })
  1337. it('should correctly handle windows1252/iso-8859-1/latin1 data', function(done) {
  1338. let req
  1339. const document_file = fs.createReadStream(
  1340. Path.resolve(
  1341. __dirname + '/../files/charsets/test-german-windows-1252.tex'
  1342. )
  1343. )
  1344. return (req = this.owner.request.post(
  1345. {
  1346. uri: `project/${example_project_id}/upload`,
  1347. qs: {
  1348. folder_id: this.root_folder_id
  1349. },
  1350. formData: {
  1351. qqfile: {
  1352. value: document_file,
  1353. options: {
  1354. filename: 'test-german-windows-1252.tex',
  1355. contentType: 'text/x-tex'
  1356. }
  1357. }
  1358. }
  1359. },
  1360. (error, res, body) => {
  1361. if (error != null) {
  1362. throw error
  1363. }
  1364. if (res.statusCode < 200 || res.statusCode >= 300) {
  1365. throw new Error(`failed to upload file ${res.statusCode}`)
  1366. }
  1367. example_file_id = JSON.parse(body).entity_id
  1368. const {
  1369. docUpdates: updates
  1370. } = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id)
  1371. const update = updates[0]
  1372. expect(update.pathname).to.equal('/test-german-windows-1252.tex')
  1373. expect(update.docLines).to.contain(
  1374. 'Der schnelle braune Fuchs sprang träge über den Hund.'
  1375. )
  1376. return done()
  1377. }
  1378. ))
  1379. })
  1380. })
  1381. })
  1382. })