ProjectControllerTests.js 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  1. const SandboxedModule = require('sandboxed-module')
  2. const path = require('path')
  3. const sinon = require('sinon')
  4. const { expect } = require('chai')
  5. const HttpErrors = require('@overleaf/o-error/http')
  6. const { ObjectId } = require('mongodb')
  7. const Errors = require('../../../../app/src/Features/Errors/Errors')
  8. const MODULE_PATH = path.join(
  9. __dirname,
  10. '../../../../app/src/Features/Project/ProjectController'
  11. )
  12. describe('ProjectController', function() {
  13. beforeEach(function() {
  14. this.project_id = ObjectId('abcdefabcdefabcdefabcdef')
  15. this.user = {
  16. _id: ObjectId('123456123456123456123456'),
  17. email: 'test@overleaf.com',
  18. first_name: 'bjkdsjfk',
  19. features: {},
  20. emails: [{ email: 'test@overleaf.com' }]
  21. }
  22. this.settings = {
  23. apis: {
  24. chat: {
  25. url: 'chat.com'
  26. }
  27. },
  28. siteUrl: 'mysite.com',
  29. algolia: {}
  30. }
  31. this.brandVariationDetails = {
  32. id: '12',
  33. active: true,
  34. brand_name: 'The journal',
  35. home_url: 'http://www.thejournal.com/',
  36. publish_menu_link_html: 'Submit your paper to the <em>The Journal</em>'
  37. }
  38. this.token = 'some-token'
  39. this.ProjectDeleter = {
  40. legacyArchiveProject: sinon.stub().callsArg(1),
  41. deleteProject: sinon.stub().callsArg(2),
  42. restoreProject: sinon.stub().callsArg(1),
  43. findArchivedProjects: sinon.stub()
  44. }
  45. this.ProjectDuplicator = {
  46. duplicate: sinon.stub().callsArgWith(3, null, { _id: this.project_id })
  47. }
  48. this.ProjectCreationHandler = {
  49. createExampleProject: sinon
  50. .stub()
  51. .callsArgWith(2, null, { _id: this.project_id }),
  52. createBasicProject: sinon
  53. .stub()
  54. .callsArgWith(2, null, { _id: this.project_id })
  55. }
  56. this.SubscriptionLocator = { getUsersSubscription: sinon.stub() }
  57. this.LimitationsManager = { hasPaidSubscription: sinon.stub() }
  58. this.TagsHandler = { getAllTags: sinon.stub() }
  59. this.NotificationsHandler = { getUserNotifications: sinon.stub() }
  60. this.UserModel = { findById: sinon.stub() }
  61. this.AuthorizationManager = {
  62. getPrivilegeLevelForProject: sinon.stub(),
  63. isRestrictedUser: sinon.stub().returns(false)
  64. }
  65. this.EditorController = { renameProject: sinon.stub() }
  66. this.InactiveProjectManager = { reactivateProjectIfRequired: sinon.stub() }
  67. this.ProjectUpdateHandler = { markAsOpened: sinon.stub() }
  68. this.ReferencesSearchHandler = { indexProjectReferences: sinon.stub() }
  69. this.ProjectGetter = {
  70. findAllUsersProjects: sinon.stub(),
  71. getProject: sinon.stub()
  72. }
  73. this.ProjectDetailsHandler = {
  74. transferOwnership: sinon.stub().yields()
  75. }
  76. this.ProjectHelper = {
  77. isArchived: sinon.stub(),
  78. isTrashed: sinon.stub(),
  79. isArchivedOrTrashed: sinon.stub()
  80. }
  81. this.AuthenticationController = {
  82. getLoggedInUser: sinon.stub().callsArgWith(1, null, this.user),
  83. getLoggedInUserId: sinon.stub().returns(this.user._id),
  84. getSessionUser: sinon.stub().returns(this.user),
  85. isUserLoggedIn: sinon.stub().returns(true)
  86. }
  87. this.AnalyticsManager = { getLastOccurrence: sinon.stub() }
  88. this.TokenAccessHandler = {
  89. getRequestToken: sinon.stub().returns(this.token),
  90. protectTokens: sinon.stub()
  91. }
  92. this.CollaboratorsGetter = {
  93. userIsTokenMember: sinon.stub().callsArgWith(2, null, false)
  94. }
  95. this.ProjectEntityHandler = {}
  96. this.NotificationBuilder = {
  97. ipMatcherAffiliation: sinon.stub().returns({ create: sinon.stub() })
  98. }
  99. this.UserGetter = {
  100. getUser: sinon
  101. .stub()
  102. .callsArgWith(2, null, { lastLoginIp: '192.170.18.2' })
  103. }
  104. this.Modules = {
  105. hooks: {
  106. fire: sinon.stub()
  107. }
  108. }
  109. this.Features = {
  110. hasFeature: sinon
  111. .stub()
  112. .withArgs('saml')
  113. .returns(false)
  114. }
  115. this.BrandVariationsHandler = {
  116. getBrandVariationById: sinon
  117. .stub()
  118. .callsArgWith(1, null, this.brandVariationDetails)
  119. }
  120. this.getUserAffiliations = sinon.stub().callsArgWith(1, null, [
  121. {
  122. email: 'test@overleaf.com',
  123. institution: {
  124. id: 1,
  125. name: 'Overleaf',
  126. ssoEnabled: true
  127. }
  128. }
  129. ])
  130. this.ProjectController = SandboxedModule.require(MODULE_PATH, {
  131. globals: {
  132. console: console
  133. },
  134. requires: {
  135. 'settings-sharelatex': this.settings,
  136. 'logger-sharelatex': {
  137. log() {},
  138. err() {}
  139. },
  140. 'metrics-sharelatex': {
  141. Timer: class {
  142. done() {}
  143. },
  144. inc() {}
  145. },
  146. '@overleaf/o-error/http': HttpErrors,
  147. './ProjectDeleter': this.ProjectDeleter,
  148. './ProjectDuplicator': this.ProjectDuplicator,
  149. './ProjectCreationHandler': this.ProjectCreationHandler,
  150. '../Editor/EditorController': this.EditorController,
  151. './ProjectHelper': this.ProjectHelper,
  152. '../Subscription/SubscriptionLocator': this.SubscriptionLocator,
  153. '../Subscription/LimitationsManager': this.LimitationsManager,
  154. '../Tags/TagsHandler': this.TagsHandler,
  155. '../Notifications/NotificationsHandler': this.NotificationsHandler,
  156. '../../models/User': {
  157. User: this.UserModel
  158. },
  159. '../Authorization/AuthorizationManager': this.AuthorizationManager,
  160. '../InactiveData/InactiveProjectManager': this.InactiveProjectManager,
  161. './ProjectUpdateHandler': this.ProjectUpdateHandler,
  162. '../ReferencesSearch/ReferencesSearchHandler': this
  163. .ReferencesSearchHandler,
  164. './ProjectGetter': this.ProjectGetter,
  165. './ProjectDetailsHandler': this.ProjectDetailsHandler,
  166. '../Authentication/AuthenticationController': this
  167. .AuthenticationController,
  168. '../Analytics/AnalyticsManager': this.AnalyticsManager,
  169. '../TokenAccess/TokenAccessHandler': this.TokenAccessHandler,
  170. '../Collaborators/CollaboratorsGetter': this.CollaboratorsGetter,
  171. '../../infrastructure/Modules': this.Modules,
  172. './ProjectEntityHandler': this.ProjectEntityHandler,
  173. '../Errors/Errors': Errors,
  174. '../../infrastructure/Features': this.Features,
  175. '../Notifications/NotificationsBuilder': this.NotificationBuilder,
  176. '../User/UserGetter': this.UserGetter,
  177. '../BrandVariations/BrandVariationsHandler': this
  178. .BrandVariationsHandler,
  179. '../Institutions/InstitutionsAPI': {
  180. getUserAffiliations: this.getUserAffiliations
  181. },
  182. '../V1/V1Handler': {},
  183. '../../models/Project': {}
  184. }
  185. })
  186. this.projectName = '£12321jkj9ujkljds'
  187. this.req = {
  188. params: {
  189. Project_id: this.project_id
  190. },
  191. headers: {},
  192. connection: {
  193. remoteAddress: '192.170.18.1'
  194. },
  195. session: {
  196. user: this.user
  197. },
  198. body: {
  199. projectName: this.projectName
  200. },
  201. i18n: {
  202. translate() {}
  203. },
  204. ip: '192.170.18.1'
  205. }
  206. this.res = {
  207. locals: {
  208. jsPath: 'js path here'
  209. },
  210. setTimeout: sinon.stub()
  211. }
  212. })
  213. describe('updateProjectSettings', function() {
  214. it('should update the name', function(done) {
  215. this.EditorController.renameProject = sinon.stub().callsArg(2)
  216. this.req.body = { name: (this.name = 'New name') }
  217. this.res.sendStatus = code => {
  218. this.EditorController.renameProject
  219. .calledWith(this.project_id, this.name)
  220. .should.equal(true)
  221. code.should.equal(204)
  222. done()
  223. }
  224. this.ProjectController.updateProjectSettings(this.req, this.res)
  225. })
  226. it('should update the compiler', function(done) {
  227. this.EditorController.setCompiler = sinon.stub().callsArg(2)
  228. this.req.body = { compiler: (this.compiler = 'pdflatex') }
  229. this.res.sendStatus = code => {
  230. this.EditorController.setCompiler
  231. .calledWith(this.project_id, this.compiler)
  232. .should.equal(true)
  233. code.should.equal(204)
  234. done()
  235. }
  236. this.ProjectController.updateProjectSettings(this.req, this.res)
  237. })
  238. it('should update the imageName', function(done) {
  239. this.EditorController.setImageName = sinon.stub().callsArg(2)
  240. this.req.body = { imageName: (this.imageName = 'texlive-1234.5') }
  241. this.res.sendStatus = code => {
  242. this.EditorController.setImageName
  243. .calledWith(this.project_id, this.imageName)
  244. .should.equal(true)
  245. code.should.equal(204)
  246. done()
  247. }
  248. this.ProjectController.updateProjectSettings(this.req, this.res)
  249. })
  250. it('should update the spell check language', function(done) {
  251. this.EditorController.setSpellCheckLanguage = sinon.stub().callsArg(2)
  252. this.req.body = { spellCheckLanguage: (this.languageCode = 'fr') }
  253. this.res.sendStatus = code => {
  254. this.EditorController.setSpellCheckLanguage
  255. .calledWith(this.project_id, this.languageCode)
  256. .should.equal(true)
  257. code.should.equal(204)
  258. done()
  259. }
  260. this.ProjectController.updateProjectSettings(this.req, this.res)
  261. })
  262. it('should update the root doc', function(done) {
  263. this.EditorController.setRootDoc = sinon.stub().callsArg(2)
  264. this.req.body = { rootDocId: (this.rootDocId = 'root-doc-id') }
  265. this.res.sendStatus = code => {
  266. this.EditorController.setRootDoc
  267. .calledWith(this.project_id, this.rootDocId)
  268. .should.equal(true)
  269. code.should.equal(204)
  270. done()
  271. }
  272. this.ProjectController.updateProjectSettings(this.req, this.res)
  273. })
  274. })
  275. describe('updateProjectAdminSettings', function() {
  276. it('should update the public access level', function(done) {
  277. this.EditorController.setPublicAccessLevel = sinon.stub().callsArg(2)
  278. this.req.body = {
  279. publicAccessLevel: (this.publicAccessLevel = 'readonly')
  280. }
  281. this.res.sendStatus = code => {
  282. this.EditorController.setPublicAccessLevel
  283. .calledWith(this.project_id, this.publicAccessLevel)
  284. .should.equal(true)
  285. code.should.equal(204)
  286. done()
  287. }
  288. this.ProjectController.updateProjectAdminSettings(this.req, this.res)
  289. })
  290. })
  291. describe('deleteProject', function() {
  292. it('should tell the project deleter to archive when forever=false', function(done) {
  293. this.res.sendStatus = code => {
  294. this.ProjectDeleter.legacyArchiveProject
  295. .calledWith(this.project_id)
  296. .should.equal(true)
  297. code.should.equal(200)
  298. done()
  299. }
  300. this.ProjectController.deleteProject(this.req, this.res)
  301. })
  302. it('should tell the project deleter to delete when forever=true', function(done) {
  303. this.req.query = { forever: 'true' }
  304. this.res.sendStatus = code => {
  305. this.ProjectDeleter.deleteProject
  306. .calledWith(this.project_id, {
  307. deleterUser: this.user,
  308. ipAddress: this.req.ip
  309. })
  310. .should.equal(true)
  311. code.should.equal(200)
  312. done()
  313. }
  314. this.ProjectController.deleteProject(this.req, this.res)
  315. })
  316. })
  317. describe('restoreProject', function() {
  318. it('should tell the project deleter', function(done) {
  319. this.res.sendStatus = code => {
  320. this.ProjectDeleter.restoreProject
  321. .calledWith(this.project_id)
  322. .should.equal(true)
  323. code.should.equal(200)
  324. done()
  325. }
  326. this.ProjectController.restoreProject(this.req, this.res)
  327. })
  328. })
  329. describe('cloneProject', function() {
  330. it('should call the project duplicator', function(done) {
  331. this.res.send = json => {
  332. this.ProjectDuplicator.duplicate
  333. .calledWith(this.user, this.project_id, this.projectName)
  334. .should.equal(true)
  335. json.project_id.should.equal(this.project_id)
  336. done()
  337. }
  338. this.ProjectController.cloneProject(this.req, this.res)
  339. })
  340. })
  341. describe('newProject', function() {
  342. it('should call the projectCreationHandler with createExampleProject', function(done) {
  343. this.req.body.template = 'example'
  344. this.res.send = json => {
  345. this.ProjectCreationHandler.createExampleProject
  346. .calledWith(this.user._id, this.projectName)
  347. .should.equal(true)
  348. this.ProjectCreationHandler.createBasicProject.called.should.equal(
  349. false
  350. )
  351. done()
  352. }
  353. this.ProjectController.newProject(this.req, this.res)
  354. })
  355. it('should call the projectCreationHandler with createBasicProject', function(done) {
  356. this.req.body.template = 'basic'
  357. this.res.send = json => {
  358. this.ProjectCreationHandler.createExampleProject.called.should.equal(
  359. false
  360. )
  361. this.ProjectCreationHandler.createBasicProject
  362. .calledWith(this.user._id, this.projectName)
  363. .should.equal(true)
  364. done()
  365. }
  366. this.ProjectController.newProject(this.req, this.res)
  367. })
  368. })
  369. describe('projectListPage', function() {
  370. beforeEach(function() {
  371. this.tags = [
  372. { name: 1, project_ids: ['1', '2', '3'] },
  373. { name: 2, project_ids: ['a', '1'] },
  374. { name: 3, project_ids: ['a', 'b', 'c', 'd'] }
  375. ]
  376. this.notifications = [
  377. { _id: '1', user_id: '2', templateKey: '3', messageOpts: '4', key: '5' }
  378. ]
  379. this.projects = [
  380. { _id: 1, lastUpdated: 1, owner_ref: 'user-1' },
  381. { _id: 2, lastUpdated: 2, owner_ref: 'user-2', lastUpdatedBy: 'user-1' }
  382. ]
  383. this.collabertions = [{ _id: 5, lastUpdated: 5, owner_ref: 'user-1' }]
  384. this.readOnly = [{ _id: 3, lastUpdated: 3, owner_ref: 'user-1' }]
  385. this.tokenReadAndWrite = [{ _id: 6, lastUpdated: 5, owner_ref: 'user-4' }]
  386. this.tokenReadOnly = [{ _id: 7, lastUpdated: 4, owner_ref: 'user-5' }]
  387. this.allProjects = {
  388. owned: this.projects,
  389. readAndWrite: this.collabertions,
  390. readOnly: this.readOnly,
  391. tokenReadAndWrite: this.tokenReadAndWrite,
  392. tokenReadOnly: this.tokenReadOnly
  393. }
  394. this.users = {
  395. 'user-1': {
  396. first_name: 'James'
  397. },
  398. 'user-2': {
  399. first_name: 'Henry'
  400. }
  401. }
  402. this.users[this.user._id] = this.user // Owner
  403. this.UserModel.findById = (id, fields, callback) => {
  404. callback(null, this.users[id])
  405. }
  406. this.UserGetter.getUser = (id, fields, callback) => {
  407. callback(null, this.users[id])
  408. }
  409. this.LimitationsManager.hasPaidSubscription.callsArgWith(1, null, false)
  410. this.TagsHandler.getAllTags.callsArgWith(1, null, this.tags)
  411. this.NotificationsHandler.getUserNotifications = sinon
  412. .stub()
  413. .callsArgWith(1, null, this.notifications, {})
  414. this.ProjectGetter.findAllUsersProjects.callsArgWith(
  415. 2,
  416. null,
  417. this.allProjects
  418. )
  419. this.Modules.hooks.fire
  420. .withArgs('findAllV1Projects', this.user._id)
  421. .yields(undefined)
  422. }) // Without integration module hook, cb returns undefined
  423. it('should render the project/list page', function(done) {
  424. this.res.render = (pageName, opts) => {
  425. pageName.should.equal('project/list')
  426. done()
  427. }
  428. this.ProjectController.projectListPage(this.req, this.res)
  429. })
  430. it('should send the tags', function(done) {
  431. this.res.render = (pageName, opts) => {
  432. opts.tags.length.should.equal(this.tags.length)
  433. done()
  434. }
  435. this.ProjectController.projectListPage(this.req, this.res)
  436. })
  437. it('should create trigger ip matcher notifications', function(done) {
  438. this.settings.overleaf = true
  439. this.res.render = (pageName, opts) => {
  440. this.NotificationBuilder.ipMatcherAffiliation.called.should.equal(true)
  441. done()
  442. }
  443. this.ProjectController.projectListPage(this.req, this.res)
  444. })
  445. it('should send the projects', function(done) {
  446. this.res.render = (pageName, opts) => {
  447. opts.projects.length.should.equal(
  448. this.projects.length +
  449. this.collabertions.length +
  450. this.readOnly.length +
  451. this.tokenReadAndWrite.length +
  452. this.tokenReadOnly.length
  453. )
  454. done()
  455. }
  456. this.ProjectController.projectListPage(this.req, this.res)
  457. })
  458. it('should send the user', function(done) {
  459. this.res.render = (pageName, opts) => {
  460. opts.user.should.deep.equal(this.user)
  461. done()
  462. }
  463. this.ProjectController.projectListPage(this.req, this.res)
  464. })
  465. it('should inject the users', function(done) {
  466. this.res.render = (pageName, opts) => {
  467. opts.projects[0].owner.should.equal(
  468. this.users[this.projects[0].owner_ref]
  469. )
  470. opts.projects[1].owner.should.equal(
  471. this.users[this.projects[1].owner_ref]
  472. )
  473. opts.projects[1].lastUpdatedBy.should.equal(
  474. this.users[this.projects[1].lastUpdatedBy]
  475. )
  476. done()
  477. }
  478. this.ProjectController.projectListPage(this.req, this.res)
  479. })
  480. it('should send hasSubscription == false when no subscription', function(done) {
  481. this.res.render = (pageName, opts) => {
  482. opts.hasSubscription.should.equal(false)
  483. done()
  484. }
  485. this.ProjectController.projectListPage(this.req, this.res)
  486. })
  487. it('should send hasSubscription == true when there is a subscription', function(done) {
  488. this.LimitationsManager.hasPaidSubscription = sinon
  489. .stub()
  490. .callsArgWith(1, null, true)
  491. this.res.render = (pageName, opts) => {
  492. opts.hasSubscription.should.equal(true)
  493. done()
  494. }
  495. this.ProjectController.projectListPage(this.req, this.res)
  496. })
  497. describe('front widget', function(done) {
  498. beforeEach(function() {
  499. this.settings.overleaf = {
  500. front_chat_widget_room_id: 'chat-room-id'
  501. }
  502. })
  503. it('should show for paid users', function(done) {
  504. this.user.features.github = true
  505. this.user.features.dropbox = true
  506. this.res.render = (pageName, opts) => {
  507. opts.frontChatWidgetRoomId.should.equal(
  508. this.settings.overleaf.front_chat_widget_room_id
  509. )
  510. done()
  511. }
  512. this.ProjectController.projectListPage(this.req, this.res)
  513. })
  514. it('should show for sample users', function(done) {
  515. this.user._id = ObjectId('588f3ddae8ebc1bac07c9f00') // last two digits
  516. this.res.render = (pageName, opts) => {
  517. opts.frontChatWidgetRoomId.should.equal(
  518. this.settings.overleaf.front_chat_widget_room_id
  519. )
  520. done()
  521. }
  522. this.ProjectController.projectListPage(this.req, this.res)
  523. })
  524. it('should not show for non sample users', function(done) {
  525. this.user._id = ObjectId('588f3ddae8ebc1bac07c9fff') // last two digits
  526. this.res.render = (pageName, opts) => {
  527. expect(opts.frontChatWidgetRoomId).to.equal(undefined)
  528. done()
  529. }
  530. this.ProjectController.projectListPage(this.req, this.res)
  531. })
  532. })
  533. describe('with overleaf-integration-web-module hook', function() {
  534. beforeEach(function() {
  535. this.Features.hasFeature = sinon
  536. .stub()
  537. .withArgs('overleaf-integration')
  538. .returns(true)
  539. this.V1Response = {
  540. projects: [
  541. {
  542. id: '123mockV1Id',
  543. title: 'mock title',
  544. updated_at: 1509616411,
  545. removed: false,
  546. archived: false
  547. },
  548. {
  549. id: '456mockV1Id',
  550. title: 'mock title 2',
  551. updated_at: 1509616411,
  552. removed: true,
  553. archived: false
  554. }
  555. ],
  556. tags: [{ name: 'mock tag', project_ids: ['123mockV1Id'] }]
  557. }
  558. this.Modules.hooks.fire
  559. .withArgs('findAllV1Projects', this.user._id)
  560. .yields(null, [this.V1Response])
  561. }) // Need to wrap response in array, as multiple hooks could fire
  562. it('should include V1 projects', function(done) {
  563. this.res.render = (pageName, opts) => {
  564. opts.projects.length.should.equal(
  565. this.projects.length +
  566. this.collabertions.length +
  567. this.readOnly.length +
  568. this.tokenReadAndWrite.length +
  569. this.tokenReadOnly.length +
  570. this.V1Response.projects.length
  571. )
  572. opts.projects.forEach(p => {
  573. // Check properties correctly mapped from V1
  574. expect(p).to.have.property('id')
  575. expect(p).to.have.property('name')
  576. expect(p).to.have.property('lastUpdated')
  577. expect(p).to.have.property('accessLevel')
  578. expect(p).to.have.property('archived')
  579. })
  580. done()
  581. }
  582. this.ProjectController.projectListPage(this.req, this.res)
  583. })
  584. it('should include V1 tags', function(done) {
  585. this.res.render = (pageName, opts) => {
  586. opts.tags.length.should.equal(
  587. this.tags.length + this.V1Response.tags.length
  588. )
  589. opts.tags.forEach(t => {
  590. expect(t).to.have.property('name')
  591. expect(t).to.have.property('project_ids')
  592. })
  593. done()
  594. }
  595. this.ProjectController.projectListPage(this.req, this.res)
  596. })
  597. it('should have isShowingV1Projects flag', function(done) {
  598. this.res.render = (pageName, opts) => {
  599. opts.isShowingV1Projects.should.equal(true)
  600. done()
  601. }
  602. this.ProjectController.projectListPage(this.req, this.res)
  603. })
  604. })
  605. describe('When Institution SSO is released', function() {
  606. beforeEach(function(done) {
  607. this.institutionEmail = 'test@overleaf.com'
  608. this.institutionName = 'Overleaf'
  609. this.Features.hasFeature.withArgs('saml').returns(true)
  610. done()
  611. })
  612. it('should show institution SSO available notification', function() {
  613. this.res.render = (pageName, opts) => {
  614. expect(opts.notifications).to.deep.include({
  615. email: 'test@overleaf.com',
  616. institutionId: 1,
  617. institutionName: 'Overleaf',
  618. templateKey: 'notification_institution_sso_available'
  619. })
  620. }
  621. this.ProjectController.projectListPage(this.req, this.res)
  622. })
  623. it('should show a linked notification', function() {
  624. this.req.session.saml = {
  625. institutionEmail: this.institutionEmail,
  626. linked: {
  627. hasEntitlement: false,
  628. universityName: this.institutionName
  629. }
  630. }
  631. this.res.render = (pageName, opts) => {
  632. expect(opts.notifications).to.deep.include({
  633. email: this.institutionEmail,
  634. institutionName: this.institutionName,
  635. templateKey: 'notification_institution_sso_linked'
  636. })
  637. }
  638. this.ProjectController.projectListPage(this.req, this.res)
  639. })
  640. it('should show a linked another email notification', function() {
  641. // when they request to link an email but the institution returns
  642. // a different email
  643. this.res.render = (pageName, opts) => {
  644. expect(opts.notifications).to.deep.include({
  645. institutionEmail: this.institutionEmail,
  646. requestedEmail: 'requested@overleaf.com',
  647. templateKey: 'notification_institution_sso_non_canonical'
  648. })
  649. }
  650. this.req.session.saml = {
  651. emailNonCanonical: this.institutionEmail,
  652. institutionEmail: this.institutionEmail,
  653. requestedEmail: 'requested@overleaf.com',
  654. linked: {
  655. hasEntitlement: false,
  656. universityName: this.institutionName
  657. }
  658. }
  659. this.ProjectController.projectListPage(this.req, this.res)
  660. })
  661. it('should show a notification when intent was to register via SSO but account existed', function() {
  662. this.res.render = (pageName, opts) => {
  663. expect(opts.notifications).to.deep.include({
  664. email: this.institutionEmail,
  665. templateKey: 'notification_institution_sso_already_registered'
  666. })
  667. }
  668. this.req.session.saml = {
  669. institutionEmail: this.institutionEmail,
  670. linked: {
  671. hasEntitlement: false,
  672. universityName: 'Overleaf'
  673. },
  674. registerIntercept: true
  675. }
  676. this.ProjectController.projectListPage(this.req, this.res)
  677. })
  678. })
  679. describe('When Institution SSO is not released', function() {
  680. beforeEach(function(done) {
  681. this.Features.hasFeature.withArgs('saml').returns(false)
  682. done()
  683. })
  684. it('should not show institution sso available notification', function() {
  685. this.res.render = (pageName, opts) => {
  686. expect(opts.notifications).to.deep.not.include({
  687. email: 'test@overleaf.com',
  688. institutionId: 1,
  689. institutionName: 'Overleaf',
  690. templateKey: 'notification_institution_sso_available'
  691. })
  692. }
  693. this.ProjectController.projectListPage(this.req, this.res)
  694. })
  695. })
  696. })
  697. describe('projectListPage with duplicate projects', function() {
  698. beforeEach(function() {
  699. this.tags = [
  700. { name: 1, project_ids: ['1', '2', '3'] },
  701. { name: 2, project_ids: ['a', '1'] },
  702. { name: 3, project_ids: ['a', 'b', 'c', 'd'] }
  703. ]
  704. this.notifications = [
  705. { _id: '1', user_id: '2', templateKey: '3', messageOpts: '4', key: '5' }
  706. ]
  707. this.projects = [
  708. { _id: 1, lastUpdated: 1, owner_ref: 'user-1' },
  709. { _id: 2, lastUpdated: 2, owner_ref: 'user-2' }
  710. ]
  711. this.collabertions = [{ _id: 5, lastUpdated: 5, owner_ref: 'user-1' }]
  712. this.readOnly = [{ _id: 3, lastUpdated: 3, owner_ref: 'user-1' }]
  713. this.tokenReadAndWrite = [{ _id: 6, lastUpdated: 5, owner_ref: 'user-4' }]
  714. this.tokenReadOnly = [
  715. { _id: 6, lastUpdated: 5, owner_ref: 'user-4' }, // Also in tokenReadAndWrite
  716. { _id: 7, lastUpdated: 4, owner_ref: 'user-5' }
  717. ]
  718. this.allProjects = {
  719. owned: this.projects,
  720. readAndWrite: this.collabertions,
  721. readOnly: this.readOnly,
  722. tokenReadAndWrite: this.tokenReadAndWrite,
  723. tokenReadOnly: this.tokenReadOnly
  724. }
  725. this.users = {
  726. 'user-1': {
  727. first_name: 'James'
  728. },
  729. 'user-2': {
  730. first_name: 'Henry'
  731. }
  732. }
  733. this.users[this.user._id] = this.user // Owner
  734. this.UserModel.findById = (id, fields, callback) => {
  735. callback(null, this.users[id])
  736. }
  737. this.LimitationsManager.hasPaidSubscription.callsArgWith(1, null, false)
  738. this.TagsHandler.getAllTags.callsArgWith(1, null, this.tags)
  739. this.NotificationsHandler.getUserNotifications = sinon
  740. .stub()
  741. .callsArgWith(1, null, this.notifications, {})
  742. this.ProjectGetter.findAllUsersProjects.callsArgWith(
  743. 2,
  744. null,
  745. this.allProjects
  746. )
  747. this.Modules.hooks.fire
  748. .withArgs('findAllV1Projects', this.user._id)
  749. .yields(undefined)
  750. }) // Without integration module hook, cb returns undefined
  751. it('should render the project/list page', function(done) {
  752. this.res.render = (pageName, opts) => {
  753. pageName.should.equal('project/list')
  754. done()
  755. }
  756. this.ProjectController.projectListPage(this.req, this.res)
  757. })
  758. it('should omit one of the projects', function(done) {
  759. this.res.render = (pageName, opts) => {
  760. opts.projects.length.should.equal(
  761. this.projects.length +
  762. this.collabertions.length +
  763. this.readOnly.length +
  764. this.tokenReadAndWrite.length +
  765. this.tokenReadOnly.length -
  766. 1
  767. )
  768. done()
  769. }
  770. this.ProjectController.projectListPage(this.req, this.res)
  771. })
  772. })
  773. describe('renameProject', function() {
  774. beforeEach(function() {
  775. this.newProjectName = 'my supper great new project'
  776. this.req.body.newProjectName = this.newProjectName
  777. })
  778. it('should call the editor controller', function(done) {
  779. this.EditorController.renameProject.callsArgWith(2)
  780. this.res.sendStatus = code => {
  781. code.should.equal(200)
  782. this.EditorController.renameProject
  783. .calledWith(this.project_id, this.newProjectName)
  784. .should.equal(true)
  785. done()
  786. }
  787. this.ProjectController.renameProject(this.req, this.res)
  788. })
  789. it('should send an error to next() if there is a problem', function(done) {
  790. let error
  791. this.EditorController.renameProject.callsArgWith(
  792. 2,
  793. (error = new Error('problem'))
  794. )
  795. const next = e => {
  796. e.should.equal(error)
  797. done()
  798. }
  799. this.ProjectController.renameProject(this.req, this.res, next)
  800. })
  801. })
  802. describe('loadEditor', function() {
  803. beforeEach(function() {
  804. this.settings.editorIsOpen = true
  805. this.project = {
  806. name: 'my proj',
  807. _id: '213123kjlkj',
  808. owner_ref: '59fc84d5fbea77482d436e1b'
  809. }
  810. this.brandedProject = {
  811. name: 'my branded proj',
  812. _id: '3252332',
  813. owner_ref: '59fc84d5fbea77482d436e1b',
  814. brandVariationId: '12'
  815. }
  816. this.user = {
  817. _id: '588f3ddae8ebc1bac07c9fa4',
  818. ace: {
  819. fontSize: 'massive',
  820. theme: 'sexy'
  821. },
  822. email: 'bob@bob.com'
  823. }
  824. this.ProjectGetter.getProject.callsArgWith(2, null, this.project)
  825. this.UserModel.findById.callsArgWith(1, null, this.user)
  826. this.SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {})
  827. this.AuthorizationManager.getPrivilegeLevelForProject.callsArgWith(
  828. 3,
  829. null,
  830. 'owner'
  831. )
  832. this.ProjectDeleter.unmarkAsDeletedByExternalSource = sinon.stub()
  833. this.InactiveProjectManager.reactivateProjectIfRequired.callsArgWith(1)
  834. this.AnalyticsManager.getLastOccurrence.yields(null, { mock: 'event' })
  835. this.ProjectUpdateHandler.markAsOpened.callsArgWith(1)
  836. })
  837. it('should render the project/editor page', function(done) {
  838. this.res.render = (pageName, opts) => {
  839. pageName.should.equal('project/editor')
  840. done()
  841. }
  842. this.ProjectController.loadEditor(this.req, this.res)
  843. })
  844. it('should add user', function(done) {
  845. this.res.render = (pageName, opts) => {
  846. opts.user.email.should.equal(this.user.email)
  847. done()
  848. }
  849. this.ProjectController.loadEditor(this.req, this.res)
  850. })
  851. it('should add on userSettings', function(done) {
  852. this.res.render = (pageName, opts) => {
  853. opts.userSettings.fontSize.should.equal(this.user.ace.fontSize)
  854. opts.userSettings.editorTheme.should.equal(this.user.ace.theme)
  855. done()
  856. }
  857. this.ProjectController.loadEditor(this.req, this.res)
  858. })
  859. it('should add isRestrictedTokenMember', function(done) {
  860. this.res.render = (pageName, opts) => {
  861. opts.isRestrictedTokenMember.should.exist
  862. opts.isRestrictedTokenMember.should.equal(false)
  863. return done()
  864. }
  865. return this.ProjectController.loadEditor(this.req, this.res)
  866. })
  867. it('should set isRestrictedTokenMember when appropriate', function(done) {
  868. this.AuthorizationManager.isRestrictedUser.returns(true)
  869. this.res.render = (pageName, opts) => {
  870. opts.isRestrictedTokenMember.should.exist
  871. opts.isRestrictedTokenMember.should.equal(true)
  872. return done()
  873. }
  874. return this.ProjectController.loadEditor(this.req, this.res)
  875. })
  876. it('should render the closed page if the editor is closed', function(done) {
  877. this.settings.editorIsOpen = false
  878. this.res.render = (pageName, opts) => {
  879. pageName.should.equal('general/closed')
  880. done()
  881. }
  882. this.ProjectController.loadEditor(this.req, this.res)
  883. })
  884. it('should not render the page if the project can not be accessed', function(done) {
  885. this.AuthorizationManager.getPrivilegeLevelForProject = sinon
  886. .stub()
  887. .callsArgWith(3, null, null)
  888. this.res.sendStatus = (resCode, opts) => {
  889. resCode.should.equal(401)
  890. done()
  891. }
  892. this.ProjectController.loadEditor(this.req, this.res)
  893. })
  894. it('should reactivateProjectIfRequired', function(done) {
  895. this.res.render = (pageName, opts) => {
  896. this.InactiveProjectManager.reactivateProjectIfRequired
  897. .calledWith(this.project_id)
  898. .should.equal(true)
  899. done()
  900. }
  901. this.ProjectController.loadEditor(this.req, this.res)
  902. })
  903. it('should mark project as opened', function(done) {
  904. this.res.render = (pageName, opts) => {
  905. this.ProjectUpdateHandler.markAsOpened
  906. .calledWith(this.project_id)
  907. .should.equal(true)
  908. done()
  909. }
  910. this.ProjectController.loadEditor(this.req, this.res)
  911. })
  912. it('should call the brand variations handler for branded projects', function(done) {
  913. this.ProjectGetter.getProject.callsArgWith(2, null, this.brandedProject)
  914. this.res.render = (pageName, opts) => {
  915. this.BrandVariationsHandler.getBrandVariationById
  916. .calledWith()
  917. .should.equal(true)
  918. done()
  919. }
  920. this.ProjectController.loadEditor(this.req, this.res)
  921. })
  922. it('should not call the brand variations handler for unbranded projects', function(done) {
  923. this.res.render = (pageName, opts) => {
  924. this.BrandVariationsHandler.getBrandVariationById.called.should.equal(
  925. false
  926. )
  927. done()
  928. }
  929. this.ProjectController.loadEditor(this.req, this.res)
  930. })
  931. it('should expose the brand variation details as locals for branded projects', function(done) {
  932. this.ProjectGetter.getProject.callsArgWith(2, null, this.brandedProject)
  933. this.res.render = (pageName, opts) => {
  934. opts.brandVariation.should.deep.equal(this.brandVariationDetails)
  935. done()
  936. }
  937. this.ProjectController.loadEditor(this.req, this.res)
  938. })
  939. })
  940. describe('userProjectsJson', function() {
  941. beforeEach(function(done) {
  942. const projects = [
  943. {
  944. archived: true,
  945. trashed: true,
  946. id: 'a',
  947. name: 'A',
  948. accessLevel: 'a',
  949. somethingElse: 1
  950. },
  951. {
  952. archived: false,
  953. id: 'b',
  954. name: 'B',
  955. accessLevel: 'b',
  956. somethingElse: 1
  957. },
  958. {
  959. archived: false,
  960. trashed: true,
  961. id: 'c',
  962. name: 'C',
  963. accessLevel: 'c',
  964. somethingElse: 1
  965. },
  966. {
  967. archived: false,
  968. trashed: false,
  969. id: 'd',
  970. name: 'D',
  971. accessLevel: 'd',
  972. somethingElse: 1
  973. }
  974. ]
  975. this.ProjectHelper.isArchivedOrTrashed
  976. .withArgs(projects[0], this.user._id)
  977. .returns(true)
  978. this.ProjectHelper.isArchivedOrTrashed
  979. .withArgs(projects[1], this.user._id)
  980. .returns(false)
  981. this.ProjectHelper.isArchivedOrTrashed
  982. .withArgs(projects[2], this.user._id)
  983. .returns(true)
  984. this.ProjectHelper.isArchivedOrTrashed
  985. .withArgs(projects[3], this.user._id)
  986. .returns(false)
  987. this.ProjectGetter.findAllUsersProjects = sinon
  988. .stub()
  989. .callsArgWith(2, null, [])
  990. this.ProjectController._buildProjectList = sinon.stub().returns(projects)
  991. this.AuthenticationController.getLoggedInUserId = sinon
  992. .stub()
  993. .returns(this.user._id)
  994. done()
  995. })
  996. it('should produce a list of projects', function(done) {
  997. this.res.json = data => {
  998. expect(data).to.deep.equal({
  999. projects: [
  1000. { _id: 'b', name: 'B', accessLevel: 'b' },
  1001. { _id: 'd', name: 'D', accessLevel: 'd' }
  1002. ]
  1003. })
  1004. done()
  1005. }
  1006. this.ProjectController.userProjectsJson(this.req, this.res, this.next)
  1007. })
  1008. })
  1009. describe('projectEntitiesJson', function() {
  1010. beforeEach(function() {
  1011. this.AuthenticationController.getLoggedInUserId = sinon
  1012. .stub()
  1013. .returns('abc')
  1014. this.req.params = { Project_id: 'abcd' }
  1015. this.project = { _id: 'abcd' }
  1016. this.docs = [
  1017. { path: '/things/b.txt', doc: true },
  1018. { path: '/main.tex', doc: true }
  1019. ]
  1020. this.files = [{ path: '/things/a.txt' }]
  1021. this.ProjectGetter.getProject = sinon
  1022. .stub()
  1023. .callsArgWith(1, null, this.project)
  1024. this.ProjectEntityHandler.getAllEntitiesFromProject = sinon
  1025. .stub()
  1026. .callsArgWith(1, null, this.docs, this.files)
  1027. })
  1028. it('should produce a list of entities', function(done) {
  1029. this.res.json = data => {
  1030. expect(data).to.deep.equal({
  1031. project_id: 'abcd',
  1032. entities: [
  1033. { path: '/main.tex', type: 'doc' },
  1034. { path: '/things/a.txt', type: 'file' },
  1035. { path: '/things/b.txt', type: 'doc' }
  1036. ]
  1037. })
  1038. expect(this.ProjectGetter.getProject.callCount).to.equal(1)
  1039. expect(
  1040. this.ProjectEntityHandler.getAllEntitiesFromProject.callCount
  1041. ).to.equal(1)
  1042. done()
  1043. }
  1044. this.ProjectController.projectEntitiesJson(this.req, this.res, this.next)
  1045. })
  1046. })
  1047. describe('_buildProjectViewModel', function() {
  1048. beforeEach(function() {
  1049. this.ProjectHelper.isArchived.returns(false)
  1050. this.project = {
  1051. _id: 'abcd',
  1052. name: 'netsenits',
  1053. lastUpdated: 1,
  1054. lastUpdatedBy: 2,
  1055. publicAccesLevel: 'private',
  1056. archived: false,
  1057. owner_ref: 'defg',
  1058. tokens: {
  1059. readAndWrite: '1abcd',
  1060. readAndWritePrefix: '1',
  1061. readOnly: 'neiotsranteoia'
  1062. }
  1063. }
  1064. })
  1065. it('should produce a model of the project', function() {
  1066. const result = this.ProjectController._buildProjectViewModel(
  1067. this.project,
  1068. 'readAndWrite',
  1069. 'owner',
  1070. this.user._id
  1071. )
  1072. expect(result).to.exist
  1073. expect(result).to.be.object
  1074. expect(result).to.deep.equal({
  1075. id: 'abcd',
  1076. name: 'netsenits',
  1077. lastUpdated: 1,
  1078. lastUpdatedBy: 2,
  1079. publicAccessLevel: 'private',
  1080. accessLevel: 'readAndWrite',
  1081. source: 'owner',
  1082. archived: false,
  1083. owner_ref: 'defg',
  1084. tokens: {
  1085. readAndWrite: '1abcd',
  1086. readAndWritePrefix: '1',
  1087. readOnly: 'neiotsranteoia'
  1088. },
  1089. isV1Project: false
  1090. })
  1091. })
  1092. describe('when token-read-only access', function() {
  1093. it('should redact the owner and last-updated data', function() {
  1094. const result = this.ProjectController._buildProjectViewModel(
  1095. this.project,
  1096. 'readOnly',
  1097. 'token',
  1098. this.user._id
  1099. )
  1100. expect(result).to.exist
  1101. expect(result).to.be.object
  1102. expect(result).to.deep.equal({
  1103. id: 'abcd',
  1104. name: 'netsenits',
  1105. lastUpdated: 1,
  1106. lastUpdatedBy: null,
  1107. publicAccessLevel: 'private',
  1108. accessLevel: 'readOnly',
  1109. source: 'token',
  1110. archived: false,
  1111. owner_ref: null,
  1112. tokens: {
  1113. readAndWrite: '1abcd',
  1114. readAndWritePrefix: '1',
  1115. readOnly: 'neiotsranteoia'
  1116. },
  1117. isV1Project: false
  1118. })
  1119. })
  1120. })
  1121. })
  1122. describe('_isInPercentageRollout', function() {
  1123. before(function() {
  1124. this.ids = [
  1125. '5a05cd7621f9fe22be131740',
  1126. '5a05cd7821f9fe22be131741',
  1127. '5a05cd7921f9fe22be131742',
  1128. '5a05cd7a21f9fe22be131743',
  1129. '5a05cd7b21f9fe22be131744',
  1130. '5a05cd7c21f9fe22be131745',
  1131. '5a05cd7d21f9fe22be131746',
  1132. '5a05cd7e21f9fe22be131747',
  1133. '5a05cd7f21f9fe22be131748',
  1134. '5a05cd8021f9fe22be131749',
  1135. '5a05cd8021f9fe22be13174a',
  1136. '5a05cd8121f9fe22be13174b',
  1137. '5a05cd8221f9fe22be13174c',
  1138. '5a05cd8221f9fe22be13174d',
  1139. '5a05cd8321f9fe22be13174e',
  1140. '5a05cd8321f9fe22be13174f',
  1141. '5a05cd8421f9fe22be131750',
  1142. '5a05cd8421f9fe22be131751',
  1143. '5a05cd8421f9fe22be131752',
  1144. '5a05cd8521f9fe22be131753'
  1145. ]
  1146. })
  1147. it('should produce the expected results', function() {
  1148. expect(
  1149. this.ids.map(i =>
  1150. this.ProjectController._isInPercentageRollout('abcd', i, 50)
  1151. )
  1152. ).to.deep.equal([
  1153. false,
  1154. false,
  1155. false,
  1156. false,
  1157. false,
  1158. false,
  1159. true,
  1160. false,
  1161. true,
  1162. true,
  1163. true,
  1164. true,
  1165. true,
  1166. true,
  1167. false,
  1168. false,
  1169. false,
  1170. true,
  1171. false,
  1172. true
  1173. ])
  1174. expect(
  1175. this.ids.map(i =>
  1176. this.ProjectController._isInPercentageRollout('efgh', i, 50)
  1177. )
  1178. ).to.deep.equal([
  1179. false,
  1180. false,
  1181. false,
  1182. false,
  1183. true,
  1184. false,
  1185. false,
  1186. true,
  1187. false,
  1188. false,
  1189. true,
  1190. true,
  1191. true,
  1192. false,
  1193. true,
  1194. false,
  1195. true,
  1196. true,
  1197. false,
  1198. false
  1199. ])
  1200. })
  1201. })
  1202. describe('transferOwnership', function() {
  1203. beforeEach(function() {
  1204. this.req.body = { user_id: this.user._id.toString() }
  1205. })
  1206. it('validates the request body', function(done) {
  1207. this.req.body = {}
  1208. this.ProjectController.transferOwnership(this.req, this.res, err => {
  1209. expect(err).to.be.instanceof(HttpErrors.BadRequestError)
  1210. done()
  1211. })
  1212. })
  1213. it('returns 204 on success', function(done) {
  1214. this.res.sendStatus = status => {
  1215. expect(status).to.equal(204)
  1216. done()
  1217. }
  1218. this.ProjectController.transferOwnership(this.req, this.res)
  1219. })
  1220. it('returns 404 if the project does not exist', function(done) {
  1221. this.ProjectDetailsHandler.transferOwnership.yields(
  1222. new Errors.ProjectNotFoundError()
  1223. )
  1224. this.ProjectController.transferOwnership(this.req, this.res, err => {
  1225. expect(err).to.be.instanceof(HttpErrors.NotFoundError)
  1226. done()
  1227. })
  1228. })
  1229. it('returns 404 if the user does not exist', function(done) {
  1230. this.ProjectDetailsHandler.transferOwnership.yields(
  1231. new Errors.UserNotFoundError()
  1232. )
  1233. this.ProjectController.transferOwnership(this.req, this.res, err => {
  1234. expect(err).to.be.instanceof(HttpErrors.NotFoundError)
  1235. done()
  1236. })
  1237. })
  1238. })
  1239. })