不要怂,就是干,撸起袖子干!

Commit 746c54f6 by Mick Hansen

test(unit/sql): abstract ticks away when they are the only difference between dialect expectations

1 parent 251648a1
...@@ -49,5 +49,8 @@ MssqlDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.support ...@@ -49,5 +49,8 @@ MssqlDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.support
MssqlDialect.prototype.Query = Query; MssqlDialect.prototype.Query = Query;
MssqlDialect.prototype.name = 'mssql'; MssqlDialect.prototype.name = 'mssql';
MssqlDialect.prototype.TICK_CHAR = '"';
MssqlDialect.prototype.TICK_CHAR_LEFT = '[';
MssqlDialect.prototype.TICK_CHAR_RIGHT = ']';
module.exports = MssqlDialect; module.exports = MssqlDialect;
...@@ -30,5 +30,8 @@ MysqlDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.support ...@@ -30,5 +30,8 @@ MysqlDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.support
MysqlDialect.prototype.Query = Query; MysqlDialect.prototype.Query = Query;
MysqlDialect.prototype.QueryGenerator = QueryGenerator; MysqlDialect.prototype.QueryGenerator = QueryGenerator;
MysqlDialect.prototype.name = 'mysql'; MysqlDialect.prototype.name = 'mysql';
MysqlDialect.prototype.TICK_CHAR = '`';
MysqlDialect.prototype.TICK_CHAR_LEFT = MysqlDialect.prototype.TICK_CHAR;
MysqlDialect.prototype.TICK_CHAR_RIGHT = MysqlDialect.prototype.TICK_CHAR;
module.exports = MysqlDialect; module.exports = MysqlDialect;
...@@ -36,5 +36,8 @@ PostgresDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.supp ...@@ -36,5 +36,8 @@ PostgresDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.supp
PostgresDialect.prototype.Query = Query; PostgresDialect.prototype.Query = Query;
PostgresDialect.prototype.name = 'postgres'; PostgresDialect.prototype.name = 'postgres';
PostgresDialect.prototype.TICK_CHAR = '"';
PostgresDialect.prototype.TICK_CHAR_LEFT = PostgresDialect.prototype.TICK_CHAR;
PostgresDialect.prototype.TICK_CHAR_RIGHT = PostgresDialect.prototype.TICK_CHAR;
module.exports = PostgresDialect; module.exports = PostgresDialect;
...@@ -28,5 +28,8 @@ SqliteDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.suppor ...@@ -28,5 +28,8 @@ SqliteDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.suppor
SqliteDialect.prototype.Query = Query; SqliteDialect.prototype.Query = Query;
SqliteDialect.prototype.name = 'sqlite'; SqliteDialect.prototype.name = 'sqlite';
SqliteDialect.prototype.TICK_CHAR = '`';
SqliteDialect.prototype.TICK_CHAR_LEFT = SqliteDialect.prototype.TICK_CHAR;
SqliteDialect.prototype.TICK_CHAR_RIGHT = SqliteDialect.prototype.TICK_CHAR;
module.exports = SqliteDialect; module.exports = SqliteDialect;
...@@ -194,7 +194,13 @@ var Support = { ...@@ -194,7 +194,13 @@ var Support = {
}, },
expectsql: function(query, expectations) { expectsql: function(query, expectations) {
var expectation = expectations[Support.sequelize.dialect.name] || expectations['default']; var expectation = expectations[Support.sequelize.dialect.name];
if (!expectation && Support.sequelize.dialect.name !== 'mssql') {
expectation = expectations['default']
.replace(/\[/g, Support.sequelize.dialect.TICK_CHAR_LEFT)
.replace(/\]/g, Support.sequelize.dialect.TICK_CHAR_RIGHT);
}
expect(query).to.equal(expectation); expect(query).to.equal(expectation);
} }
}; };
......
...@@ -14,7 +14,7 @@ suite('SQL', function() { ...@@ -14,7 +14,7 @@ suite('SQL', function() {
options = undefined; options = undefined;
} }
test(util.inspect(params)+(options && ','+util.inspect(options) || ''), function () { test(util.inspect(params)+(options && ', '+util.inspect(options) || ''), function () {
return expectsql(sql.whereQuery(params, options), expectation); return expectsql(sql.whereQuery(params, options), expectation);
}); });
}; };
...@@ -26,21 +26,15 @@ suite('SQL', function() { ...@@ -26,21 +26,15 @@ suite('SQL', function() {
default: '' default: ''
}); });
testsql({id: 1}, { testsql({id: 1}, {
default: 'WHERE `id` = 1', default: 'WHERE [id] = 1'
postgres: 'WHERE "id" = 1',
mssql: 'WHERE [id] = 1'
}); });
testsql({id: 1}, {prefix: 'User'}, { testsql({id: 1}, {prefix: 'User'}, {
default: 'WHERE `User`.`id` = 1', default: 'WHERE [User].[id] = 1'
postgres: 'WHERE "User"."id" = 1',
mssql: 'WHERE [User].[id] = 1'
}); });
test("{ id: 1 }, { prefix: current.literal(sql.quoteTable.call(current.dialect.QueryGenerator, {schema: 'yolo', tableName: 'User'})) }", function () { test("{ id: 1 }, { prefix: current.literal(sql.quoteTable.call(current.dialect.QueryGenerator, {schema: 'yolo', tableName: 'User'})) }", function () {
expectsql(sql.whereQuery({id: 1}, {prefix: current.literal(sql.quoteTable.call(current.dialect.QueryGenerator, {schema: 'yolo', tableName: 'User'}))}), { expectsql(sql.whereQuery({id: 1}, {prefix: current.literal(sql.quoteTable.call(current.dialect.QueryGenerator, {schema: 'yolo', tableName: 'User'}))}), {
default: 'WHERE `yolo.User`.`id` = 1', default: 'WHERE [yolo.User].[id] = 1'
postgres: 'WHERE "yolo"."User"."id" = 1',
mssql: 'WHERE [yolo].[User].[id] = 1'
}); });
}); });
}); });
...@@ -67,17 +61,13 @@ suite('SQL', function() { ...@@ -67,17 +61,13 @@ suite('SQL', function() {
testsql('equipment', { testsql('equipment', {
$in: [1, 3] $in: [1, 3]
}, { }, {
default: "`equipment` IN (1, 3)", default: '[equipment] IN (1, 3)'
postgres: '"equipment" IN (1, 3)',
mssql: '[equipment] IN (1, 3)'
}); });
testsql('muscles', { testsql('muscles', {
in: [2, 4] in: [2, 4]
}, { }, {
default: "`muscles` IN (2, 4)", default: '[muscles] IN (2, 4)'
postgres: '"muscles" IN (2, 4)',
mssql: '[muscles] IN (2, 4)'
}); });
}); });
...@@ -85,34 +75,26 @@ suite('SQL', function() { ...@@ -85,34 +75,26 @@ suite('SQL', function() {
testsql('deleted', { testsql('deleted', {
$not: true $not: true
}, { }, {
default: "`deleted` NOT true", default: "[deleted] NOT 'true'",
sqlite: "`deleted` NOT 1", sqlite: "`deleted` NOT 1"
postgres: '"deleted" NOT true',
mssql: "[deleted] NOT 'true'"
}); });
testsql('deleted', { testsql('deleted', {
$not: null $not: null
}, { }, {
default: "`deleted` NOT NULL", default: "[deleted] NOT NULL"
postgres: '"deleted" NOT NULL',
mssql: "[deleted] NOT NULL"
}); });
testsql('muscles', { testsql('muscles', {
$not: [2, 4] $not: [2, 4]
}, { }, {
default: "`muscles` NOT IN (2, 4)", default: '[muscles] NOT IN (2, 4)'
postgres: '"muscles" NOT IN (2, 4)',
mssql: '[muscles] NOT IN (2, 4)'
}); });
testsql('muscles', { testsql('muscles', {
$notIn: [2, 4] $notIn: [2, 4]
}, { }, {
default: "`muscles` NOT IN (2, 4)", default: '[muscles] NOT IN (2, 4)'
postgres: '"muscles" NOT IN (2, 4)',
mssql: '[muscles] NOT IN (2, 4)'
}); });
}); });
...@@ -120,27 +102,21 @@ suite('SQL', function() { ...@@ -120,27 +102,21 @@ suite('SQL', function() {
testsql('email', { testsql('email', {
$or: ['maker@mhansen.io', 'janzeh@gmail.com'] $or: ['maker@mhansen.io', 'janzeh@gmail.com']
}, { }, {
default: "(`email` = 'maker@mhansen.io' OR `email` = 'janzeh@gmail.com')", default: '([email] = \'maker@mhansen.io\' OR [email] = \'janzeh@gmail.com\')'
postgres: '("email" = \'maker@mhansen.io\' OR "email" = \'janzeh@gmail.com\')',
mssql: '([email] = \'maker@mhansen.io\' OR [email] = \'janzeh@gmail.com\')'
}); });
testsql('$or', [ testsql('$or', [
{email: 'maker@mhansen.io'}, {email: 'maker@mhansen.io'},
{email: 'janzeh@gmail.com'} {email: 'janzeh@gmail.com'}
], { ], {
default: "(`email` = 'maker@mhansen.io' OR `email` = 'janzeh@gmail.com')", default: '([email] = \'maker@mhansen.io\' OR [email] = \'janzeh@gmail.com\')'
postgres: '("email" = \'maker@mhansen.io\' OR "email" = \'janzeh@gmail.com\')',
mssql: '([email] = \'maker@mhansen.io\' OR [email] = \'janzeh@gmail.com\')'
}); });
testsql('$or', { testsql('$or', {
email: 'maker@mhansen.io', email: 'maker@mhansen.io',
name: 'Mick Hansen' name: 'Mick Hansen'
}, { }, {
default: "(`email` = 'maker@mhansen.io' OR `name` = 'Mick Hansen')", default: '([email] = \'maker@mhansen.io\' OR [name] = \'Mick Hansen\')'
postgres: '("email" = \'maker@mhansen.io\' OR "name" = \'Mick Hansen\')',
mssql: '([email] = \'maker@mhansen.io\' OR [name] = \'Mick Hansen\')'
}); });
testsql('$or', { testsql('$or', {
...@@ -149,16 +125,12 @@ suite('SQL', function() { ...@@ -149,16 +125,12 @@ suite('SQL', function() {
$in: [2, 4] $in: [2, 4]
} }
}, { }, {
default: "(`equipment` IN (1, 3) OR `muscles` IN (2, 4))", default: '([equipment] IN (1, 3) OR [muscles] IN (2, 4))'
postgres: '("equipment" IN (1, 3) OR "muscles" IN (2, 4))',
mssql: '([equipment] IN (1, 3) OR [muscles] IN (2, 4))'
}); });
test("sequelize.or({group_id: 1}, {user_id: 2})", function () { test("sequelize.or({group_id: 1}, {user_id: 2})", function () {
expectsql(sql.whereItemQuery(undefined, this.sequelize.or({group_id: 1}, {user_id: 2})), { expectsql(sql.whereItemQuery(undefined, this.sequelize.or({group_id: 1}, {user_id: 2})), {
default: "(`group_id` = 1 OR `user_id` = 2)", default: "([group_id] = 1 OR [user_id] = 2)"
postgres: '("group_id" = 1 OR "user_id" = 2)',
mssql: "([group_id] = 1 OR [user_id] = 2)"
}); });
}); });
}); });
...@@ -171,16 +143,12 @@ suite('SQL', function() { ...@@ -171,16 +143,12 @@ suite('SQL', function() {
user_id: 2 user_id: 2
} }
}, { }, {
default: "(`shared` = 1 AND (`group_id` = 1 OR `user_id` = 2))", default: "([shared] = 1 AND ([group_id] = 1 OR [user_id] = 2))"
postgres: '("shared" = 1 AND ("group_id" = 1 OR "user_id" = 2))',
mssql: "([shared] = 1 AND ([group_id] = 1 OR [user_id] = 2))"
}); });
test("sequelize.and({shared: 1, sequelize.or({group_id: 1}, {user_id: 2}))", function () { test("sequelize.and({shared: 1, sequelize.or({group_id: 1}, {user_id: 2}))", function () {
expectsql(sql.whereItemQuery(undefined, this.sequelize.and({shared: 1}, this.sequelize.or({group_id: 1}, {user_id: 2}))), { expectsql(sql.whereItemQuery(undefined, this.sequelize.and({shared: 1}, this.sequelize.or({group_id: 1}, {user_id: 2}))), {
default: "(`shared` = 1 AND (`group_id` = 1 OR `user_id` = 2))", default: "([shared] = 1 AND ([group_id] = 1 OR [user_id] = 2))"
postgres: '("shared" = 1 AND ("group_id" = 1 OR "user_id" = 2))',
mssql: "([shared] = 1 AND ([group_id] = 1 OR [user_id] = 2))"
}); });
}); });
}); });
...@@ -189,9 +157,7 @@ suite('SQL', function() { ...@@ -189,9 +157,7 @@ suite('SQL', function() {
testsql('rank', { testsql('rank', {
$gt: 2 $gt: 2
}, { }, {
default: "`rank` > 2", default: "[rank] > 2"
postgres: '"rank" > 2',
mssql: "[rank] > 2"
}); });
}); });
...@@ -199,9 +165,7 @@ suite('SQL', function() { ...@@ -199,9 +165,7 @@ suite('SQL', function() {
testsql('username', { testsql('username', {
$like: '%swagger' $like: '%swagger'
}, { }, {
default: "`username` LIKE '%swagger'", default: "[username] LIKE '%swagger'"
postgres: '"username" LIKE \'%swagger\'',
mssql: "[username] LIKE '%swagger'"
}); });
}); });
...@@ -209,18 +173,14 @@ suite('SQL', function() { ...@@ -209,18 +173,14 @@ suite('SQL', function() {
testsql('date', { testsql('date', {
$between: ['2013-01-01', '2013-01-11'] $between: ['2013-01-01', '2013-01-11']
}, { }, {
default: "`date` BETWEEN '2013-01-01' AND '2013-01-11'", default: "[date] BETWEEN '2013-01-01' AND '2013-01-11'"
postgres: '"date" BETWEEN \'2013-01-01\' AND \'2013-01-11\'',
mssql: "[date] BETWEEN '2013-01-01' AND '2013-01-11'"
}); });
testsql('date', { testsql('date', {
between: ['2012-12-10', '2013-01-02'], between: ['2012-12-10', '2013-01-02'],
nbetween: ['2013-01-04', '2013-01-20'] nbetween: ['2013-01-04', '2013-01-20']
}, { }, {
default: "(`date` BETWEEN '2012-12-10' AND '2013-01-02' AND `date` NOT BETWEEN '2013-01-04' AND '2013-01-20')", default: "([date] BETWEEN '2012-12-10' AND '2013-01-02' AND [date] NOT BETWEEN '2013-01-04' AND '2013-01-20')"
postgres: '("date" BETWEEN \'2012-12-10\' AND \'2013-01-02\' AND "date" NOT BETWEEN \'2013-01-04\' AND \'2013-01-20\')',
mssql: "([date] BETWEEN '2012-12-10' AND '2013-01-02' AND [date] NOT BETWEEN '2013-01-04' AND '2013-01-20')"
}); });
}); });
...@@ -228,9 +188,7 @@ suite('SQL', function() { ...@@ -228,9 +188,7 @@ suite('SQL', function() {
testsql('date', { testsql('date', {
$notBetween: ['2013-01-01', '2013-01-11'] $notBetween: ['2013-01-01', '2013-01-11']
}, { }, {
default: "`date` NOT BETWEEN '2013-01-01' AND '2013-01-11'", default: "[date] NOT BETWEEN '2013-01-01' AND '2013-01-11'"
postgres: '"date" NOT BETWEEN \'2013-01-01\' AND \'2013-01-11\'',
mssql: "[date] NOT BETWEEN '2013-01-01' AND '2013-01-11'"
}); });
}); });
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!