Bläddra i källkod

标准清单,添加单元测试

MaiXinRong 6 år sedan
förälder
incheckning
220d00f68a

+ 1 - 1
app/service/standard_lib.js

@@ -1,6 +1,6 @@
 'use strict';
 'use strict';
 /**
 /**
- * 标准库基类
+ * 标准库基类(请勿使用该类创造示例)
  *
  *
  * @author Mai
  * @author Mai
  * @date 2018/3/13
  * @date 2018/3/13

+ 73 - 0
test/app/service/std_bills.test.js

@@ -0,0 +1,73 @@
+'use strict';
+
+/**
+ * 标准清单 -- 工程量清单 模型 单元测试
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+'use strict';
+
+const { app, assert } = require('egg-mock/bootstrap');
+
+describe('test/app/service/std_bills.test.js', () => {
+    // 测试R类方法
+    it('test getData', function* () {
+        const ctx = app.mockContext();
+
+        // 查询前2层节点
+        const result1 = yield ctx.service.stdBills.getData(1);
+        assert(result1.length === 10);
+        // 查询前1层节点
+        const result2 = yield ctx.service.stdBills.getData(1, 1);
+        assert(result2.length === 1);
+    });
+    it('test getDataByDataId', function* () {
+        const ctx = app.mockContext();
+
+        // 查询节点101-1
+        const node = yield ctx.service.stdBills.getDataByDataId(1, 296);
+        assert(node);
+        assert(node.b_code === '101-1');
+        assert(node.full_path === '1.294.295.296');
+        assert(node.source === ctx.service.stdBills.stdType + '-' + node.list_id + '-' + node.bill_id);
+    });
+    it('test getDataByFullPath', function* () {
+        const ctx = app.mockContext();
+
+        // 查询节点102
+        const node = yield ctx.service.stdBills.getDataByCondition({
+            list_id: 1,
+            code: '102',
+        });
+        // 查询102及其子节点
+        const result = yield ctx.service.stdBills.getDataByFullPath(1, node.full_path + '%');
+        assert(result.length === 6);
+
+        // 查询1-10-1的子孙节点
+        const result1 = yield ctx.service.stdBills.getDataByFullPath(1, node.full_path + '.%');
+        assert(result1.length === 5);
+    });
+    it('test getFullLevelDataByFullPath', function* () {
+        const ctx = app.mockContext();
+
+        // 查询节点102-1
+        const node1 = yield ctx.service.stdBills.getDataByCondition({
+            list_id: 1,
+            code: '102-1',
+        });
+        // 查询102-1及其全部父节点
+        const result1 = yield ctx.service.stdBills.getFullLevelDataByFullPath(1, node1.full_path);
+        assert(result1.length === 4);
+
+        // 查询102-1/102-2及其全部父节点
+        const node2 = yield ctx.service.stdBills.getDataByCondition({
+            list_id: 1,
+            code: '102-2',
+        });
+        const result2 = yield ctx.service.stdBills.getFullLevelDataByFullPath(1, [node1.full_path, node2.full_path]);
+        assert(result2.length === 5);
+    });
+});

+ 2 - 2
test/app/service/std_chapter.test.js

@@ -1,5 +1,5 @@
 /**
 /**
- * 标段--台账 模型 单元测试
+ * 标准清单 -- 项目节 模型 单元测试
  *
  *
  * @author Mai
  * @author Mai
  * @date 2018/3/15
  * @date 2018/3/15
@@ -9,7 +9,7 @@
 
 
 const { app, assert } = require('egg-mock/bootstrap');
 const { app, assert } = require('egg-mock/bootstrap');
 
 
-describe('test/app/service/ledger.test.js', () => {
+describe('test/app/service/std_chapter.test.js', () => {
     // 测试R类方法
     // 测试R类方法
     it('test getData', function* () {
     it('test getData', function* () {
         const ctx = app.mockContext();
         const ctx = app.mockContext();