diff --git a/package.json b/package.json index d4c3fb6c9..10c966fd8 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "mongoose": "3.8.x", "mongoose-text-search": "~0.0.2", "request": "2.12.x", - "tv4": "1.0.x", + "tv4": "~1.0.16", "lodash": "~2.0.0", "underscore.string": "2.3.x", "async": "0.2.x", @@ -92,7 +92,8 @@ "karma-phantomjs-launcher": "~0.1.1", "karma": "~0.10.9", "karma-coverage": "~0.1.4", - "compressible": "~1.0.1" + "compressible": "~1.0.1", + "jasmine-spec-reporter":"~0.3.0" }, "license": "MIT for the code, and CC-BY for the art and music", "private": true, diff --git a/test/server/common.coffee b/test/server/common.coffee index 80aa6e47e..dc01d8389 100644 --- a/test/server/common.coffee +++ b/test/server/common.coffee @@ -3,7 +3,12 @@ console.log 'IT BEGINS' - +require('jasmine-spec-reporter') +jasmine.getEnv().reporter.subReporters_ = [] +jasmine.getEnv().addReporter(new jasmine.SpecReporter({ + displaySuccessfulSpec: true, + displayFailedSpec: true + })) GLOBAL._ = require('lodash') _.str = require('underscore.string') _.mixin(_.str.exports()) diff --git a/test/server/functional/user.spec.coffee b/test/server/functional/user.spec.coffee index 46c98fc24..7ce89886d 100644 --- a/test/server/functional/user.spec.coffee +++ b/test/server/functional/user.spec.coffee @@ -44,6 +44,20 @@ describe 'User.updateMailChimp', -> describe 'POST /db/user', -> + createAnonNameUser = (done)-> + request.post getURL('/auth/logout'), -> + request.get getURL('/auth/whoami'), -> + req = request.post(getURL('/db/user'), (err, response) -> + expect(response.statusCode).toBe(200) + request.get getURL('/auth/whoami'), (request, response, body) -> + res = JSON.parse(response.body) + expect(res.anonymous).toBeTruthy() + expect(res.name).toEqual('Jim') + done() + ) + form = req.form() + form.append('name', 'Jim') + it 'preparing test : clears the db first', (done) -> clearModels [User], (err) -> throw err if err @@ -90,6 +104,36 @@ describe 'POST /db/user', -> expect(user.passwordHash).toBeUndefined() done() + it 'should allow setting anonymous user name', (done) -> + createAnonNameUser(done) + + it 'should allow multiple anonymous users with same name', (done) -> + createAnonNameUser(done) + + + it 'should not allow setting existing user name to anonymous user', (done) -> + + createAnonUser = -> + request.post getURL('/auth/logout'), -> + request.get getURL('/auth/whoami'), -> + req = request.post(getURL('/db/user'), (err, response) -> + expect(response.statusCode).toBe(409) + done() + ) + form = req.form() + form.append('name', 'Jim') + + req = request.post(getURL('/db/user'), (err,response,body) -> + expect(response.statusCode).toBe(200) + request.get getURL('/auth/whoami'), (request, response, body) -> + res = JSON.parse(response.body) + expect(res.anonymous).toBeFalsy() + createAnonUser() + ) + form = req.form() + form.append('email', 'new@user.com') + form.append('password', 'new') + describe 'PUT /db/user', ->