-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
93 lines (88 loc) · 3.35 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var squel = require('squel');
var assert = require('assert');
var selectTop = require('./index').selectTop;
describe('TopStartAtBlock', function() {
describe('#_sanitizeTop', function() {
var block = new squel.cls.TopStartAtBlock();
it('should parse numerics', function() {
assert.equal(10, block._sanitizeTop('10'));
assert.equal(1, block._sanitizeTop('1'));
assert.equal(42, block._sanitizeTop('42'));
});
it('should return "ALL"', function() {
assert.equal('ALL', block._sanitizeTop('all'));
assert.equal('ALL', block._sanitizeTop('ALL'));
assert.equal('ALL', block._sanitizeTop('ALl'));
});
it('should throw error', function() {
var sanitize = block._sanitizeTop;
assert.throws(sanitize.bind(block, null), Error);
assert.throws(sanitize.bind(block, 'foobar'), Error);
assert.doesNotThrow(sanitize.bind(block, 3));
assert.throws(sanitize.bind(block, -1), Error);
});
});
describe('#_sanitizeStartAt', function() {
var block = new squel.cls.TopStartAtBlock();
it('should parse numerics', function() {
assert.equal(10, block._sanitizeStartAt('10'));
assert.equal(1, block._sanitizeStartAt('1'));
assert.equal(42, block._sanitizeStartAt('42'));
});
it('should throw error', function() {
var sanitize = block._sanitizeStartAt;
assert.throws(sanitize.bind(block, null), Error);
assert.throws(sanitize.bind(block, 'bizbang'), Error);
assert.doesNotThrow(sanitize.bind(block, 3), Error);
assert.throws(sanitize.bind(block, -1), Error);
});
});
});
describe('select', function() {
it('should return "SELECT * FROM test"', function() {
var query = selectTop().from('test').toString();
assert.equal('SELECT * FROM test', query);
});
describe('#first', function() {
it('should return "SELECT FIRST * FROM test"', function() {
var query = selectTop().first().from('test').toString();
assert.equal('SELECT FIRST * FROM test', query);
});
it('should throw an error becaue of combination of TOP/START AT with FIRST', function() {
var func1 = selectTop().top(10).first;
var func2 = selectTop().top(10).startAt(2).first;
assert.throws(func1, Error);
assert.throws(func2, Error);
});
});
describe('#top', function() {
it('should throw Error because of present FIRST', function() {
var block = new squel.cls.TopStartAtBlock();
block.first();
assert.throws(block.top.bind(block, '10'), Error);
});
it('should return "SELECT TOP 2 * FROM test"', function() {
var query = squel.selectTop().top('2').from('test').toString();
assert.equal('SELECT TOP 2 * FROM test', query);
});
it('should return "SELECT TOP ALL * FROM test"', function() {
var query = squel.selectTop().top('ALL').from('test').toString();
assert.equal('SELECT TOP ALL * FROM test', query);
});
describe('#start at', function() {
it('should return "SELECT TOP 10 START AT 1 * FROM test"', function() {
var query = squel.selectTop().top(10).startAt(1).from('test').toString();
assert.equal('SELECT TOP 10 START AT 1 * FROM test', query);
});
it('should throw Error because of missing TOP', function() {
var func = selectTop().startAt(3).toString;
assert.throws(func, Error);
});
it('should throw Error because of present FIRST', function() {
var block = new squel.cls.TopStartAtBlock();
block.first();
assert.throws(block.startAt.bind(block, '50'), Error);
});
});
});
});