codecombat/test/server/models/CampaignStatus.spec.coffee
2014-01-03 10:32:13 -08:00

34 lines
994 B
CoffeeScript

require '../common'
describe 'CampaignStatus', ->
user = new User(name:'sup')
campaign = new Campaign(name:'Project Vengeance.', permissions: simplePermissions)
stat = new CampaignStatus(user: user._id, campaign: campaign._id)
it 'clears things first', (done) ->
clearModels [User, Campaign, CampaignStatus], (err) ->
expect(err).toBeNull()
done()
it 'can be saved', (done) ->
saveModels [user, campaign, stat], (err) ->
expect(err).toBeNull()
done()
it 'can populate', (done) ->
CampaignStatus
.findOne({_id:stat._id})
.populate('user')
.populate('campaign')
.exec (err, c) ->
expect(err).toBe(null)
expect(c.user.get('name')).not.toBeUndefined()
expect(c.campaign.get('name')).not.toBeUndefined()
done()
it 'rejects duplicates', (done) ->
stat2 = new CampaignStatus(user: user._id, campaign: campaign._id)
stat2.save (err) ->
expect(err).not.toBe(null)
done()