forked from bergur/pg-parameterize
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
75 lines (63 loc) · 2.29 KB
/
test.js
File metadata and controls
75 lines (63 loc) · 2.29 KB
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
'use strict';
const parameterize = require('./index');
const expect = require('chai').expect;
describe('ordinal', function() {
it('should return original string when no ? parameter is found', function() {
const string = 'SELECT * FROM table WHERE field = value';
const res = parameterize.ordinal(string);
expect(res).to.equal(string);
})
it('should replace ? with $1', function() {
const string = 'SELECT * FROM table WHERE field = ?';
const res = parameterize.ordinal(string);
expect(res).to.equal('SELECT * FROM table WHERE field = $1');
})
it('should handle multiple occurances', function() {
const string = 'SELECT * FROM table WHERE field1 = ? OR field2 = ? AND field3 = ?';
const res = parameterize.ordinal(string);
expect(res).to.equal('SELECT * FROM table WHERE field1 = $1 OR field2 = $2 AND field3 = $3');
})
})
describe('flatten', function() {
it('should return empty array when given array is empty', function() {
const arr = [];
const res = parameterize.flatten(arr);
expect(res).to.eql([]);
})
it('should flatten array', function() {
const arr = [
['John','A',1],
['Jane','B',2],
];
const res = parameterize.flatten(arr);
expect(res).to.eql(['John', 'A', 1, 'Jane', 'B', 2]);
})
})
describe('tuple', function() {
it('should return empty string when given array is empty', function() {
const arr = [];
const res = parameterize.tuple(arr);
expect(res).to.eql('');
});
it.skip('should return tuple frome single array', function() {
const arr = ['John','A',1];
const res = parameterize.tuple(arr);
expect(res).to.eql('(?,?,?)');
});
it('should return tuple from array', function() {
const arr = [
['John','A',1],
['Jane','B',2]
];
const res = parameterize.tuple(arr);
expect(res).to.equal('(?,?,?),(?,?,?)');
});
it('should return parameterized tuple from array', function() {
const arr = [
['John','A',1],
['Jane','B',2]
];
const res = parameterize.tuple(arr, true);
expect(res).to.eql('($1,$2,$3),($4,$5,$6)');
});
})