From 23a9aadba5780faf2e7de67955bb355974272caa Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 21 Jul 2016 10:08:22 +0100 Subject: [PATCH] start tests for invite controller --- .../CollaboratorsInviteHandler.coffee | 11 ++++ .../CollaboratorsInviteControllerTests.coffee | 57 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 services/web/test/UnitTests/coffee/Collaborators/CollaboratorsInviteControllerTests.coffee diff --git a/services/web/app/coffee/Features/Collaborators/CollaboratorsInviteHandler.coffee b/services/web/app/coffee/Features/Collaborators/CollaboratorsInviteHandler.coffee index f3d09effd4..f22bcb4c4f 100644 --- a/services/web/app/coffee/Features/Collaborators/CollaboratorsInviteHandler.coffee +++ b/services/web/app/coffee/Features/Collaborators/CollaboratorsInviteHandler.coffee @@ -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)->) -> diff --git a/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsInviteControllerTests.coffee b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsInviteControllerTests.coffee new file mode 100644 index 0000000000..fb9e77f952 --- /dev/null +++ b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsInviteControllerTests.coffee @@ -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'