1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var Chai = require('chai');
|
10 | var Expect = Chai.expect;
|
11 | var Assert = Chai.assert;
|
12 |
|
13 | var libFable = require('fable');
|
14 | var libFoxHound = require('../source/FoxHound.js');
|
15 |
|
16 | suite
|
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 |
|
60 | tmpQuery.buildCreateQuery();
|
61 |
|
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 |
|
73 | tmpQuery.buildReadQuery();
|
74 |
|
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 |
|
93 | tmpQuery.buildReadQuery();
|
94 |
|
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 |
|
113 | tmpQuery.buildReadQuery();
|
114 |
|
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 |
|
134 | tmpQuery.buildReadQuery();
|
135 |
|
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 |
|
157 | tmpQuery.buildReadQuery();
|
158 |
|
159 | Expect(tmpQuery.query.body)
|
160 | .to.equal('Please give me all your Animal records. Thanks.');
|
161 |
|
162 |
|
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 |
|
174 | tmpQuery.buildUpdateQuery();
|
175 |
|
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 |
|
188 | tmpQuery.buildDeleteQuery();
|
189 |
|
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 |
|
202 | tmpQuery.buildCountQuery();
|
203 |
|
204 | Expect(tmpQuery.query.body)
|
205 | .to.equal('Count your Animal.');
|
206 | }
|
207 | );
|
208 | }
|
209 | );
|
210 | }
|
211 | ); |
\ | No newline at end of file |