add some test for component

This commit is contained in:
jysperm
2015-06-03 17:24:27 +08:00
parent ef57e227c9
commit 3c13be76ed
4 changed files with 47 additions and 6 deletions

View File

@@ -65,6 +65,8 @@ module.exports = Component = Mabolo.model 'Component',
type: Object
default: -> {}
Account = require './account'
Component.createComponent = (account, {name, type, node, dependencies, options}) ->
@create
account_id: account._id
@@ -152,7 +154,7 @@ Component::populate = ->
@account = _.find accounts, ({_id}) =>
return @account_id.equals _id
@coworkers.each (coworker) ->
@coworkers.forEach (coworker) ->
coworker.account = _.find accounts, ({_id}) ->
return coworker.account_id.equals _id

View File

@@ -1,8 +1,5 @@
describe 'model.account', ->
Account = null
before ->
{Account} = root
Account = require '../../model/account'
describe '.register', ->
it 'should success', ->
@@ -34,7 +31,7 @@ describe 'model.account', ->
Account.search(randomAccount().username).then (account) ->
expect(account).to.not.exists
describe '#createToken', ->
describe '::createToken', ->
it 'should success', ->
createAccount().then (account) ->
account.createToken('full_access').then ({code}) ->

View File

@@ -0,0 +1,27 @@
describe 'model.component', ->
Component = require '../../model/component'
describe '.createComponent', ->
it 'should success', ->
createAccount().then (account) ->
Component.createComponent account,
name: 'linux component'
type: 'linux'
node: 'master'
.then ->
Component.getComponents(account).then (components) ->
_.findWhere(components,
name: 'linux component'
).should.be.exists
describe '::hasMember', ->
it 'should success', ->
createAccount().then (account) ->
createComponent({account}).then (component) ->
component.hasMember(account).should.be.true
describe '::populate', ->
it 'should success', ->
createComponent().then (component) ->
component.populate().then ->
component.account.username.should.be.exists

View File

@@ -33,6 +33,20 @@ randomAccount = ->
createAccount = ->
root.Account.register randomAccount()
createComponent = (options) ->
options = _.defaults {}, options,
name: 'linux component'
type: 'linux'
node: 'master'
Q().then ->
if options.account
return options.account
else
return createAccount()
.then (account) ->
root.Component.createComponent account, options
createLoggedAgent = (options) ->
ready = null
agent = {}
@@ -61,6 +75,7 @@ module.exports = {
randomAccount
createAccount
createComponent
createAgent
createLoggedAgent
}