foxhound
Version:
A Database Query generation library.
254 lines (239 loc) • 6.38 kB
JavaScript
/**
* Unit tests for FoxHound
*
* @license MIT
*
* @author Steven Velozo <steven@velozo.com>
*/
var Chai = require('chai');
var Expect = Chai.expect;
var Assert = Chai.assert;
var libFable = require('fable');
const _Fable = new libFable({Product:'FoxhoundTestsEnglish'});
var libFoxHound = require('../source/FoxHound.js');
suite
(
'FoxHound-Dialect-English',
function()
{
setup
(
function()
{
}
);
suite
(
'Object Sanity',
function()
{
test
(
'initialize should build a happy little object',
function()
{
var testFoxHound = libFoxHound.new(_Fable).setDialect('English');
Expect(testFoxHound.dialect.name)
.to.equal('English');
Expect(testFoxHound)
.to.be.an('object', 'FoxHound with English should initialize as an object directly from the require statement.');
}
);
}
);
suite
(
'Basic Query Generation',
function()
{
test
(
'Create Query',
function()
{
var tmpQuery = libFoxHound.new(_Fable).setLogLevel(5).setDialect('English').setScope('Animal');
// Build the query
tmpQuery.buildCreateQuery();
// This is the query generated by the English dialect
Expect(tmpQuery.query.body)
.to.equal('Here is a Animal.');
}
);
test
(
'Read Query',
function()
{
var tmpQuery = libFoxHound.new(_Fable).setScope('Animal');
// Build the query
tmpQuery.buildReadQuery();
// This is the query generated by the English dialect
Expect(tmpQuery.query.body)
.to.equal('Please give me all your Animal records. Thanks.');
}
);
test
(
'Read Query with Distinct',
function()
{
var tmpQuery = libFoxHound.new(_Fable).setScope('Animal').setDistinct(true);
// Build the query
tmpQuery.buildReadQuery();
// This is the query generated by the English dialect
Expect(tmpQuery.query.body)
.to.equal('Please give me all your unique Animal records. Thanks.');
}
);
test
(
'Complex Read Query',
function()
{
var tmpQuery = libFoxHound.new(_Fable)
.setDialect('English')
.setScope('Animal')
.setCap(10)
.setBegin(0)
.setDataElements('Name')
.setSort()
.setFilter({Column:'Name',Operator:'EQ',Value:'William'});
// Build the query
tmpQuery.buildReadQuery();
// This is the query generated by the English dialect
Expect(tmpQuery.query.body)
.to.equal('Please give me all your Animal records. Thanks.');
}
);
test
(
'Complex Alternate Read Query',
function()
{
var tmpQuery = libFoxHound.new(_Fable)
.setDialect('English')
.setScope('Animal')
.setCap(10)
.setBegin(0)
.setDataElements(['Name', 'Age'])
.setSort({Column:'Age',Direction:'Ascending'})
.setFilter();
// Build the query
tmpQuery.buildReadQuery();
// This is the query generated by the English dialect
Expect(tmpQuery.query.body)
.to.equal('Please give me all your Animal records. Thanks.');
}
);
test
(
'Complex Alternate Read Query 2',
function()
{
var tmpQuery = libFoxHound.new(_Fable)
.setDialect('English')
.setScope('Animal')
.setCap(10)
.setBegin(0)
.setDataElements(['Name', 'Age'])
.setSort([{Column:'Name',Direction:'Ascending'},{Column:'Age',Direction:'Ascending'}])
.setFilter([{Column:'Name',Operator:'EQ',Value:'Janet'}]);
// Build the query
tmpQuery.buildReadQuery();
// This is the query generated by the English dialect
Expect(tmpQuery.query.body)
.to.equal('Please give me all your Animal records. Thanks.');
}
);
test
(
'Complex Read Query with Logging',
function()
{
var tmpQuery = libFoxHound.new(_Fable)
.setLogLevel(5)
.setDialect('English')
.setScope('Animal')
.setCap(10)
.setBegin(0)
.setDataElements('Name')
.setSort('Age')
.setFilter([{Column:'Name',Operator:'EQ',Value:'Janet'}]);
// Build the query
tmpQuery.buildReadQuery();
// This is the query generated by the English dialect
Expect(tmpQuery.query.body)
.to.equal('Please give me all your Animal records. Thanks.');
// Now clone it
var tmpQueryCopy = tmpQuery.clone();
}
);
test
(
'Update Query',
function()
{
var tmpQuery = libFoxHound.new(_Fable).setDialect('English').setScope('Animal');
// Build the query
tmpQuery.buildUpdateQuery();
// This is the query generated by the English dialect
Expect(tmpQuery.query.body)
.to.equal('I am changing your Animal.');
}
);
test
(
'Delete Query',
function()
{
var tmpQuery = libFoxHound.new(_Fable).setDialect('English').setScope('Animal');
// Build the query
tmpQuery.buildDeleteQuery();
// This is the query generated by the English dialect
Expect(tmpQuery.query.body)
.to.equal('I am deleting your Animal.');
}
);
test
(
'Undelete Query',
function()
{
var tmpQuery = libFoxHound.new(_Fable).setDialect('English').setScope('Animal');
// Build the query
tmpQuery.buildUndeleteQuery();
// This is the query generated by the English dialect
Expect(tmpQuery.query.body)
.to.equal('I am undeleting your Animal.');
}
);
test
(
'Count Query',
function()
{
var tmpQuery = libFoxHound.new(_Fable).setDialect('English').setScope('Animal');
// Build the query
tmpQuery.buildCountQuery();
// This is the query generated by the English dialect
Expect(tmpQuery.query.body)
.to.equal('Count your Animal.');
}
);
test
(
'Count Query with Distinct',
function()
{
var tmpQuery = libFoxHound.new(_Fable).setDialect('English').setScope('Animal').setDistinct(true);
// Build the query
tmpQuery.buildCountQuery();
// This is the query generated by the English dialect
Expect(tmpQuery.query.body)
.to.equal('Count your unique Animal.');
}
);
}
);
}
);