mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-03-25 23:24:05 +08:00
add some test for component
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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}) ->
|
||||
|
||||
27
core/test/model/component.test.coffee
Normal file
27
core/test/model/component.test.coffee
Normal 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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user