'use strict';

const Domain = require('cqrs')
,User = require('../core/Actor/User')
,should = require('should')
,domain = new Domain()

domain.register(User);

describe('User', function(){
    let UserId;
    //测试create
    it('#create', done=>{
        domain.create('User',{
            loginName:'hoozi',
            password:'12345'
        }).then((data)=>{
            data.loginName.should.equal('hoozi');
            data.password.should.equal('12345');
            UserId = data.id;
            done();
        })
    });

    //测试是否有UserId
    it('#should have UserId', done=>{
        should.exists(UserId);
        done();
    });

    //测试加分
    it("#User.plus", done=>{
        domain.call(`User.${UserId}.plus`);
        domain.get('User', UserId).then((data)=>{
            data.num.should.equal(1); 
        });
        done();
    })

    //测试减分
    it("#User.minus", done=>{
        domain.call(`User.${UserId}.minus`);
        domain.get('User', UserId).then((data)=>{
            data.num.should.equal(0); 
        });
        done();
    });

    //测试update
    it("#User.update", done=>{
        domain.call(`User.${UserId}.update`,{email:'aaa@111',nickName:'hoozi nick'});
        domain.get('User', UserId).then((data)=>{
            data.email.should.equal('aaa@111'); 
            data.nickName.should.equal('hoozi nick'); 
        });
        domain.call(`User.${UserId}.update`,{email:'aaa@222'});
        domain.call(`User.${UserId}.update`,{nickName:'hoozi nick222'});
        domain.get('User', UserId).then((data)=>{
            data.email.should.equal('aaa@222'); 
            data.nickName.should.equal('hoozi nick222'); 
        });
        done();
    })

    //测试updatePassword
    it("#User.updatePassword", done=>{
        domain.call(`User.${UserId}.updatePassword`,{password:'54321'});
        domain.get('User', UserId).then((data)=>{
            data.password.should.equal('54321'); 
        });
        done();
    })

})

@@ -718,19 +718,32 @@
 d%7D.plus%60
+,%7Bintegral:4%7D
 );%0A
-
         
@@ -793,35 +793,40 @@
            data.
-num
+integral
 .should.equal(1)
@@ -823,17 +823,17 @@
 d.equal(
-1
+4
 ); %0A    
@@ -947,16 +947,29 @@
 %7D.minus%60
+,%7Bintegral:5%7D
 );%0A     
@@ -1034,11 +1034,16 @@
 ata.
-num
+integral
 .sho
@@ -1056,9 +1056,10 @@
 ual(
-0
+-1
 ); %0A

update User unit test