UNPKG

5.17 kBJavaScriptView Raw
1/**
2* Unit tests for FoxHound
3*
4* @license MIT
5*
6* @author Steven Velozo <steven@velozo.com>
7*/
8
9var Chai = require('chai');
10var Expect = Chai.expect;
11var Assert = Chai.assert;
12
13var libFable = require('fable');
14var libFoxHound = require('../source/FoxHound.js');
15
16suite
17(
18 'FoxHound-Dialect-English',
19 function()
20 {
21 setup
22 (
23 function()
24 {
25 }
26 );
27
28 suite
29 (
30 'Object Sanity',
31 function()
32 {
33 test
34 (
35 'initialize should build a happy little object',
36 function()
37 {
38 var testFoxHound = libFoxHound.new(libFable).setDialect('English');
39 Expect(testFoxHound.dialect.name)
40 .to.equal('English');
41 Expect(testFoxHound)
42 .to.be.an('object', 'FoxHound with English should initialize as an object directly from the require statement.');
43 }
44 );
45 }
46 );
47
48 suite
49 (
50 'Basic Query Generation',
51 function()
52 {
53 test
54 (
55 'Create Query',
56 function()
57 {
58 var tmpQuery = libFoxHound.new(libFable).setLogLevel(5).setDialect('English').setScope('Animal');
59 // Build the query
60 tmpQuery.buildCreateQuery();
61 // This is the query generated by the English dialect
62 Expect(tmpQuery.query.body)
63 .to.equal('Here is a Animal.');
64 }
65 );
66 test
67 (
68 'Read Query',
69 function()
70 {
71 var tmpQuery = libFoxHound.new(libFable).setScope('Animal');
72 // Build the query
73 tmpQuery.buildReadQuery();
74 // This is the query generated by the English dialect
75 Expect(tmpQuery.query.body)
76 .to.equal('Please give me all your Animal records. Thanks.');
77 }
78 );
79 test
80 (
81 'Complex Read Query',
82 function()
83 {
84 var tmpQuery = libFoxHound.new(libFable)
85 .setDialect('English')
86 .setScope('Animal')
87 .setCap(10)
88 .setBegin(0)
89 .setDataElements('Name')
90 .setSort()
91 .setFilter({Column:'Name',Operator:'EQ',Value:'William'});
92 // Build the query
93 tmpQuery.buildReadQuery();
94 // This is the query generated by the English dialect
95 Expect(tmpQuery.query.body)
96 .to.equal('Please give me all your Animal records. Thanks.');
97 }
98 );
99 test
100 (
101 'Complex Alternate Read Query',
102 function()
103 {
104 var tmpQuery = libFoxHound.new(libFable)
105 .setDialect('English')
106 .setScope('Animal')
107 .setCap(10)
108 .setBegin(0)
109 .setDataElements(['Name', 'Age'])
110 .setSort({Column:'Age',Direction:'Ascending'})
111 .setFilter();
112 // Build the query
113 tmpQuery.buildReadQuery();
114 // This is the query generated by the English dialect
115 Expect(tmpQuery.query.body)
116 .to.equal('Please give me all your Animal records. Thanks.');
117 }
118 );
119 test
120 (
121 'Complex Alternate Read Query 2',
122 function()
123 {
124 var tmpQuery = libFoxHound.new(libFable)
125 .setDialect('English')
126 .setScope('Animal')
127 .setCap(10)
128 .setBegin(0)
129 .setDataElements(['Name', 'Age'])
130 .setSort([{Column:'Name',Direction:'Ascending'},{Column:'Age',Direction:'Ascending'}])
131 .setFilter([{Column:'Name',Operator:'EQ',Value:'Janet'}]);
132
133 // Build the query
134 tmpQuery.buildReadQuery();
135 // This is the query generated by the English dialect
136
137 Expect(tmpQuery.query.body)
138 .to.equal('Please give me all your Animal records. Thanks.');
139 }
140 );
141 test
142 (
143 'Complex Read Query with Logging',
144 function()
145 {
146 var tmpQuery = libFoxHound.new(libFable)
147 .setLogLevel(5)
148 .setDialect('English')
149 .setScope('Animal')
150 .setCap(10)
151 .setBegin(0)
152 .setDataElements('Name')
153 .setSort('Age')
154 .setFilter([{Column:'Name',Operator:'EQ',Value:'Janet'}]);
155
156 // Build the query
157 tmpQuery.buildReadQuery();
158 // This is the query generated by the English dialect
159 Expect(tmpQuery.query.body)
160 .to.equal('Please give me all your Animal records. Thanks.');
161
162 // Now clone it
163 var tmpQueryCopy = tmpQuery.clone();
164 }
165 );
166 test
167 (
168 'Update Query',
169 function()
170 {
171 var tmpQuery = libFoxHound.new(libFable).setDialect('English').setScope('Animal');
172
173 // Build the query
174 tmpQuery.buildUpdateQuery();
175 // This is the query generated by the English dialect
176 Expect(tmpQuery.query.body)
177 .to.equal('I am changing your Animal.');
178 }
179 );
180 test
181 (
182 'Delete Query',
183 function()
184 {
185 var tmpQuery = libFoxHound.new(libFable).setDialect('English').setScope('Animal');
186
187 // Build the query
188 tmpQuery.buildDeleteQuery();
189 // This is the query generated by the English dialect
190 Expect(tmpQuery.query.body)
191 .to.equal('I am deleting your Animal.');
192 }
193 );
194 test
195 (
196 'Count Query',
197 function()
198 {
199 var tmpQuery = libFoxHound.new(libFable).setDialect('English').setScope('Animal');
200
201 // Build the query
202 tmpQuery.buildCountQuery();
203 // This is the query generated by the English dialect
204 Expect(tmpQuery.query.body)
205 .to.equal('Count your Animal.');
206 }
207 );
208 }
209 );
210 }
211);
\No newline at end of file