ProjectEditorHandlerTests.coffee 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. chai = require('chai')
  2. should = chai.should()
  3. modulePath = "../../../../app/js/Features/Project/ProjectEditorHandler"
  4. SandboxedModule = require('sandboxed-module')
  5. describe "ProjectEditorHandler", ->
  6. beforeEach ->
  7. @project =
  8. _id : "project-id"
  9. name : "Project Name"
  10. rootDoc_id : "file-id"
  11. publicAccesLevel : "private"
  12. deletedByExternalDataSource: false
  13. rootFolder : [{
  14. _id : "root-folder-id"
  15. name : ""
  16. docs : []
  17. fileRefs : []
  18. folders : [{
  19. _id : "sub-folder-id"
  20. name : "folder"
  21. docs : [{
  22. _id : "doc-id"
  23. name : "main.tex"
  24. lines : @lines = [
  25. "line 1"
  26. "line 2"
  27. "line 3"
  28. ]
  29. }]
  30. fileRefs : [{
  31. _id : "file-id"
  32. name : "image.png"
  33. created : new Date()
  34. size : 1234
  35. }]
  36. folders : []
  37. }]
  38. }]
  39. owner_ref :
  40. _id: "owner-id"
  41. first_name : "Owner"
  42. last_name : "ShareLaTeX"
  43. email : "owner@sharelatex.com"
  44. readOnly_refs: [{
  45. _id: "read-only-id"
  46. first_name : "Read"
  47. last_name : "Only"
  48. email : "read-only@sharelatex.com"
  49. }]
  50. collaberator_refs: [{
  51. _id: "read-write-id"
  52. first_name : "Read"
  53. last_name : "Write"
  54. email : "read-write@sharelatex.com"
  55. }]
  56. @handler = SandboxedModule.require modulePath
  57. describe "buildProjectModelView", ->
  58. describe "with owner and members included", ->
  59. beforeEach ->
  60. @result = @handler.buildProjectModelView @project
  61. it "should include the id", ->
  62. should.exist @result._id
  63. @result._id.should.equal "project-id"
  64. it "should include the name", ->
  65. should.exist @result.name
  66. @result.name.should.equal "Project Name"
  67. it "should include the root doc id", ->
  68. should.exist @result.rootDoc_id
  69. @result.rootDoc_id.should.equal "file-id"
  70. it "should include the public access level", ->
  71. should.exist @result.publicAccesLevel
  72. @result.publicAccesLevel.should.equal "private"
  73. it "should include the owner", ->
  74. should.exist @result.owner
  75. @result.owner._id.should.equal "owner-id"
  76. @result.owner.email.should.equal "owner@sharelatex.com"
  77. @result.owner.first_name.should.equal "Owner"
  78. @result.owner.last_name.should.equal "ShareLaTeX"
  79. @result.owner.privileges.should.equal "owner"
  80. it "should gather readOnly_refs and collaberators_refs into a list of members", ->
  81. findMember = (id) =>
  82. for member in @result.members
  83. return member if member._id == id
  84. return null
  85. @result.members.length.should.equal 2
  86. should.exist findMember("read-only-id")
  87. findMember("read-only-id").privileges.should.equal "readOnly"
  88. findMember("read-only-id").first_name.should.equal "Read"
  89. findMember("read-only-id").last_name.should.equal "Only"
  90. findMember("read-only-id").email.should.equal "read-only@sharelatex.com"
  91. should.exist findMember("read-write-id")
  92. findMember("read-write-id").privileges.should.equal "readAndWrite"
  93. findMember("read-write-id").first_name.should.equal "Read"
  94. findMember("read-write-id").last_name.should.equal "Write"
  95. findMember("read-write-id").email.should.equal "read-write@sharelatex.com"
  96. it "should include folders in the project", ->
  97. @result.rootFolder[0]._id.should.equal "root-folder-id"
  98. @result.rootFolder[0].name.should.equal ""
  99. @result.rootFolder[0].folders[0]._id.should.equal "sub-folder-id"
  100. @result.rootFolder[0].folders[0].name.should.equal "folder"
  101. it "should not duplicate folder contents", ->
  102. @result.rootFolder[0].docs.length.should.equal 0
  103. @result.rootFolder[0].fileRefs.length.should.equal 0
  104. it "should include files in the project", ->
  105. @result.rootFolder[0].folders[0].fileRefs[0]._id.should.equal "file-id"
  106. @result.rootFolder[0].folders[0].fileRefs[0].name.should.equal "image.png"
  107. should.not.exist @result.rootFolder[0].folders[0].fileRefs[0].created
  108. should.not.exist @result.rootFolder[0].folders[0].fileRefs[0].size
  109. it "should include docs in the project but not the lines", ->
  110. @result.rootFolder[0].folders[0].docs[0]._id.should.equal "doc-id"
  111. @result.rootFolder[0].folders[0].docs[0].name.should.equal "main.tex"
  112. should.not.exist @result.rootFolder[0].folders[0].docs[0].lines
  113. describe "deletedByExternalDataSource", ->
  114. it "should set the deletedByExternalDataSource flag to false when it is not there", ->
  115. delete @project.deletedByExternalDataSource
  116. result = @handler.buildProjectModelView @project
  117. result.deletedByExternalDataSource.should.equal false
  118. it "should set the deletedByExternalDataSource flag to false when it is false", ->
  119. result = @handler.buildProjectModelView @project
  120. result.deletedByExternalDataSource.should.equal false
  121. it "should set the deletedByExternalDataSource flag to true when it is true", ->
  122. @project.deletedByExternalDataSource = true
  123. result = @handler.buildProjectModelView @project
  124. result.deletedByExternalDataSource.should.equal true
  125. describe "features", ->
  126. beforeEach ->
  127. @project.owner_ref.features =
  128. versioning: true
  129. collaborators: 3
  130. @result = @handler.buildProjectModelView @project
  131. it "should copy the owner features to the project", ->
  132. @result.features.versioning.should.equal @project.owner_ref.features.versioning
  133. @result.features.collaborators.should.equal @project.owner_ref.features.collaborators
  134. describe "without owners and members", ->
  135. beforeEach ->
  136. @result = @handler.buildProjectModelView @project, includeUsers: false
  137. it "should not include the owner", ->
  138. should.not.exist @result.owner
  139. it "should not include the members", ->
  140. should.not.exist @result.members