/**
 * sql拼接器单元测试
 *
 * @author CaiAoLin
 * @date 2017/10/20
 * @version
 */

'use strict';

const { app, assert } = require('egg-mock/bootstrap');
const SqlBuilder = require('../../../app/lib/sql_builder');

describe('test/app/lib/sql_builder.test.js', () => {
    it('set normal sql', function* () {
        const sqlBuilder = new SqlBuilder();
        sqlBuilder.columns = ['id'];
        sqlBuilder.limit = 10;
        sqlBuilder.offset = 1;
        sqlBuilder.orderBy = [['id', 'DESC']];

        const [sql, param] = sqlBuilder.build('table');
        const finalSql = app.mysql.format(sql, param);
        // 最后组合后应该获得的数据
        const matchSql = 'SELECT `id` FROM `table` LIMIT 1,10 ORDER BY  `id` DESC';
        assert(finalSql === matchSql);
    });

});
