mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-21 04:52:47 -05:00
43 lines
1.4 KiB
CoffeeScript
43 lines
1.4 KiB
CoffeeScript
|
require '../common'
|
||
|
|
||
|
describe '/db/campaign', ->
|
||
|
request = require 'request'
|
||
|
it 'clears the db first', (done) ->
|
||
|
clearModels [User, Campaign], (err) ->
|
||
|
throw err if err
|
||
|
done()
|
||
|
|
||
|
campaign = {name: 'A', description:'B'}
|
||
|
url = getURL('/db/campaign')
|
||
|
campaigns = {}
|
||
|
|
||
|
it 'allows making Campaigns.', (done) ->
|
||
|
loginJoe (user) ->
|
||
|
campaign.permissions = [access: 'owner', target: user._id]
|
||
|
request.post {uri:url, json:campaign}, (err, res, body) ->
|
||
|
expect(res.statusCode).toBe(200)
|
||
|
expect(body.permissions).not.toBeUndefined()
|
||
|
campaigns[0] = body
|
||
|
done()
|
||
|
|
||
|
it 'does not allow other users access', (done) ->
|
||
|
loginSam (user) ->
|
||
|
request.get {uri:url+'/'+campaigns[0]._id}, (err, res, body) ->
|
||
|
expect(res.statusCode).toBe(403)
|
||
|
done()
|
||
|
|
||
|
it 'allows editing permissions.', (done) ->
|
||
|
loginJoe (user) ->
|
||
|
campaigns[0].permissions.push(access: 'read', target: 'public')
|
||
|
request.put {uri:url, json:campaigns[0]}, (err, res, body) ->
|
||
|
expect(res.statusCode).toBe(200)
|
||
|
expect(body.permissions.length).toBe(2)
|
||
|
campaigns[0] = body
|
||
|
done()
|
||
|
|
||
|
it 'allows anyone to access it through public permissions', (done) ->
|
||
|
loginSam (user) ->
|
||
|
request.get {uri:url+'/'+campaigns[0]._id}, (err, res, body) ->
|
||
|
expect(res.statusCode).toBe(200)
|
||
|
done()
|