From ea4523bf6a0c560ff7b013d4262fa03c9a00f27b Mon Sep 17 00:00:00 2001 From: Ruben Vereecken Date: Wed, 9 Jul 2014 21:29:57 +0200 Subject: [PATCH] Test coverage for GETting users by slug --- test/server/functional/user.spec.coffee | 70 ++++++++++++++++++------- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/test/server/functional/user.spec.coffee b/test/server/functional/user.spec.coffee index 5395566a4..8f1bedbcd 100644 --- a/test/server/functional/user.spec.coffee +++ b/test/server/functional/user.spec.coffee @@ -44,20 +44,6 @@ 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 @@ -105,11 +91,32 @@ describe 'POST /db/user', -> done() it 'should allow setting anonymous user name', (done) -> - createAnonNameUser(done) - - it 'should allow multiple anonymous users with same name', (done) -> - 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 'should not allow multiple anonymous users with same name anymore', (done) -> + request.post getURL('/auth/logout'), -> + request.get getURL('/auth/whoami'), -> + req = request.post(getURL('/db/user'), (err, response) -> + expect(response.statusCode).toBe(409) + request.get getURL('/auth/whoami'), (request, response, body) -> + res = JSON.parse(response.body) + expect(res.anonymous).toBeTruthy() + expect(res.name).not.toEqual('Jim') + done() + ) + form = req.form() + form.append('name', 'Jim') it 'should not allow setting existing user name to anonymous user', (done) -> @@ -267,3 +274,30 @@ describe 'GET /db/user', -> expect(response.statusCode).toBe(422) done() ) + + it 'can fetch myself by id completely', (done) -> + loginSam (sam) -> + request.get {url: getURL(urlUser + '/' + sam.id)}, (err, response) -> + expect(err).toBeNull() + expect(response.statusCode).toBe(200) + done() + + # TODO Ruben should be able to fetch other users but probably with restricted data access + # Add to the test case above an extra data check + + it 'can fetch myself by slug completely', (done) -> + loginSam (sam) -> + request.get {url: getURL(urlUser + '/sam')}, (err, response) -> + expect(err).toBeNull() + expect(response.statusCode).toBe(200) + guy = JSON.parse response.body + expect(guy._id).toBe sam.get('_id').toHexString() + expect(guy.name).toBe sam.get 'name' + done() + + + + + + +