Skip to content

Commit

Permalink
test: make 100% test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
leizongmin committed Dec 5, 2018
1 parent d62b2f9 commit 5416a73
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/test/query1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
*/

import { expect } from "chai";
import Q from "../lib";
import Q, { table } from "../lib";
import * as utils from "./utils";

test("format", function() {
expect(Q.table("test1").format('"a"')).to.equal('"a"');
expect(Q.table("test1").format("a=?", [0])).to.equal("a=0");
expect(Q.table("test1").format("a=:v", { v: 0 })).to.equal("a=0");
});

test("select", function() {
{
const sql = Q.table("test1")
Expand Down Expand Up @@ -239,6 +245,27 @@ test("update", function() {
utils.debug(sql);
expect(sql).to.equal("UPDATE `test1` SET `a`=123, `b`=456");
}
{
const sql = Q.table("test1")
.update("a=?, b=?", [123, 456])
.build();
utils.debug(sql);
expect(sql).to.equal("UPDATE `test1` SET a=123, b=456");
}
{
const sql = Q.table("test1")
.update("a=:a, b=:b", { a: 123, b: 456 })
.build();
utils.debug(sql);
expect(sql).to.equal("UPDATE `test1` SET a=123, b=456");
}
{
const sql = Q.table("test1")
.update("`a`=123, b=456")
.build();
utils.debug(sql);
expect(sql).to.equal("UPDATE `test1` SET `a`=123, b=456");
}
{
const sql = Q.table("test1")
.update({
Expand Down Expand Up @@ -455,6 +482,20 @@ test("options", function() {
utils.debug(sql);
expect(sql).to.equal("SELECT `id`, `name` FROM `test1` GROUP BY `name` ORDER BY `id` DESC LIMIT 1,2");
}
{
const sql = Q.table("test1")
.select()
.options({
skip: 1,
limit: 2,
orderBy: "`id` DESC",
groupBy: "`name`",
fields: ["id", "name"],
})
.build();
utils.debug(sql);
expect(sql).to.equal("SELECT `id`, `name` FROM `test1` GROUP BY `name` ORDER BY `id` DESC LIMIT 1,2");
}
});

test("where(condition): condition for modify operation cannot be empty", function() {
Expand Down Expand Up @@ -564,3 +605,7 @@ test("update(data): support for $incr", function() {
expect(sql).to.equal("UPDATE `test1` SET `a`=`a`+1 WHERE `a`=2");
}
});

test("build()", function() {
expect(() => table("test1").build()).to.throws('invalid query type ""');
});

0 comments on commit 5416a73

Please sign in to comment.