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

Commit 28b8cfd2 by Daniel Durante

Moved the main connection out into Mocha's global Suite describe, made all tests…

… async, and added Makefile. Also added data-types test.
1 parent daf4c69a
test:
@mocha -c $(find ./test -name "*.test.js")
.PHONY: test
...@@ -2,12 +2,13 @@ var chai = require('chai') ...@@ -2,12 +2,13 @@ var chai = require('chai')
, expect = chai.expect , expect = chai.expect
, semver = require("semver") , semver = require("semver")
, config = require(__dirname + "/config/config") , config = require(__dirname + "/config/config")
, Utils = require(__dirname + '/../lib/utils')
, Support = require(__dirname + '/support') , Support = require(__dirname + '/support')
, dialect = Support.getTestDialect() , dialect = Support.getTestDialect()
, Sequelize = require(__dirname + '/../index') , Sequelize = require(__dirname + '/../index')
, noDomains = semver.lt(process.version, '0.8.0') , noDomains = semver.lt(process.version, '0.8.0')
chai.Assertion.includeStack = true
describe(Support.getTestDialectTeaser("Configuration"), function() { describe(Support.getTestDialectTeaser("Configuration"), function() {
describe('Connections problems should fail with a nice message', function() { describe('Connections problems should fail with a nice message', function() {
it('when we don\'t have the correct server details', function(done) { it('when we don\'t have the correct server details', function(done) {
......
var chai = require('chai') var chai = require('chai')
, expect = chai.expect , expect = chai.expect
, Sequelize = require(__dirname + '/../index') , Sequelize = require(__dirname + '/../index')
, Utils = require(__dirname + '/../lib/utils')
, Support = require(__dirname + '/support') , Support = require(__dirname + '/support')
, dialect = Support.getTestDialect()
describe(Support.getTestDialectTeaser("DaoValidator"), function() { chai.Assertion.includeStack = true
var sequelize = Support.createSequelizeInstance({ dialect: dialect })
describe(Support.getTestDialectTeaser("DaoValidator"), function() {
describe('validations', function() { describe('validations', function() {
before(function(done) {
this.sequelize = Object.create(sequelize)
Support.clearDatabase(this.sequelize, done)
})
var checks = { var checks = {
is: { is: {
spec: { args: ["[a-z]",'i'] }, spec: { args: ["[a-z]",'i'] },
......
var chai = require('chai')
, expect = chai.expect
, Sequelize = require(__dirname + '/../index')
, Support = require(__dirname + '/support')
chai.Assertion.includeStack = true
describe(Support.getTestDialectTeaser('DataTypes'), function() {
it('should return DECIMAL for the default decimal type', function(done) {
expect(Sequelize.DECIMAL.toString()).to.equal('DECIMAL')
done()
})
it('should return DECIMAL(10,2) for the default decimal type with arguments', function(done) {
expect(Sequelize.DECIMAL(10, 2)).to.equal('DECIMAL(10,2)')
done()
})
var tests = [
[Sequelize.STRING, 'STRING', 'VARCHAR(255)'],
[Sequelize.STRING(1234), 'STRING(1234)', 'VARCHAR(1234)'],
[Sequelize.STRING(1234).BINARY, 'STRING(1234).BINARY', 'VARCHAR(1234) BINARY'],
[Sequelize.STRING.BINARY, 'STRING.BINARY', 'VARCHAR(255) BINARY'],
[Sequelize.TEXT, 'TEXT', 'TEXT'],
[Sequelize.DATE, 'DATE', 'DATETIME'],
[Sequelize.NOW, 'NOW', 'NOW'],
[Sequelize.BOOLEAN, 'BOOLEAN', 'TINYINT(1)'],
[Sequelize.INTEGER, 'INTEGER', 'INTEGER'],
[Sequelize.INTEGER.UNSIGNED, 'INTEGER.UNSIGNED', 'INTEGER UNSIGNED'],
[Sequelize.INTEGER(11), 'INTEGER(11)','INTEGER(11)'],
[Sequelize.INTEGER(11).UNSIGNED, 'INTEGER(11).UNSIGNED', 'INTEGER(11) UNSIGNED'],
[Sequelize.INTEGER(11).UNSIGNED.ZEROFILL,'INTEGER(11).UNSIGNED.ZEROFILL','INTEGER(11) UNSIGNED ZEROFILL'],
[Sequelize.INTEGER(11).ZEROFILL,'INTEGER(11).ZEROFILL', 'INTEGER(11) ZEROFILL'],
[Sequelize.INTEGER(11).ZEROFILL.UNSIGNED,'INTEGER(11).ZEROFILL.UNSIGNED', 'INTEGER(11) UNSIGNED ZEROFILL'],
[Sequelize.BIGINT, 'BIGINT', 'BIGINT'],
[Sequelize.BIGINT.UNSIGNED, 'BIGINT.UNSIGNED', 'BIGINT UNSIGNED'],
[Sequelize.BIGINT(11), 'BIGINT(11)','BIGINT(11)'],
[Sequelize.BIGINT(11).UNSIGNED, 'BIGINT(11).UNSIGNED', 'BIGINT(11) UNSIGNED'],
[Sequelize.BIGINT(11).UNSIGNED.ZEROFILL, 'BIGINT(11).UNSIGNED.ZEROFILL','BIGINT(11) UNSIGNED ZEROFILL'],
[Sequelize.BIGINT(11).ZEROFILL, 'BIGINT(11).ZEROFILL', 'BIGINT(11) ZEROFILL'],
[Sequelize.BIGINT(11).ZEROFILL.UNSIGNED, 'BIGINT(11).ZEROFILL.UNSIGNED', 'BIGINT(11) UNSIGNED ZEROFILL'],
[Sequelize.FLOAT, 'FLOAT', 'FLOAT'],
[Sequelize.FLOAT.UNSIGNED, 'FLOAT.UNSIGNED', 'FLOAT UNSIGNED'],
[Sequelize.FLOAT(11), 'FLOAT(11)','FLOAT(11)'],
[Sequelize.FLOAT(11).UNSIGNED, 'FLOAT(11).UNSIGNED', 'FLOAT(11) UNSIGNED'],
[Sequelize.FLOAT(11).UNSIGNED.ZEROFILL,'FLOAT(11).UNSIGNED.ZEROFILL','FLOAT(11) UNSIGNED ZEROFILL'],
[Sequelize.FLOAT(11).ZEROFILL,'FLOAT(11).ZEROFILL', 'FLOAT(11) ZEROFILL'],
[Sequelize.FLOAT(11).ZEROFILL.UNSIGNED,'FLOAT(11).ZEROFILL.UNSIGNED', 'FLOAT(11) UNSIGNED ZEROFILL'],
[Sequelize.FLOAT(11, 12), 'FLOAT(11,12)','FLOAT(11,12)'],
[Sequelize.FLOAT(11, 12).UNSIGNED, 'FLOAT(11,12).UNSIGNED', 'FLOAT(11,12) UNSIGNED'],
[Sequelize.FLOAT(11, 12).UNSIGNED.ZEROFILL,'FLOAT(11,12).UNSIGNED.ZEROFILL','FLOAT(11,12) UNSIGNED ZEROFILL'],
[Sequelize.FLOAT(11, 12).ZEROFILL,'FLOAT(11,12).ZEROFILL', 'FLOAT(11,12) ZEROFILL'],
[Sequelize.FLOAT(11, 12).ZEROFILL.UNSIGNED,'FLOAT(11,12).ZEROFILL.UNSIGNED', 'FLOAT(11,12) UNSIGNED ZEROFILL']
]
tests.forEach(function(test) {
it('transforms "' + test[1] + '" to "' + test[2] + '"', function(done) {
expect(test[0].toString()).to.equal(test[2])
done()
})
})
})
var Support = require(__dirname + '/support')
, dialect = Support.getTestDialect()
before(function(done) {
var sequelize = Support.createSequelizeInstance({ dialect: dialect })
this.sequelize = sequelize
Support.clearDatabase(this.sequelize, done)
})
...@@ -3,9 +3,11 @@ var chai = require('chai') ...@@ -3,9 +3,11 @@ var chai = require('chai')
, Utils = require(__dirname + '/../lib/utils') , Utils = require(__dirname + '/../lib/utils')
, Support = require(__dirname + '/support') , Support = require(__dirname + '/support')
chai.Assertion.includeStack = true
describe(Support.getTestDialectTeaser("Utils"), function() { describe(Support.getTestDialectTeaser("Utils"), function() {
describe('removeCommentsFromFunctionString', function() { describe('removeCommentsFromFunctionString', function() {
it("removes line comments at the start of a line", function() { it("removes line comments at the start of a line", function(done) {
var functionWithLineComments = function() { var functionWithLineComments = function() {
// noot noot // noot noot
} }
...@@ -14,9 +16,10 @@ describe(Support.getTestDialectTeaser("Utils"), function() { ...@@ -14,9 +16,10 @@ describe(Support.getTestDialectTeaser("Utils"), function() {
, result = Utils.removeCommentsFromFunctionString(string) , result = Utils.removeCommentsFromFunctionString(string)
expect(result).not.to.match(/.*noot.*/) expect(result).not.to.match(/.*noot.*/)
done()
}) })
it("removes lines comments in the middle of a line", function() { it("removes lines comments in the middle of a line", function(done) {
var functionWithLineComments = function() { var functionWithLineComments = function() {
alert(1) // noot noot alert(1) // noot noot
} }
...@@ -25,9 +28,10 @@ describe(Support.getTestDialectTeaser("Utils"), function() { ...@@ -25,9 +28,10 @@ describe(Support.getTestDialectTeaser("Utils"), function() {
, result = Utils.removeCommentsFromFunctionString(string) , result = Utils.removeCommentsFromFunctionString(string)
expect(result).not.to.match(/.*noot.*/) expect(result).not.to.match(/.*noot.*/)
done()
}) })
it("removes range comments", function() { it("removes range comments", function(done) {
var s = function() { var s = function() {
alert(1) /* alert(1) /*
noot noot noot noot
...@@ -42,67 +46,80 @@ describe(Support.getTestDialectTeaser("Utils"), function() { ...@@ -42,67 +46,80 @@ describe(Support.getTestDialectTeaser("Utils"), function() {
expect(result).not.to.match(/.*noot.*/) expect(result).not.to.match(/.*noot.*/)
expect(result).not.to.match(/.*foo.*/) expect(result).not.to.match(/.*foo.*/)
expect(result).to.match(/.*alert\(2\).*/) expect(result).to.match(/.*alert\(2\).*/)
done()
}) })
}) })
describe('argsArePrimaryKeys', function() { describe('argsArePrimaryKeys', function() {
it("doesn't detect primary keys if primareyKeys and values have different lengths", function() { it("doesn't detect primary keys if primareyKeys and values have different lengths", function(done) {
expect(Utils.argsArePrimaryKeys([1,2,3], [1])).to.be.false expect(Utils.argsArePrimaryKeys([1,2,3], [1])).to.be.false
done()
}) })
it("doesn't detect primary keys if primary keys are hashes or arrays", function() { it("doesn't detect primary keys if primary keys are hashes or arrays", function(done) {
expect(Utils.argsArePrimaryKeys([[]], [1])).to.be.false expect(Utils.argsArePrimaryKeys([[]], [1])).to.be.false
done()
}) })
it('detects primary keys if length is correct and data types are matching', function() { it('detects primary keys if length is correct and data types are matching', function(done) {
expect(Utils.argsArePrimaryKeys([1,2,3], ["INTEGER", "INTEGER", "INTEGER"])).to.be.true expect(Utils.argsArePrimaryKeys([1,2,3], ["INTEGER", "INTEGER", "INTEGER"])).to.be.true
done()
}) })
it("detects primary keys if primary keys are dates and lengths are matching", function() { it("detects primary keys if primary keys are dates and lengths are matching", function(done) {
expect(Utils.argsArePrimaryKeys([new Date()], ['foo'])).to.be.true expect(Utils.argsArePrimaryKeys([new Date()], ['foo'])).to.be.true
done()
}) })
}) })
describe('underscore', function() { describe('underscore', function() {
describe('underscoredIf', function() { describe('underscoredIf', function() {
it('is defined', function() { it('is defined', function(done) {
expect(Utils._.underscoredIf).to.be.ok expect(Utils._.underscoredIf).to.be.ok
done()
}) })
it('underscores if second param is true', function() { it('underscores if second param is true', function(done) {
expect(Utils._.underscoredIf('fooBar', true)).to.equal('foo_bar') expect(Utils._.underscoredIf('fooBar', true)).to.equal('foo_bar')
done()
}) })
it("doesn't underscore if second param is false", function() { it("doesn't underscore if second param is false", function(done) {
expect(Utils._.underscoredIf('fooBar', false)).to.equal('fooBar') expect(Utils._.underscoredIf('fooBar', false)).to.equal('fooBar')
done()
}) })
}) })
describe('camelizeIf', function() { describe('camelizeIf', function() {
it('is defined', function() { it('is defined', function(done) {
expect(Utils._.camelizeIf).to.be.ok expect(Utils._.camelizeIf).to.be.ok
done()
}) })
it('camelizes if second param is true', function() { it('camelizes if second param is true', function(done) {
expect(Utils._.camelizeIf('foo_bar', true)).to.equal('fooBar') expect(Utils._.camelizeIf('foo_bar', true)).to.equal('fooBar')
done()
}) })
it("doesn't camelize if second param is false", function() { it("doesn't camelize if second param is false", function(done) {
expect(Utils._.underscoredIf('fooBar', true)).to.equal('foo_bar') expect(Utils._.underscoredIf('fooBar', true)).to.equal('foo_bar')
done()
}) })
}) })
}) })
describe('isHash', function() { describe('isHash', function() {
it('doesn\'t match arrays', function() { it('doesn\'t match arrays', function(done) {
expect(Utils.isHash([])).to.be.false expect(Utils.isHash([])).to.be.false
done()
}) })
it('doesn\'t match null', function() { it('doesn\'t match null', function(done) {
expect(Utils.isHash(null)).to.be.false expect(Utils.isHash(null)).to.be.false
done()
}) })
it('matches plain objects', function() { it('matches plain objects', function(done) {
var values = { var values = {
'name': { 'name': {
'first': 'Foo', 'first': 'Foo',
...@@ -111,9 +128,10 @@ describe(Support.getTestDialectTeaser("Utils"), function() { ...@@ -111,9 +128,10 @@ describe(Support.getTestDialectTeaser("Utils"), function() {
} }
expect(Utils.isHash(values)).to.be.true expect(Utils.isHash(values)).to.be.true
done()
}) })
it('matches plain objects with length property/key', function() { it('matches plain objects with length property/key', function(done) {
var values = { var values = {
'name': { 'name': {
'first': 'Foo', 'first': 'Foo',
...@@ -123,18 +141,21 @@ describe(Support.getTestDialectTeaser("Utils"), function() { ...@@ -123,18 +141,21 @@ describe(Support.getTestDialectTeaser("Utils"), function() {
} }
expect(Utils.isHash(values)).to.be.true expect(Utils.isHash(values)).to.be.true
done()
}) })
}) })
describe('format', function() { describe('format', function() {
it('should format where clause correctly when the value is truthy', function() { it('should format where clause correctly when the value is truthy', function(done) {
var where = ['foo = ?', 1] var where = ['foo = ?', 1]
expect(Utils.format(where)).to.equal('foo = 1') expect(Utils.format(where)).to.equal('foo = 1')
done()
}) })
it('should format where clause correctly when the value is false', function() { it('should format where clause correctly when the value is false', function(done) {
var where = ['foo = ?', 0] var where = ['foo = ?', 0]
expect(Utils.format(where)).to.equal('foo = 0') expect(Utils.format(where)).to.equal('foo = 0')
done()
}) })
}) })
}) })
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!