/** * 标准清单 -- 项目节 模型 单元测试 * * @author Mai * @date 2018/3/15 * @version */ 'use strict'; const { app, assert } = require('egg-mock/bootstrap'); describe('test/app/service/std_chapter.test.js', () => { // 测试R类方法 it('test getData', function* () { const ctx = app.mockContext(); // 查询前2层节点 const result1 = yield ctx.service.stdChapter.getData(1); assert(result1.length === 32); // 查询前1层节点 const result2 = yield ctx.service.stdChapter.getData(1, 1); assert(result2.length === 6); }); it('test getDataByDataId', function* () { const ctx = app.mockContext(); // 查询节点1-10-2 const node = yield ctx.service.stdChapter.getDataByDataId(1, 47); assert(node); assert(node.code === '1-10-2'); assert(node.full_path === '1.210.47'); assert(node.source === ctx.service.stdChapter.stdType + '-' + node.list_id + '-' + node.chapter_id); }); it('test getDataByFullPath', function* () { const ctx = app.mockContext(); // 查询节点1-10-1及其子节点 const result = yield ctx.service.stdChapter.getDataByFullPath(1, '1.210.3002%'); assert(result.length === 9); // 查询1-10-1的子孙节点 const result1 = yield ctx.service.stdChapter.getDataByFullPath(1, '1.210.3002.%'); assert(result1.length === 8); }); it('test getFullLevelDataByFullPath', function* () { const ctx = app.mockContext(); // 查询1-10-1及其全部父节点 const result1 = yield ctx.service.stdChapter.getFullLevelDataByFullPath(1, '1.210.3002'); assert(result1.length === 3); // 查询1-10-2/1-10-3及其全部父节点 const result2 = yield ctx.service.stdChapter.getFullLevelDataByFullPath(1, ['1.210.47', '1.210.48']); assert(result2.length === 4); }); });