base-domain
Version:
simple module to help build Domain-Driven Design
92 lines (63 loc) • 3.31 kB
text/coffeescript
facade = require('../create-facade').create()
Facade = facade.constructor
PropInfo = require '../../src/lib/prop-info'
describe 'PropInfo', ->
before ->
class A extends Facade.Entity
:
str : .STRING
num : .NUMBER
date : .DATE
createdAt : .CREATED_AT
createdAt2 : .CREATED_AT
updatedAt : .UPDATED_AT
updatedAt2 : .UPDATED_AT
b : .MODEL 'b'
c : .MODEL 'c'
bs : .MODEL_LIST 'b'
cs : .MODEL_LIST 'c'
facade.addClass('a', A)
facade.addClass('b', class B extends Facade.Entity)
facade.addClass('c', class C extends Facade.BaseModel)
= facade.getModel('a').properties
= facade
= new PropInfo(A.properties, facade)
it 'has dateProps collecting prop of DATE, CREATED_AT and UPDATED_AT', ->
expect(.dateProps).to.eql ['date', 'createdAt', 'createdAt2', 'updatedAt', 'updatedAt2']
it 'has createdAt whose value is CREATED_AT at last column', ->
expect(.createdAt).to.equal 'createdAt2'
it 'has updatedAt whose value is UPDATED_AT at last column', ->
expect(.updatedAt).to.equal 'updatedAt2'
it 'has modelProps collecting MODELs (BaseModels and Entities)', ->
expect(.modelProps).to.eql ['b', 'c']
it 'has listProps collecting MODEL_LISTs', ->
expect(.listProps).to.eql ['bs', 'cs']
it 'has entityProps collecting MODELs who extend Entity', ->
expect(.entityProps).to.eql ['b']
it 'has nonEntityProps collecting MODELs who don\'t extend Entity', ->
expect(.nonEntityProps).to.eql ['c']
it 'has dic collecting all properties', ->
expect(Object.keys .dic).to.eql Object.keys
it 'has entityDic collecting all entities', ->
expect(Object.keys .entityDic).to.eql ['b']
it 'has modelDic collecting all models', ->
expect(Object.keys .modelDic).to.eql ['b', 'c']
describe 'isEntityProp', ->
it 'returns whether the prop is entity', ->
expect(.isEntityProp('b')).to.be.true
expect(.isEntityProp('c')).to.be.false
expect(.isEntityProp('date')).to.be.false
expect(.isEntityProp('xxx')).to.be.false
describe 'isModelProp', ->
it 'returns whether the prop is model', ->
expect(.isModelProp('b')).to.be.true
expect(.isModelProp('c')).to.be.true
expect(.isModelProp('date')).to.be.false
expect(.isModelProp('xxx')).to.be.false
describe 'getTypeInfo', ->
it 'returns typeInfo of the prop', ->
expect(.getTypeInfo('b')).to.exist
expect(.getTypeInfo('c')).to.exist
expect(.getTypeInfo('cs')).to.exist
expect(.getTypeInfo('num')).to.exist
expect(.getTypeInfo('xxxx')).not.to.exist