2014-04-09 07:17:50 -04:00
|
|
|
should = require('chai').should()
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
assert = require('assert')
|
|
|
|
path = require('path')
|
|
|
|
sinon = require('sinon')
|
|
|
|
modulePath = path.join __dirname, "../../../../app/js/Features/User/UserPagesController"
|
|
|
|
expect = require("chai").expect
|
|
|
|
|
|
|
|
describe "UserPagesController", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
|
|
|
|
@settings = {}
|
2014-04-09 10:04:47 -04:00
|
|
|
@user =
|
|
|
|
_id:"kwjewkl"
|
|
|
|
features:{}
|
2014-04-09 10:41:19 -04:00
|
|
|
|
2014-04-09 10:04:47 -04:00
|
|
|
@UserLocator =
|
|
|
|
findById: sinon.stub().callsArgWith(1, null, @user)
|
|
|
|
@dropboxStatus = {}
|
|
|
|
@DropboxHandler =
|
|
|
|
getUserRegistrationStatus : sinon.stub().callsArgWith(1, null, @dropboxStatus)
|
2014-04-09 07:17:50 -04:00
|
|
|
@UserPagesController = SandboxedModule.require modulePath, requires:
|
|
|
|
"settings-sharelatex":@settings
|
|
|
|
"logger-sharelatex": log:->
|
2014-04-09 10:04:47 -04:00
|
|
|
"./UserLocator": @UserLocator
|
|
|
|
'../Dropbox/DropboxHandler': @DropboxHandler
|
2014-04-09 07:17:50 -04:00
|
|
|
@req =
|
|
|
|
query:{}
|
2014-04-09 10:04:47 -04:00
|
|
|
session:
|
|
|
|
user:@user
|
2014-04-09 07:17:50 -04:00
|
|
|
@res = {}
|
|
|
|
|
|
|
|
|
|
|
|
describe "registerPage", ->
|
|
|
|
|
|
|
|
it "should render the register page", (done)->
|
|
|
|
@res.render = (page)=>
|
|
|
|
page.should.equal "user/register"
|
|
|
|
done()
|
|
|
|
@UserPagesController.registerPage @req, @res
|
|
|
|
|
|
|
|
it "should set the redirect", (done)->
|
|
|
|
redirect = "/go/here/please"
|
|
|
|
@req.query.redir = redirect
|
|
|
|
@res.render = (page, opts)=>
|
|
|
|
opts.redir.should.equal redirect
|
|
|
|
done()
|
|
|
|
@UserPagesController.registerPage @req, @res
|
|
|
|
|
|
|
|
it "should set sharedProjectData", (done)->
|
|
|
|
@req.query.project_name = "myProject"
|
|
|
|
@req.query.user_first_name = "user_first_name_here"
|
|
|
|
|
|
|
|
@res.render = (page, opts)=>
|
|
|
|
opts.sharedProjectData.project_name.should.equal "myProject"
|
|
|
|
opts.sharedProjectData.user_first_name.should.equal "user_first_name_here"
|
|
|
|
done()
|
|
|
|
@UserPagesController.registerPage @req, @res
|
|
|
|
|
|
|
|
it "should set newTemplateData", (done)->
|
|
|
|
@req.session.templateData =
|
|
|
|
templateName : "templateName"
|
|
|
|
|
|
|
|
@res.render = (page, opts)=>
|
|
|
|
opts.newTemplateData.templateName.should.equal "templateName"
|
|
|
|
done()
|
|
|
|
@UserPagesController.registerPage @req, @res
|
|
|
|
|
|
|
|
it "should not set the newTemplateData if there is nothing in the session", (done)->
|
|
|
|
@res.render = (page, opts)=>
|
|
|
|
assert.equal opts.newTemplateData.templateName, undefined
|
|
|
|
done()
|
|
|
|
@UserPagesController.registerPage @req, @res
|
|
|
|
|
|
|
|
|
2014-04-09 07:22:57 -04:00
|
|
|
describe "loginForm", ->
|
2014-04-09 07:17:50 -04:00
|
|
|
|
2014-04-09 07:22:57 -04:00
|
|
|
it "should render the login page", (done)->
|
|
|
|
@res.render = (page)=>
|
|
|
|
page.should.equal "user/login"
|
|
|
|
done()
|
|
|
|
@UserPagesController.loginPage @req, @res
|
2014-04-09 07:17:50 -04:00
|
|
|
|
2014-04-09 07:22:57 -04:00
|
|
|
it "should set the redirect", (done)->
|
|
|
|
redirect = "/go/here/please"
|
|
|
|
@req.query.redir = redirect
|
|
|
|
@res.render = (page, opts)=>
|
|
|
|
opts.redir.should.equal redirect
|
|
|
|
done()
|
|
|
|
@UserPagesController.loginPage @req, @res
|
2014-04-09 07:26:59 -04:00
|
|
|
|
|
|
|
|
2014-04-09 10:04:47 -04:00
|
|
|
describe "settingsPage", ->
|
2014-04-09 09:43:08 -04:00
|
|
|
|
2014-04-09 10:04:47 -04:00
|
|
|
it "should render user/settings", (done)->
|
|
|
|
@res.render = (page)->
|
|
|
|
page.should.equal "user/settings"
|
|
|
|
done()
|
|
|
|
@UserPagesController.settingsPage @req, @res
|
2014-04-09 09:43:08 -04:00
|
|
|
|
2014-04-09 10:04:47 -04:00
|
|
|
it "should send user", (done)->
|
|
|
|
@res.render = (page, opts)=>
|
|
|
|
opts.user.should.equal @user
|
|
|
|
done()
|
|
|
|
@UserPagesController.settingsPage @req, @res
|