|
|
@@ -2,18 +2,18 @@ sinon = require('sinon')
|
|
|
chai = require('chai')
|
|
|
should = chai.should()
|
|
|
expect = chai.expect
|
|
|
-modulePath = "../../../../app/js/Features/User/UserController.js"
|
|
|
+modulePath = "../../../../app/js/Features/User/UserInfoController.js"
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
events = require "events"
|
|
|
MockResponse = require "../helpers/MockResponse"
|
|
|
MockRequest = require "../helpers/MockRequest"
|
|
|
ObjectId = require("mongojs").ObjectId
|
|
|
|
|
|
-describe "UserController", ->
|
|
|
+describe "UserInfoController", ->
|
|
|
beforeEach ->
|
|
|
@UserDeleter =
|
|
|
deleteUser: sinon.stub().callsArgWith(1)
|
|
|
- @UserController = SandboxedModule.require modulePath, requires:
|
|
|
+ @UserInfoController = SandboxedModule.require modulePath, requires:
|
|
|
"./UserGetter": @UserGetter = {}
|
|
|
"./UserDeleter": @UserDeleter
|
|
|
|
|
|
@@ -26,11 +26,11 @@ describe "UserController", ->
|
|
|
@user =
|
|
|
_id: ObjectId()
|
|
|
@req.user = @user
|
|
|
- @UserController.sendFormattedPersonalInfo = sinon.stub()
|
|
|
- @UserController.getLoggedInUsersPersonalInfo(@req, @res, @next)
|
|
|
+ @UserInfoController.sendFormattedPersonalInfo = sinon.stub()
|
|
|
+ @UserInfoController.getLoggedInUsersPersonalInfo(@req, @res, @next)
|
|
|
|
|
|
it "should call sendFormattedPersonalInfo", ->
|
|
|
- @UserController.sendFormattedPersonalInfo
|
|
|
+ @UserInfoController.sendFormattedPersonalInfo
|
|
|
.calledWith(@user, @res, @next)
|
|
|
.should.equal true
|
|
|
|
|
|
@@ -44,8 +44,8 @@ describe "UserController", ->
|
|
|
describe "when the user exists", ->
|
|
|
beforeEach ->
|
|
|
@UserGetter.getUser = sinon.stub().callsArgWith(2, null, @user)
|
|
|
- @UserController.sendFormattedPersonalInfo = sinon.stub()
|
|
|
- @UserController.getPersonalInfo(@req, @res, @next)
|
|
|
+ @UserInfoController.sendFormattedPersonalInfo = sinon.stub()
|
|
|
+ @UserInfoController.getPersonalInfo(@req, @res, @next)
|
|
|
|
|
|
it "should look up the user in the database", ->
|
|
|
@UserGetter.getUser
|
|
|
@@ -53,15 +53,15 @@ describe "UserController", ->
|
|
|
.should.equal true
|
|
|
|
|
|
it "should send the formatted details back to the client", ->
|
|
|
- @UserController.sendFormattedPersonalInfo
|
|
|
+ @UserInfoController.sendFormattedPersonalInfo
|
|
|
.calledWith(@user, @res, @next)
|
|
|
.should.equal true
|
|
|
|
|
|
describe "when the user does not exist", ->
|
|
|
beforeEach ->
|
|
|
@UserGetter.getUser = sinon.stub().callsArgWith(2, null, null)
|
|
|
- @UserController.sendFormattedPersonalInfo = sinon.stub()
|
|
|
- @UserController.getPersonalInfo(@req, @res, @next)
|
|
|
+ @UserInfoController.sendFormattedPersonalInfo = sinon.stub()
|
|
|
+ @UserInfoController.getPersonalInfo(@req, @res, @next)
|
|
|
|
|
|
it "should return 404 to the client", ->
|
|
|
@res.statusCode.should.equal 404
|
|
|
@@ -78,11 +78,11 @@ describe "UserController", ->
|
|
|
first_name: @user.first_name
|
|
|
last_name: @user.last_name
|
|
|
email: @user.email
|
|
|
- @UserController._formatPersonalInfo = sinon.stub().callsArgWith(1, null, @formattedInfo)
|
|
|
- @UserController.sendFormattedPersonalInfo @user, @res
|
|
|
+ @UserInfoController._formatPersonalInfo = sinon.stub().callsArgWith(1, null, @formattedInfo)
|
|
|
+ @UserInfoController.sendFormattedPersonalInfo @user, @res
|
|
|
|
|
|
it "should format the user details for the response", ->
|
|
|
- @UserController._formatPersonalInfo
|
|
|
+ @UserInfoController._formatPersonalInfo
|
|
|
.calledWith(@user)
|
|
|
.should.equal true
|
|
|
|
|
|
@@ -98,7 +98,7 @@ describe "UserController", ->
|
|
|
email: "doug@sharelatex.com"
|
|
|
password: "should-not-get-included"
|
|
|
signUpDate: new Date()
|
|
|
- @UserController._formatPersonalInfo @user, (error, info) =>
|
|
|
+ @UserInfoController._formatPersonalInfo @user, (error, info) =>
|
|
|
expect(info).to.deep.equal {
|
|
|
id: @user._id.toString()
|
|
|
first_name: @user.first_name
|
|
|
@@ -118,7 +118,7 @@ describe "UserController", ->
|
|
|
@UserDeleter.deleteUser.calledWith(user_id)
|
|
|
code.should.equal 200
|
|
|
done()
|
|
|
- @UserController.deleteUser @req, @res
|
|
|
+ @UserInfoController.deleteUser @req, @res
|
|
|
|
|
|
|
|
|
|