Skip to content

Commit

Permalink
adding tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Apr 23, 2017
1 parent 811dddf commit 5f408a1
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"env": {
"es6": false,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
Expand Down
24 changes: 0 additions & 24 deletions lib/adapters/config.js

This file was deleted.

25 changes: 25 additions & 0 deletions lib/adapters/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

/**
* @class Database
* @description
* Represents configuration of a server driver.
*
* @param {Object} driver
* Database driver object.
*
* @returns {Database}
*/
function Database(driver) {

if (!driver || typeof driver !== 'object') {
throw new TypeError('Invalid driver specified.');
}

if (!(this instanceof Database)) {
return new Database(driver);
}

}

module.exports = Database;
21 changes: 11 additions & 10 deletions lib/adapters/type.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
'use strict';

/**
* @class TypeAdapter
* @class DataType
* @description
* Represents a single database type.
* Represents a single data type.
*
* @param {Object} driverType
* @param {Object} dt
* Database Data Type.
*
* @returns {TypeAdapter}
* @returns {DataType}
*/
function TypeAdapter(driverType) {
function DataType(dt) {

if (!driverType || typeof driverType !== 'object') {
throw new TypeError('Invalid driver specified.');
if (!dt || typeof dt !== 'object') {
throw new TypeError('Invalid database type specified.');
}

if (!(this instanceof TypeAdapter)) {
return new TypeAdapter(driverType);
if (!(this instanceof DataType)) {
return new DataType(dt);
}

}

module.exports = TypeAdapter;
module.exports = DataType;

16 changes: 10 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
'use strict';

var ConfigAdapter = require('./adapters/config');
var TypeAdapter = require('./adapters/type');
var nodeHighVer = +process.versions.node.split('.')[0];

module.exports = {
ConfigAdapter: ConfigAdapter,
TypeAdapter: TypeAdapter
};
// istanbul ignore if
if (nodeHighVer < 4) {
throw new Error('Minimum Node.js version required by db-types is 4.x');
}

var Database = require('./adapters/database');
var DataType = require('./adapters/type');

module.exports = {Database, DataType};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
},
"license": "MIT",
"engines": {
"node": ">=0.10",
"npm": ">=1.4"
"node": ">=4.0",
"npm": ">=2.15"
},
"devDependencies": {
"istanbul": "0.4",
Expand Down
25 changes: 25 additions & 0 deletions test/databaseSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

var lib = require('../');

describe("Database", function () {

it("must initialize correctly", function () {
expect(lib.Database({}) instanceof lib.Database).toBe(true);
expect(new lib.Database({}) instanceof lib.Database).toBe(true);
});

it("must throw on invalid parameters", function () {
var error = new TypeError('Invalid driver specified.');
expect(function () {
lib.Database(undefined);
}).toThrow(error);
expect(function () {
lib.Database(123);
}).toThrow(error);
expect(function () {
lib.Database('hello');
}).toThrow(error);
});

});
7 changes: 5 additions & 2 deletions test/mainSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
var lib = require('../');

describe("Main", function () {
it("must do something", function () {

it("must initialize correctly", function () {
expect(typeof lib.Database).toBe('function');
expect(typeof lib.DataType).toBe('function');
});
});

});
25 changes: 25 additions & 0 deletions test/typeSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

var lib = require('../');

describe("DataType", function () {

it("must initialize correctly", function () {
expect(lib.DataType({}) instanceof lib.DataType).toBe(true);
expect(new lib.DataType({}) instanceof lib.DataType).toBe(true);
});

it("must throw on invalid parameters", function () {
var error = new TypeError('Invalid database type specified.');
expect(function () {
lib.DataType(undefined);
}).toThrow(error);
expect(function () {
lib.DataType(123);
}).toThrow(error);
expect(function () {
lib.DataType('hello');
}).toThrow(error);
});

});

0 comments on commit 5f408a1

Please sign in to comment.