sorla-db 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Brainstorming.md +22 -0
- package/LICENSE +21 -0
- package/README.md +31 -0
- package/debug-not.js +24 -0
- package/dist/sorla.min.js +1 -0
- package/example/simple_data_example.html +196 -0
- package/index.js +62 -0
- package/package.json +42 -0
- package/src/collections/collection.js +47 -0
- package/src/dbs/database.js +72 -0
- package/src/documents/cursor.js +144 -0
- package/src/documents/document.js +88 -0
- package/src/helper.js +41 -0
- package/src/query_language/index.js +0 -0
- package/src/query_language/manipulation.js +161 -0
- package/src/query_language/operators.js +289 -0
- package/src/query_language/query.js +104 -0
- package/src/sorla.js +123 -0
- package/src/utils.js +41 -0
- package/test/feature_collection.test.js +73 -0
- package/test/feature_collection_queries.test.js +269 -0
- package/test/unit_database.test.js +36 -0
- package/test/unit_document_test.js +39 -0
- package/test/unit_sorla.test.js +42 -0
- package/test/unit_test.test.js +25 -0
- package/webpack.config.js +11 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const chai = require('chai')
|
|
2
|
+
const expect = chai.expect
|
|
3
|
+
const faker = require('faker')
|
|
4
|
+
const sorla = require('../src/sorla.js')
|
|
5
|
+
|
|
6
|
+
describe('SORLA Collection Feature Test', () => {
|
|
7
|
+
beforeAll(() => {
|
|
8
|
+
this.srla = new sorla();
|
|
9
|
+
this.dbname = faker.random.word();
|
|
10
|
+
this.srla.createDb(this.dbname);
|
|
11
|
+
this.srla.useDb(this.dbname);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
this.collectionName = faker.random.word();
|
|
16
|
+
this.srla.db.createCollection(this.collectionName);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('Create a single document inside of a collection and check by length', () => {
|
|
20
|
+
this.srla.db[this.collectionName].insertOne({name: 'Anderson'});
|
|
21
|
+
expect(this.srla.db[this.collectionName].count()).to.equal(1);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('create multiple documents and check by length', () => {
|
|
25
|
+
this.srla.db[this.collectionName].insertMany([
|
|
26
|
+
{name: 'Anderson'},
|
|
27
|
+
{name: 'Arruda'},
|
|
28
|
+
{name: 'Sorla'}
|
|
29
|
+
]);
|
|
30
|
+
expect(this.srla.db[this.collectionName].count()).to.equal(3);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('create a document with prohibited character $', () => {
|
|
34
|
+
expect(() => this.srla.db[this.collectionName].insertOne({name: 'Anderson', $test: '123'})).to.throw();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('create a document with prohibited character .', () => {
|
|
38
|
+
expect(() => this.srla.db[this.collectionName].insertOne({"name.name": 'Anderson', test: {test: '123'}})).to.throw();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('create a document with prohibited character . inside of an array', () => {
|
|
42
|
+
expect(() => this.srla.db[this.collectionName].insertOne({name: 'Anderson', test: [{"test.number": '123'}, {"test.number": '123'}]})).to.throw();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('create a document with prohibited character . inside of an object', () => {
|
|
46
|
+
expect(() => this.srla.db[this.collectionName].insertOne({name: 'Anderson', test: {"test.number": '123'}})).to.throw();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/*it('get a document by his subfield using test.inscription', () => {
|
|
50
|
+
this.srla.db[this.collectionName].insertMany([
|
|
51
|
+
{name: 'Anderson', test: {inscription: 123}},
|
|
52
|
+
{name: 'Arruda', test: {inscription: 321}},
|
|
53
|
+
{name: 'Sorla', test: {inscription: 213}}
|
|
54
|
+
]);
|
|
55
|
+
expect(this.srla.db[this.collectionName].findOne({'test.inscription': 123}).length).to.equal(1);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('Try to create a document without beeing a valid object', () => {
|
|
59
|
+
expect(() => this.srla.db[this.collectionName].insertOne('Anderson')).to.throw();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('Try to create a document with array', () => {
|
|
63
|
+
expect(() => this.srla.db[this.collectionName].insertOne(['Anderson'])).to.throw();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('Try to create many documents without beeing a valid array', () => {
|
|
67
|
+
expect(() => this.srla.db[this.collectionName].insertMany('Anderson')).to.throw();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('Try to create many documents without having valid object', () => {
|
|
71
|
+
expect(() => this.srla.db[this.collectionName].insertMany([{test: '123', }, 'anderson'])).to.throw();
|
|
72
|
+
});*/
|
|
73
|
+
});
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
const chai = require('chai')
|
|
2
|
+
const expect = chai.expect
|
|
3
|
+
const faker = require('faker')
|
|
4
|
+
const sorla = require('../src/sorla.js')
|
|
5
|
+
const helper = require('../src/helper.js')
|
|
6
|
+
|
|
7
|
+
describe('SORLA Collection Queries Feature Test', () => {
|
|
8
|
+
beforeAll(() => {
|
|
9
|
+
this.srla = new sorla();
|
|
10
|
+
this.dbname = faker.random.word();
|
|
11
|
+
this.srla.createDb(this.dbname);
|
|
12
|
+
this.srla.useDb(this.dbname);
|
|
13
|
+
this.collectionName = faker.random.word();
|
|
14
|
+
this.srla.db.createCollection(this.collectionName);
|
|
15
|
+
this.objects = helper.createFakeCollection(this.srla, this.collectionName, 30);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('Test if the first document in the collection is the same first document on the objects array', () => {
|
|
19
|
+
const firstDoc = this.srla.db[this.collectionName].findOne({}, { _id: 0 });
|
|
20
|
+
const firstObj = this.objects[0];
|
|
21
|
+
expect(firstDoc).to.deep.equal(firstObj);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('Takes the data field name from the document inside the collection', () => {
|
|
25
|
+
const firstDoc = this.srla.db[this.collectionName].findOne({}, { _id: 0 });
|
|
26
|
+
const firstObj = this.objects[0];
|
|
27
|
+
expect(firstDoc.name).to.be.a('string').equal(firstObj.name);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('Takes the data field email from the document inside the collection', () => {
|
|
31
|
+
const firstDoc = this.srla.db[this.collectionName].findOne({}, { _id: 0 });
|
|
32
|
+
const firstObj = this.objects[0];
|
|
33
|
+
expect(firstDoc.email).to.be.a('string').equal(firstObj.email);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('Takes the data field age from the document inside the collection', () => {
|
|
37
|
+
const firstDoc = this.srla.db[this.collectionName].findOne({}, { _id: 0 });
|
|
38
|
+
const firstObj = this.objects[0];
|
|
39
|
+
expect(firstDoc.age).to.be.a('number').equal(firstObj.age);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('Creates a few documents and search for one of them', () => {
|
|
43
|
+
const [item1,] = helper.getRandomComparisonData(this.objects);
|
|
44
|
+
const doc = this.srla.db[this.collectionName].findOne({ uuid: item1.uuid }, { _id: 0 });
|
|
45
|
+
expect(doc).to.deep.equal(item1);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('Creates a few documents and search for some of them', () => {
|
|
49
|
+
const [item1, item2] = helper.getRandomComparisonData(this.objects);
|
|
50
|
+
const docs = this.srla.db[this.collectionName].find({
|
|
51
|
+
$or: [
|
|
52
|
+
{ uuid: item1.uuid },
|
|
53
|
+
{ uuid: item2.uuid }
|
|
54
|
+
]
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
expect(docs.length).to.be.equal(2);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('Creates a few documents and search using not', () => {
|
|
61
|
+
const [item1] = helper.getRandomComparisonData(this.objects);
|
|
62
|
+
const docs = this.srla.db[this.collectionName].find(
|
|
63
|
+
{
|
|
64
|
+
uuid: {
|
|
65
|
+
$not: {
|
|
66
|
+
$eq: item1.uuid
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
expect(docs.length).to.be.equal(this.objects.length - 1);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('Creates a few documents and search using not with more than one expression', () => {
|
|
76
|
+
const [item1,] = helper.getRandomComparisonData(this.objects);
|
|
77
|
+
const docs = this.srla.db[this.collectionName].find(
|
|
78
|
+
{
|
|
79
|
+
age: {
|
|
80
|
+
$not: {
|
|
81
|
+
$eq: item1.age,
|
|
82
|
+
$gt: 18
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
expect(docs.length).to.be.equal(this.objects.length - 1);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('Creates a few documents and search it using nor', () => {
|
|
92
|
+
const [item1,] = helper.getRandomComparisonData(this.objects);
|
|
93
|
+
const docs = this.srla.db[this.collectionName].findOne({
|
|
94
|
+
$nor: [
|
|
95
|
+
{name: item1.name},
|
|
96
|
+
{age: item1.age}
|
|
97
|
+
]
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
expect(docs.name).to.not.be.equal(item1.name);
|
|
101
|
+
expect(docs.age).to.not.be.equal(item1.age);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('Creates a few documents and search it using nor with more than one expression', () => {
|
|
105
|
+
const [item1, item2] = helper.getRandomComparisonData(this.objects);
|
|
106
|
+
const docs = this.srla.db[this.collectionName].find({
|
|
107
|
+
$nor: [
|
|
108
|
+
{name: item1.name},
|
|
109
|
+
{age: item1.age},
|
|
110
|
+
{name: item2.name},
|
|
111
|
+
{age: item2.age}
|
|
112
|
+
]
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
expect(docs.length).to.be.equal(this.objects.length - 2);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('Test sort number in ascending order', () => {
|
|
119
|
+
this.srla.db.createCollection('sortNumberAsc');
|
|
120
|
+
this.srla.db.sortNumberAsc.insertMany([
|
|
121
|
+
{
|
|
122
|
+
name: 'A',
|
|
123
|
+
age: 20
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: 'B',
|
|
127
|
+
age: 10
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'C',
|
|
131
|
+
age: 30
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: 'A',
|
|
135
|
+
age: 3
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: 'B',
|
|
139
|
+
age: 5
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: 'C',
|
|
143
|
+
age: 1
|
|
144
|
+
},
|
|
145
|
+
]);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('Test sort number in descending order', () => {
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('Test sort string in ascending order', () => {
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('Test sort string in descending order', () => {
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('Test sort date in ascending order', () => {
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('Test sort date in descending order', () => {
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('Test sort boolean in ascending order', () => {
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('Test sort boolean in descending order', () => {
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('Test equal comparison', () => {
|
|
170
|
+
const [item1,] = helper.getRandomComparisonData(this.objects);
|
|
171
|
+
const doc = this.srla.db[this.collectionName].findOne({ uuid: item1.uuid }, { _id: 0 });
|
|
172
|
+
expect(doc).to.deep.equal(item1);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('Test not equal comparison', () => {
|
|
176
|
+
const [item1,] = helper.getRandomComparisonData(this.objects);
|
|
177
|
+
const docs = this.srla.db[this.collectionName].find({
|
|
178
|
+
uuid: { $ne: item1.uuid }
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
expect(docs.length).to.be.equal(this.objects.length - 1);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('Test greater than comparison', () => {
|
|
185
|
+
const [item1,] = helper.getRandomComparisonData(this.objects);
|
|
186
|
+
const docs = this.srla.db[this.collectionName].find({
|
|
187
|
+
age: { $gt: item1.age }
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
countAges = this.objects.filter(obj => obj.age > item1.age).length;
|
|
191
|
+
expect(docs.length).to.be.equal(countAges);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('Test greater than or equal comparison', () => {
|
|
195
|
+
const [item1,] = helper.getRandomComparisonData(this.objects);
|
|
196
|
+
const docs = this.srla.db[this.collectionName].find({
|
|
197
|
+
age: { $gte: item1.age }
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
countAges = this.objects.filter(obj => obj.age >= item1.age).length;
|
|
201
|
+
expect(docs.length).to.be.equal(countAges);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('Test less than comparison', () => {
|
|
205
|
+
const [item1,] = helper.getRandomComparisonData(this.objects);
|
|
206
|
+
const docs = this.srla.db[this.collectionName].find({
|
|
207
|
+
age: { $lt: item1.age }
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
countAges = this.objects.filter(obj => obj.age < item1.age).length;
|
|
211
|
+
expect(docs.length).to.be.equal(countAges);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('Test less than or equal comparison', () => {
|
|
215
|
+
const [item1,] = helper.getRandomComparisonData(this.objects);
|
|
216
|
+
const docs = this.srla.db[this.collectionName].find({
|
|
217
|
+
age: { $lte: item1.age }
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
countAges = this.objects.filter(obj => obj.age <= item1.age).length;
|
|
221
|
+
expect(docs.length).to.be.equal(countAges);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('Test in comparison', () => {
|
|
225
|
+
const [item1, item2] = helper.getRandomComparisonData(this.objects);
|
|
226
|
+
const docs = this.srla.db[this.collectionName].find({
|
|
227
|
+
age: { $in: [item1.age, item2.age] }
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
countAges = this.objects.filter(obj => obj.age === item1.age || obj.age === item2.age).length;
|
|
231
|
+
expect(docs.length).to.be.equal(countAges);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('Test not in comparison', () => {
|
|
235
|
+
const [item1, item2] = helper.getRandomComparisonData(this.objects);
|
|
236
|
+
const docs = this.srla.db[this.collectionName].find({
|
|
237
|
+
age: { $nin: [item1.age, item2.age] }
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
countAges = this.objects.filter(obj => obj.age !== item1.age && obj.age !== item2.age).length;
|
|
241
|
+
expect(docs.length).to.be.equal(countAges);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('Test mixed comparison with and', () => {
|
|
245
|
+
const [item1,] = helper.getRandomComparisonData(this.objects);
|
|
246
|
+
const docs = this.srla.db[this.collectionName].find({
|
|
247
|
+
$and: [
|
|
248
|
+
{ name: item1.name },
|
|
249
|
+
{ age: item1.age }
|
|
250
|
+
]
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
const filtered = this.objects.filter(obj => obj.name === item1.name && obj.age === item1.age);
|
|
254
|
+
expect(docs.length).to.be.equal(filtered.length);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it('Test mixed comparison with or', () => {
|
|
258
|
+
const [item1, item2] = helper.getRandomComparisonData(this.objects);
|
|
259
|
+
const docs = this.srla.db[this.collectionName].find({
|
|
260
|
+
$or: [
|
|
261
|
+
{ name: item1.name },
|
|
262
|
+
{ age: item2.age }
|
|
263
|
+
]
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
const filtered = this.objects.filter(obj => obj.name === item1.name || obj.age === item2.age);
|
|
267
|
+
expect(docs.length).to.be.equal(filtered.length);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const chai = require('chai')
|
|
2
|
+
const expect = chai.expect
|
|
3
|
+
const faker = require('faker')
|
|
4
|
+
const sorla = require('../src/sorla.js')
|
|
5
|
+
const collection = require('../src/collections/collection.js');
|
|
6
|
+
|
|
7
|
+
describe('SORLA Database Unit Test', () => {
|
|
8
|
+
beforeAll(() => {
|
|
9
|
+
this.srla = new sorla();
|
|
10
|
+
this.dbname = faker.random.word();
|
|
11
|
+
this.srla.createDb(this.dbname);
|
|
12
|
+
this.srla.useDb(this.dbname);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('Should create a new collection with specified name', () => {
|
|
16
|
+
this.srla.db.createCollection('collection1');
|
|
17
|
+
expect(this.srla.db.countCollections()).to.equal(1);
|
|
18
|
+
expect(this.srla.db.collection1).to.not.be.undefined;
|
|
19
|
+
expect(this.srla.db.collection1).to.be.an.instanceof(collection);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('Should create a new collection with specified name, second collection', () => {
|
|
23
|
+
this.srla.db.createCollection('collection2');
|
|
24
|
+
expect(this.srla.db.countCollections()).to.equal(2);
|
|
25
|
+
expect(this.srla.db.collection2).to.not.be.undefined;
|
|
26
|
+
expect(this.srla.db.collection2).to.be.an.instanceof(collection);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('Should return a collection undefined when not exists', () => {
|
|
30
|
+
expect(this.srla.db.collection3).to.be.undefined;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('Should avoid create a collection with name that exists in database class', () => {
|
|
34
|
+
expect(() => this.srla.db.createCollection('_name')).to.throw();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const chai = require('chai');
|
|
2
|
+
const expect = chai.expect;
|
|
3
|
+
const faker = require('faker');
|
|
4
|
+
const documents = require('../src/documents/document.js');
|
|
5
|
+
|
|
6
|
+
describe('testing document capabilities', () => {
|
|
7
|
+
it('checking capabilities of getting a field inside a object', () => {
|
|
8
|
+
const doc = new documents({
|
|
9
|
+
name: 'Anderson',
|
|
10
|
+
test: {
|
|
11
|
+
inscription: 123
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
expect(doc.name).to.equal('Anderson');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('checking capabilities of getting a field inside a object', () => {
|
|
19
|
+
const doc = new documents({
|
|
20
|
+
name: 'Anderson',
|
|
21
|
+
test: {
|
|
22
|
+
inscription: 123
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
expect(doc.test.inscription).to.equal(123);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('checking capabilities of getting a field inside a object', () => {
|
|
30
|
+
const doc = new documents({
|
|
31
|
+
name: 'Anderson',
|
|
32
|
+
test: {
|
|
33
|
+
inscription: 123
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(doc['test.inscription']).to.equal(123);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const chai = require('chai')
|
|
2
|
+
const expect = chai.expect
|
|
3
|
+
const faker = require('faker')
|
|
4
|
+
|
|
5
|
+
const sorla = require('../src/sorla.js')
|
|
6
|
+
|
|
7
|
+
describe('SORLA Unit Test', () => {
|
|
8
|
+
it('Should create a new database with random name', () => {
|
|
9
|
+
const srla = new sorla();
|
|
10
|
+
const dbname = faker.random.word();
|
|
11
|
+
srla.createDb(dbname);
|
|
12
|
+
srla.useDb(dbname);
|
|
13
|
+
|
|
14
|
+
expect(srla.countDb()).to.equal(1);
|
|
15
|
+
expect(srla.dbExists(dbname)).to.equal(true);
|
|
16
|
+
expect(srla.db.name).to.equal(dbname);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('Should not create a new database with the same name', () => {
|
|
20
|
+
const srla = new sorla();
|
|
21
|
+
const dbname = faker.random.word();
|
|
22
|
+
srla.createDb(dbname);
|
|
23
|
+
|
|
24
|
+
expect(srla.createDb(dbname)).to.equal(false);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('Should created more than one database', () => {
|
|
28
|
+
const srla = new sorla();
|
|
29
|
+
for(let i=0; i<2; i++)
|
|
30
|
+
{
|
|
31
|
+
const dbname = faker.random.word();
|
|
32
|
+
srla.createDb(dbname);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
expect(srla.countDb()).to.equal(2);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('Should not have any database created', () => {
|
|
39
|
+
const srla = new sorla();
|
|
40
|
+
expect(srla.countDb()).to.equal(0);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const chai = require('chai');
|
|
2
|
+
const expect = chai.expect;
|
|
3
|
+
|
|
4
|
+
const sorla = require('../src/sorla.js');
|
|
5
|
+
|
|
6
|
+
describe('Sorla Class', () => {
|
|
7
|
+
it('should create a new database', () => {
|
|
8
|
+
const srla = new sorla();
|
|
9
|
+
srla.createDb('test');
|
|
10
|
+
expect(srla.countDb()).to.equal(1);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should not create a new database with the same name', () => {
|
|
14
|
+
const srla = new sorla();
|
|
15
|
+
srla.createDb('test');
|
|
16
|
+
expect(srla.createDb('test')).to.equal(false);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should created a new database and select it', () => {
|
|
20
|
+
const srla = new sorla();
|
|
21
|
+
const dbname = 'test';
|
|
22
|
+
srla.useDb(dbname);
|
|
23
|
+
expect(srla.db.name).to.equal(dbname);
|
|
24
|
+
});
|
|
25
|
+
});
|