mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
start tests for invite controller
This commit is contained in:
parent
c3e51dd773
commit
23a9aadba5
2 changed files with 68 additions and 0 deletions
|
@ -1,3 +1,14 @@
|
|||
UserCreator = require('../User/UserCreator')
|
||||
Project = require("../../models/Project").Project
|
||||
mimelib = require("mimelib")
|
||||
logger = require('logger-sharelatex')
|
||||
UserGetter = require "../User/UserGetter"
|
||||
ContactManager = require "../Contacts/ContactManager"
|
||||
CollaboratorsEmailHandler = require "./CollaboratorsEmailHandler"
|
||||
Async = require "async"
|
||||
PrivilegeLevels = require "../Authorization/PrivilegeLevels"
|
||||
Errors = require "../Errors/Errors"
|
||||
|
||||
module.experts = CollaboratorsInviteHandler =
|
||||
|
||||
inviteToProject: (projectId, sendingUserId, email, priveleges, callback=(err,invite)->) ->
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
sinon = require('sinon')
|
||||
chai = require('chai')
|
||||
should = chai.should()
|
||||
expect = chai.expect
|
||||
modulePath = "../../../../app/js/Features/Collaborators/CollaboratorsInviteController.js"
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
events = require "events"
|
||||
MockRequest = require "../helpers/MockRequest"
|
||||
MockResponse = require "../helpers/MockResponse"
|
||||
ObjectId = require("mongojs").ObjectId
|
||||
|
||||
describe "CollaboratorsInviteController", ->
|
||||
beforeEach ->
|
||||
@CollaboratorsInviteController = SandboxedModule.require modulePath, requires:
|
||||
"../Project/ProjectGetter": @ProjectGetter = {}
|
||||
"./CollaboratorsInviteHandler": @CollaboratorsInviteHandler = {}
|
||||
"../Editor/EditorRealTimeController": @EditorRealTimeController = {}
|
||||
'../Subscription/LimitationsManager' : @LimitationsManager = {}
|
||||
'../Project/ProjectEditorHandler' : @ProjectEditorHandler = {}
|
||||
'../User/UserGetter': @UserGetter = {}
|
||||
@res = new MockResponse()
|
||||
@req = new MockRequest()
|
||||
|
||||
@project_id = "project-id-123"
|
||||
@callback = sinon.stub()
|
||||
|
||||
describe "viewInvite", ->
|
||||
|
||||
beforeEach ->
|
||||
@req.params =
|
||||
Project_id: @project_id
|
||||
token: "some-opaque-token"
|
||||
@req.session =
|
||||
user: _id: @current_user_id = "current-user-id"
|
||||
@res.render = sinon.stub()
|
||||
@invite = {
|
||||
_id: ObjectId(),
|
||||
token: "htnseuthaouse",
|
||||
sendingUserId: ObjectId(),
|
||||
projectId: @projectId,
|
||||
targetEmail: 'user@example.com'
|
||||
createdAt: new Date(),
|
||||
expiresAt: new Date()
|
||||
}
|
||||
@CollaboratorsInviteHandler.getInviteByToken = sinon.stub().callsArgWith(2, null, @invite)
|
||||
@callback = sinon.stub()
|
||||
@next = sinon.stub()
|
||||
|
||||
describe 'when the token is valid', ->
|
||||
|
||||
beforeEach ->
|
||||
@CollaboratorsInviteHandler.getInviteByToken.callsArgWith(2, null, @invite)
|
||||
@CollaboratorsInviteController.viewInvite @req, @res, @next
|
||||
|
||||
it 'should render the view template', ->
|
||||
@res.render.callCount.should.equal 1
|
||||
@res.render.firstCall.args[0].should.equal 'project/invite'
|
Loading…
Reference in a new issue