Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lodash and test scripts update #420

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,907 changes: 1,907 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"node": "*"
},
"dependencies": {
"sliced": "0.0.x",
"lodash": "4.1.x"
"lodash": "^4.17.21",
"sliced": "0.0.x"
},
"devDependencies": {
"jshint": "*",
Expand Down
2 changes: 1 addition & 1 deletion test/binary-clause-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var Foo = Table.define({
columns: ['baz','bar']
});

test('operators', function() {
it('operators', function() {
assert.equal(Foo.baz.equals(1).operator, '=');
assert.equal(Foo.baz.equal(1).operator, '=');
assert.equal(Foo.baz.notEqual(1).operator, '<>');
Expand Down
2 changes: 1 addition & 1 deletion test/clause-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var Boom = Node.define({
}
});

test('clause definition', function() {
it('clause definition', function() {
var select = new Bang();
assert.equal(select.type, 'SELECT');
assert.equal(select.nodes.length, 0);
Expand Down
2 changes: 1 addition & 1 deletion test/dialects/create-table-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ Harness.test({

// TEMPORARY TABLE TESTS

// This tests explicitly setting the isTemporary flag to false, as opposed to all the test above here which have it
// This its explicitly setting the isTemporary flag to false, as opposed to all the it above here which have it
// as undefined.
Harness.test({
query: Table.define({
Expand Down
2 changes: 1 addition & 1 deletion test/dialects/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
var DialectClass = dialects[dialect];

var title = dialect + ': ' + (expected.title || expectedObject.text || expectedObject);
test(title, function() {
it(title, function() {

// check if this query is expected to throw
if (expectedObject.throws) {
Expand Down
20 changes: 10 additions & 10 deletions test/function-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ var user = sql.define({
]
});

suite('function', function() {
test('alias function call', function() {
describe('function', function() {
it('alias function call', function() {
var upper = sql.functions.UPPER;
var aliasedUpper = upper(user.email).as('upperAlias').toQuery();

assert.equal(aliasedUpper.text, 'UPPER("user"."email") AS "upperAlias"');
});

test('function call on aliased column', function() {
it('function call on aliased column', function() {
var round = sql.functions.ROUND;
var aliasedRound = round(user.howOld, 2).toQuery();

assert.equal(aliasedRound.text, 'ROUND("user"."age", $1)');
assert.equal(aliasedRound.values[0], 2);
});

test('creating function call works', function() {
it('creating function call works', function() {
var upper = sql.functionCallCreator('UPPER');
var functionCall = upper('hello', 'world').toQuery();

Expand All @@ -38,23 +38,23 @@ suite('function', function() {
assert.equal(functionCall.values[1], 'world');
});

test('creating function call on columns works', function() {
it('creating function call on columns works', function() {
var upper = sql.functionCallCreator('UPPER');
var functionCall = upper(user.id, user.email).toQuery();

assert.equal(functionCall.text, 'UPPER("user"."id", "user"."email")');
assert.equal(functionCall.values.length, 0);
});

test('function call inside select works', function() {
it('function call inside select works', function() {
var upper = sql.functionCallCreator('UPPER');
var query = sql.select(upper(user.id, user.email)).from(user).where(user.email.equals('[email protected]')).toQuery();

assert.equal(query.text, 'SELECT UPPER("user"."id", "user"."email") FROM "user" WHERE ("user"."email" = $1)');
assert.equal(query.values[0], '[email protected]');
});

test('standard aggregate functions with having clause', function() {
it('standard aggregate functions with having clause', function() {
var count = sql.functions.COUNT;
var distinct = sql.functions.DISTINCT;
var distinctEmailCount = count(distinct(user.email));
Expand All @@ -65,7 +65,7 @@ suite('function', function() {
assert.equal(query.values[0], 100);
});

test('custom and standard functions behave the same', function() {
it('custom and standard functions behave the same', function() {
var standardUpper = sql.functions.UPPER;
var customUpper = sql.functionCallCreator('UPPER');

Expand All @@ -77,15 +77,15 @@ suite('function', function() {
assert.equal(customQuery.text, expectedQuery);
});

test('combine function with operations', function() {
it('combine function with operations', function() {
var f = sql.functions;
var query = user.select(f.AVG(f.DISTINCT(f.COUNT(user.id).plus(f.MAX(user.id))).minus(f.MIN(user.id))).multiply(100)).toQuery();

assert.equal(query.text, 'SELECT (AVG((DISTINCT((COUNT("user"."id") + MAX("user"."id"))) - MIN("user"."id"))) * $1) FROM "user"');
assert.equal(query.values[0], 100);
});

test('use custom function', function() {
it('use custom function', function() {
var query = user.select(sql.function('PHRASE_TO_TSQUERY')('simple', user.name)).toQuery();
assert.equal(query.text, 'SELECT PHRASE_TO_TSQUERY($1, "user"."name") FROM "user"');
assert.equal(query.values[0], 'simple');
Expand Down
42 changes: 21 additions & 21 deletions test/index-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,55 @@ var user = sql.define({
columns: ['id', 'email']
});

suite('index', function() {
test('unknown dialect throws exception', function() {
describe('index', function() {
it('unknown dialect throws exception', function() {
assert.throws(function() {
sql.setDialect('asdf');
});
});

test('stores the default dialect\'s name if none has been passed', function() {
it('stores the default dialect\'s name if none has been passed', function() {
assert.equal(sql.create().dialectName, 'postgres');
});

test('stores the sqlite dialect', function() {
it('stores the sqlite dialect', function() {
assert.equal(sql.create('sqlite').dialectName, 'sqlite');
});

test('stores the mysql dialect', function() {
it('stores the mysql dialect', function() {
assert.equal(sql.create('mysql').dialectName, 'mysql');
});

test('stores the mssql dialect', function() {
it('stores the mssql dialect', function() {
assert.equal(sql.create('mssql').dialectName, 'mssql');
});

test('stores the oracle dialect', function() {
it('stores the oracle dialect', function() {
assert.equal(sql.create('oracle').dialectName, 'oracle');
});


test('can create a query using the default dialect', function() {
it('can create a query using the default dialect', function() {
var query = sql.select(user.id).from(user).where(user.email.equals('[email protected]')).toQuery();
assert.equal(query.text, 'SELECT "user"."id" FROM "user" WHERE ("user"."email" = $1)');
assert.equal(query.values[0], '[email protected]');
});

test('setting dialect to postgres works', function() {
it('setting dialect to postgres works', function() {
sql.setDialect('postgres');
var query = sql.select(user.id).from(user).where(user.email.equals('[email protected]')).toQuery();
assert.equal(query.text, 'SELECT "user"."id" FROM "user" WHERE ("user"."email" = $1)');
assert.equal(query.values[0], '[email protected]');
});

test('sql.create creates an instance with a new dialect', function() {
it('sql.create creates an instance with a new dialect', function() {
var mysql = sql.create('mysql');
var query = mysql.select(user.id).from(user).where(user.email.equals('[email protected]')).toQuery();
assert.equal(query.text, 'SELECT `user`.`id` FROM `user` WHERE (`user`.`email` = ?)');
assert.equal(query.values[0], '[email protected]');
});

test('sql.define for parallel dialects work independently', function() {
it('sql.define for parallel dialects work independently', function() {
var mssql = sql.create('mssql');
var mysql = sql.create('mysql');
var postgres = sql.create('postgres');
Expand All @@ -76,7 +76,7 @@ suite('index', function() {
assert.equal(oracleTable.sql, oracle);
});

test('using Sql as a class', function() {
it('using Sql as a class', function() {
var Sql = sql.Sql;
var mssql = new Sql('mssql');
var mysql = new Sql('mysql');
Expand All @@ -91,7 +91,7 @@ suite('index', function() {
assert.equal(oracle.dialect, require(__dirname + '/../lib/dialect/oracle'));
});

test('override dialect for toQuery using dialect name', function() {
it('override dialect for toQuery using dialect name', function() {
var Sql = sql.Sql;
var mssql = new Sql('mssql');
var mysql = new Sql('mysql');
Expand Down Expand Up @@ -122,35 +122,35 @@ suite('index', function() {
assert.deepEqual(oracleQuery.values, values);
});

test('override dialect for toQuery using invalid dialect name', function() {
it('override dialect for toQuery using invalid dialect name', function() {
var query = sql.select(user.id).from(user);
assert.throws(function() {
query.toQuery('invalid');
});
});

test('using named queries with toNamedQuery', function() {
it('using named queries with toNamedQuery', function() {
var query = sql.select(user.id).from(user).where(user.email.equals('[email protected]')).toNamedQuery('users');
assert.equal(query.text, 'SELECT "user"."id" FROM "user" WHERE ("user"."email" = $1)');
assert.equal(query.values[0], '[email protected]');
assert.equal(query.name, 'users');
});

test('provide an empty query name for toNamedQuery', function() {
it('provide an empty query name for toNamedQuery', function() {
var query = sql.select(user.id).from(user);
assert.throws(function() {
query.toNamedQuery('');
});
});

test('provide an undefined query name for toNamedQuery', function() {
it('provide an undefined query name for toNamedQuery', function() {
var query = sql.select(user.id).from(user);
assert.throws(function() {
query.toNamedQuery();
});
});

test('override dialect for toNamedQuery using dialect name', function() {
it('override dialect for toNamedQuery using dialect name', function() {
var Sql = sql.Sql;
var mysql = new Sql('mysql');
var postgres = new Sql('postgres');
Expand Down Expand Up @@ -188,22 +188,22 @@ suite('index', function() {

});

test('override dialect for toNamedQuery using invalid dialect name', function() {
it('override dialect for toNamedQuery using invalid dialect name', function() {
var query = sql.select(user.id).from(user);
assert.throws(function() {
query.toNamedQuery('name', 'invalid');
});
});

test('mssql default parameter place holder is @index', function() {
it('mssql default parameter place holder is @index', function() {
var Sql = sql.Sql;
var mssql = new Sql('mssql');
var query = mssql.select(user.id).from(user).where(user.email.equals('[email protected]')).toQuery();
assert.equal(query.text, 'SELECT [user].[id] FROM [user] WHERE ([user].[email] = @1)');
assert.equal(query.values[0], '[email protected]');
});

test('mssql override default parameter placeholder with ?', function() {
it('mssql override default parameter placeholder with ?', function() {
var Sql = sql.Sql;
var mssql = new Sql('mssql',{questionMarkParameterPlaceholder:true});
var query = mssql.select(user.id).from(user).where(user.email.equals('[email protected]')).toQuery();
Expand Down
4 changes: 2 additions & 2 deletions test/select-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ var Select = require(__dirname + '/../lib/node/select');

var select = new Select({sql: require('../lib/index')});

test('has SELECT type', function() {
it('has SELECT type', function() {
assert.equal(select.type, 'SELECT');
});


test('can go toQuery', function() {
it('can go toQuery', function() {
assert.equal(select.toQuery().text, 'SELECT ');
});
Loading