1234567891011121314151617181920212223242526272829303132333435 |
- /**
- * sql执行数据模型单元测试
- *
- * @author CaiAoLin
- * @date 2017/10/23
- * @version
- */
- 'use strict';
- const { app, assert } = require('egg-mock/bootstrap');
- describe('test/app/service/sql_execute.test.js', () => {
- it('select test', function* () {
- // 创建 ctx
- const ctx = app.mockContext();
- const sql = 'select * from zh_manager';
- const [filedList, result] = yield ctx.service.sqlExecute.execute(sql);
- assert(result.length > 0 && filedList.length > 0);
- });
- it('other operate test', function* () {
- // 创建 ctx
- const ctx = app.mockContext();
- const sql = 'UPDATE zh_manager SET token = 111 WHERE id = 10;';
- let message = '';
- try {
- yield ctx.service.sqlExecute.execute(sql);
- } catch (error) {
- message = error.toString();
- }
- assert(message === '只能执行select相关代码');
- });
- });
|