-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.test.js
267 lines (228 loc) · 7.16 KB
/
index.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
var expect = require('chai').expect;
var dominoNsf = require('./index');
var domino = dominoNsf();
var db;
var savedDocumentUnid = "";
var doc = {
"Form":"Test",
"Name": "Test",
"date": new Date(0),
"number": 10,
"array": ["a","b","c"]
};
var test_db = {
"database":"nodejs_domino9.nsf",
"title":"Test database"
}
describe('domino-nsf',function() {
before(function() {
domino.createDatabase(test_db,function(error, database) {
if (error) {
console.error(error);
}
db = domino.use(database.database);
});
});
after(function() {
domino.deleteDatabase(test_db,function(error,status) {
if (error) {
console.log("error deleting database,",error);
}
});
domino.termSession();
});
describe('save document',function() {
var savedDocument = {};
before(function(done) {
db.insert(doc,function(err,result) {
if(err) {
done(err);
} else {
savedDocument = result;
savedDocumentUnid = result["@unid"];
done();
}
});
});
it ('should create a document with unid with length of 32', function() {
expect(savedDocument).to.have.property('@unid').with.length(32);
});
it ('should have a number property that equals 10', function() {
expect(savedDocument).to.have.property('number').to.equal(10);
});
it('should have a date property that equals ', function() {
expect(savedDocument).to.have.property('date').to.eql(new Date(0));
});
it('shoud have a Name property that equals "Test"',function() {
expect(savedDocument).to.have.property('Name').to.eql("Test");
});
it('shoud have a array property that equals ["a","b","c"]',function() {
expect(savedDocument).to.have.property('array').to.eql(["a","b","c"]);
});
});
describe('get document fields', function() {
var document = {};
before(function(done) {
db.get(savedDocumentUnid,{fields: ['Name','Number']},function(err,result) {
if (err) {
done(err);
} else {
document = result;
done();
}
});
});
it('shoud have a Name property that equals "Test"',function() {
expect(document).to.have.property('Name').to.eql("Test");
});
it('shoud have not have a date property ',function() {
expect(document).to.not.have.property('date');
});
});
describe('get all document items', function() {
var document = {};
before(function(done) {
db.get(savedDocumentUnid,function(err,result) {
if (err) {
done(err);
} else {
document = result;
done();
}
});
});
it ('should create a document with unid with length of 32', function() {
expect(document).to.have.property('@unid').with.length(32);
});
it ('should have a number property that equals 10', function() {
expect(document).to.have.property('number').to.equal(10);
});
it('should have a date property that equals ', function() {
expect(document).to.have.property('date').to.eql(new Date(0));
});
it('shoud have a Name property that equals "Test"',function() {
expect(document).to.have.property('Name').to.eql("Test");
});
it('shoud have a array property that equals ["a","b","c"]',function() {
expect(document).to.have.property('array').to.eql(["a","b","c"]);
});
});
describe('search database', function() {
var searchResults = [];
before(function(done) {
db.search("SELECT *",function(err,result) {
if (err) {
done(err);
} else {
searchResults = result;
done();
}
});
});
it('expect a list of documents with length of 1',function() {
expect(searchResults).to.have.lengthOf(1);
});
});
describe('open database and get name', function() {
let db = {};
let note = {};
let newNote = {};
const body = "This is a body";
before(function(done) {
domino.sinitThread();
db = domino.openDatabase(test_db.database);
note = db.openNotesNote(savedDocumentUnid);
const header = "Content-Type: application/text";
note.setItemMime("Body",header,body);
note.updateNote();
done();
});
it('should have a mime item body', function() {
expect(note.getItemMime("Body").value).to.be.equal(body);
});
it('should have a name equals ' + test_db.title, function() {
expect(db.getDatabaseName()).to.be.equal(test_db.title);
});
it('should have a note.Name equals to ' + doc.Name, function() {
expect(note.getItemText("Name")).to.be.equal(doc.Name);
});
it('should have a note.Number equals to ' + doc.number, function() {
expect(note.getItemNumber("number")).to.be.equal(doc.number);
});
it ('should return a number value', function() {
expect(note.getItemValue("number")).to.be.equal(doc.number);
});
it ('should return a text value', function() {
expect(note.getItemValue("Name")).to.be.equal(doc.Name);
})
it('should have a note.Date equals to ' + doc.date, function() {
expect(new Date(note.getItemDate("date")).getTime()).to.be.equal(doc.date.getTime());
});
it('should return a date equals to ' + doc.date, function() {
expect(note.getItemValue("date").toString()).to.be.equal(doc.date.toString());
})
it('should create a new note and get a handle', function() {
newNote = db.createNotesNote();
expect(newNote.handle).to.not.equal(0);
});
it('should create a item on newly created note', function() {
newNote.setItemText("test", "test value");
expect(newNote.getItemText("test")).to.be.equal("test value");
});
it('hasItem should return true', function() {
expect(newNote.hasItem("test")).to.be.true;
});
it('deleted item should be empty', function() {
newNote.deleteItem("test");
expect(newNote.getItemText("test")).to.be.equal("");
});
it('should create a number item on newly created note', function() {
newNote.setItemNumber("tall", 33.3);
expect(newNote.getItemNumber("tall")).to.be.equal(33.3);
});
it('should create an array item on newly created note', function() {
var text_list = ["Text1","Text2","Text3"];
newNote.setItemValue("text_list",text_list);
expect(newNote.getItemValue("text_list")).to.deep.equal(text_list);
});
it('should append a value to the array', function() {
let text_list = ["Text1","Text2","Text3"];
let textToAppend = "Text4";
text_list.push(textToAppend);
newNote.appendItemValue("text_list",textToAppend);
expect(newNote.getItemValue("text_list")).to.deep.equal(text_list);
});
it('should create a date item', function() {
let date = new Date();
newNote.setItemDate("date_test",date);
// notes does not save ms in dates, compare the date strings instead.
expect(newNote.getItemDate("date_test").toString()).to.be.equal(date.toString());
})
it('should save the newnote and get the note unid', function() {
newNote.updateNote();
expect(newNote.getUNID()).to.have.lengthOf(32);
});
after(function(done) {
note.close();
db.close();
domino.stermThread();
done();
})
});
describe('delete document', function() {
var deleteResult = {};
before(function(done) {
db.del(savedDocumentUnid,function(err,result) {
if (err) {
done(err);
} else {
deleteResult = result;
done();
}
});
});
it('should return status property that equals "deleted"',function() {
expect(deleteResult).to.have.property('status').to.eql("deleted");
});
});
});