Added jasmine spec reporter and tests for anonymous name collisions.

This commit is contained in:
Aditya Raisinghani 2014-04-28 15:16:43 +05:30
parent 834c27bbd7
commit 0cd5d0f4af
3 changed files with 53 additions and 3 deletions

View file

@ -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,

View file

@ -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())

View file

@ -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', ->