'use strict';

/**
 * 台账审批流程单元测试
 *
 * @author Mai
 * @date 2018/5/25
 * @version
 */

const { app, assert } = require('egg-mock/bootstrap');
const testTenderId = 3, testProjectId = 17;

describe('test/app/service/ledger_audit.test.js', () => {
    let times = 1;
    // 清理旧测试数据
    it('clear history test data', function* () {
        const ctx = app.mockContext();
        const result = yield ctx.service.ledgerAudit.db.delete(ctx.service.ledgerAudit.tableName, { tender_id: testTenderId });
        assert(result.affectedRows >= 0);
    });
    // 新增审核人
    it('test addAuditor', function* () {
        const ctx = app.mockContext();
        const result = yield ctx.service.ledgerAudit.addAuditor(testTenderId, 11, times);
        assert(result);
    });
    // 查询审核人
    it('test getAuditor', function* () {
        const ctx = app.mockContext();
        const result = yield ctx.service.ledgerAudit.getAuditor(testTenderId, 11, times);
        assert(result);
        assert(result.audit_order === 1);
        assert(result.name === 'olymcai');
    });
    // 获取台账审核人列表
    it('test getAuditors', function* () {
        const ctx = app.mockContext();
        const result = yield ctx.service.ledgerAudit.getAuditors(testTenderId, times);
        assert(result);
        assert(result.length === 1);
        assert(result[0].audit_order === 1);
        assert(result[0].name === 'olymcai');
    });
    // 获取New Order
    it('test getNewOrder', function* () {
        const ctx = app.mockContext();
        const result = yield ctx.service.ledgerAudit.getNewOrder(testTenderId, times);
        assert(result === 2);
    });
});