Repository navigation
Expand file tree
/
Copy pathsqlite_spec.js
More file actions
138 lines (112 loc) · 3.56 KB
/
Copy pathsqlite_spec.js
File metadata and controls
138 lines (112 loc) · 3.56 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
var _ = require('lodash');
var should = require('should');
var Driver = require('../../../lib/Drivers/DML/sqlite').Driver;
var helper = require('../../support/spec_helper');
var common = require('../../common');
if (common.protocol() != "sqlite") return;
describe("Sqlite driver", function() {
describe("#valueToProperty", function () {
var driver = null;
before(function () {
driver = new Driver({}, {}, {});
});
describe("numbers", function () {
describe("floats", function () {
function valueToProperty (value) {
return driver.valueToProperty(value, { type: 'number' });
}
it("should pass on empty string", function () {
should.strictEqual(valueToProperty(''), '');
});
it("should pass on text", function () {
should.strictEqual(valueToProperty('fff'), 'fff');
});
it("should pass on numbers", function () {
should.strictEqual(valueToProperty(1.2), 1.2);
});
it("should parse numbers in strings", function () {
should.strictEqual(valueToProperty('1.2'), 1.2);
should.strictEqual(valueToProperty('1.200 '), 1.2);
});
it("should support non finite numbers", function () {
should.strictEqual(valueToProperty( 'Infinity'), Infinity);
should.strictEqual(valueToProperty('-Infinity'), -Infinity);
should.strictEqual(isNaN(valueToProperty('NaN')), true);
});
});
describe("integers", function () {
function valueToProperty (value) {
return driver.valueToProperty(value, { type: 'integer' });
}
it("should pass on empty string", function () {
should.strictEqual(valueToProperty(''), '');
});
it("should pass on text", function () {
should.strictEqual(valueToProperty('fff'), 'fff');
});
it("should pass on non finite numbers as text", function () {
should.strictEqual(valueToProperty( 'Infinity'), 'Infinity');
should.strictEqual(valueToProperty('-Infinity'), '-Infinity');
should.strictEqual(valueToProperty('NaN'), 'NaN');
});
it("should pass on numbers", function () {
should.strictEqual(valueToProperty(1.2), 1.2);
});
it("should parse integers in strings", function () {
should.strictEqual(valueToProperty('1.2'), 1);
should.strictEqual(valueToProperty('1.200 '), 1);
});
});
});
});
describe("db", function () {
var db = null;
var Person = null;
before(function (done) {
helper.connect(function (connection) {
db = connection;
Person = db.define("person", {
name: String
});
return helper.dropSync([ Person ], done);
});
});
after(function () {
return db.close();
});
describe("#clear", function () {
beforeEach(function (done) {
Person.create([{ name: 'John' }, { name: 'Jane' }], function (err) {
Person.count(function (err, count) {
should.not.exist(err);
should.equal(count, 2);
done();
});
});
});
it("should drop all items", function (done) {
Person.clear(function (err) {
should.not.exist(err);
Person.count(function (err, count) {
should.not.exist(err);
should.equal(count, 0);
done();
});
});
});
it("should reset id sequence", function (done) {
Person.clear(function (err) {
should.not.exist(err);
db.driver.execQuery("SELECT * FROM ?? WHERE ?? = ?", ['sqlite_sequence', 'name', Person.table], function (err, data) {
should.not.exist(err);
Person.create({ name: 'Bob' }, function (err, person) {
should.not.exist(err);
should.equal(person.id, 1);
done();
});
});
});
});
});
});
});