Skip to content

Commit 0a9214a

Browse files
committed
Refactor varchar2 tests
1 parent 12d78d2 commit 0a9214a

8 files changed

+879
-892
lines changed

test/dataTypeAssist.js

Lines changed: 479 additions & 137 deletions
Large diffs are not rendered by default.

test/dataTypeDate.js

Lines changed: 30 additions & 305 deletions
Original file line numberDiff line numberDiff line change
@@ -64,39 +64,12 @@ describe('32. dataTypeDate.js', function() {
6464
});
6565
})
6666

67-
describe('32.1 Insert JavaScript Date data', function() {
67+
describe('32.1 Testing JavaScript Date data', function() {
6868
var dates = assist.data.dates;
69-
var numRows = 3; // number of rows to return from each call to getRows()
7069

71-
before(function(done) {
72-
async.series([
73-
function createTable(callback) {
74-
var sqlCreate = assist.sqlCreateTable(tableName);
75-
connection.execute(
76-
sqlCreate,
77-
function(err) {
78-
should.not.exist(err);
79-
callback();
80-
}
81-
);
82-
},
83-
function insertDataJS(callback) {
84-
async.forEach(dates, function(date, cb) {
85-
connection.execute(
86-
"INSERT INTO " + tableName + " VALUES(:no, :bindValue)",
87-
{ no: dates.indexOf(date), bindValue: date },
88-
function(err) {
89-
should.not.exist(err);
90-
cb();
91-
}
92-
);
93-
}, function(err) {
94-
should.not.exist(err);
95-
callback();
96-
});
97-
}
98-
], done);
99-
}) // before
70+
before('create table, insert data',function(done) {
71+
assist.setUp(connection, tableName, dates, done);
72+
})
10073

10174
after(function(done) {
10275
connection.execute(
@@ -106,135 +79,34 @@ describe('32. dataTypeDate.js', function() {
10679
done();
10780
}
10881
);
109-
}) // after
82+
})
11083

11184
it('32.1.1 works well with SELECT query', function(done) {
112-
async.forEach(dates, function(date, cb) {
113-
var bv = dates.indexOf(date);
114-
115-
connection.execute(
116-
"SELECT content FROM " + tableName + " WHERE num = :no",
117-
{ no: bv },
118-
{ outFormat: oracledb.OBJECT },
119-
function(err, result) {
120-
should.not.exist(err);
121-
result.rows[0].CONTENT.toUTCString().should.eql(dates[bv].toUTCString());
122-
cb();
123-
}
124-
);
125-
}, function(err) {
126-
should.not.exist(err);
127-
done();
128-
});
129-
}) // 32.1.1
85+
assist.dataTypeSupport(connection, tableName, dates, done);
86+
})
13087

13188
it('32.1.2 works well with result set', function(done) {
132-
connection.execute(
133-
"SELECT * FROM " + tableName,
134-
[],
135-
{ resultSet: true, outFormat: oracledb.OBJECT },
136-
function(err, result) {
137-
should.not.exist(err);
138-
(result.resultSet.metaData[0]).name.should.eql('NUM');
139-
(result.resultSet.metaData[1]).name.should.eql('CONTENT');
140-
fetchRowsFromRS(result.resultSet, dates, done);
141-
}
142-
);
143-
}) // 32.1.2
89+
assist.verifyResultSet(connection, tableName, dates, done);
90+
})
14491

14592
it.skip('32.1.3 works well with REF Cursor', function(done) {
146-
async.series([
147-
function createProcedure(callback) {
148-
var proc = assist.sqlCreateProcedure(tableName);
149-
connection.execute(
150-
proc,
151-
function(err) {
152-
should.not.exist(err);
153-
callback();
154-
}
155-
);
156-
},
157-
function verifyRefCursor(callback) {
158-
connection.execute(
159-
"BEGIN testproc(:o); END;",
160-
[
161-
{ type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
162-
],
163-
function(err, result) {
164-
should.not.exist(err);
165-
console.log(result.outBinds.o);
166-
callback();
167-
// fetchRowsFromRS(result.outBinds.o, dates, callback);
168-
}
169-
);
170-
},
171-
function dropProcedure(callback) {
172-
connection.execute(
173-
"DROP PROCEDURE testproc",
174-
function(err) {
175-
should.not.exist(err);
176-
callback();
177-
}
178-
);
179-
}
180-
], done);
181-
}) // 32.1.3
182-
183-
function fetchRowsFromRS(rs, array, cb)
184-
{
185-
rs.getRows(numRows, function(err, rows) {
186-
should.not.exist(err);
187-
if(rows.length > 0) {
188-
for(var i = 0; i < rows.length; i++) {
189-
(rows[i].CONTENT.toUTCString()).should.eql(array[ (rows[i].NUM) ].toUTCString());
190-
return fetchRowsFromRS(rs, array, cb);
191-
}
192-
} else {
193-
rs.close( function(err) {
194-
should.not.exist(err);
195-
cb();
196-
});
197-
}
198-
});
199-
}
93+
assist.verifyRefCursor(connection, tableName, dates, done);
94+
})
20095

20196
}) // 32.1 suite
20297

203-
describe('32.2 insert SQL Date data', function(done) {
98+
describe('32.2 stores null value correctly', function() {
99+
it('32.2.1 testing Null, Empty string and Undefined', function(done) {
100+
assist.verifyNullValues(connection, tableName, done);
101+
})
102+
})
103+
104+
describe('32.3 insert SQL Date data', function(done) {
204105
var dates = assist.DATE_STRINGS;
205106

206107
before(function(done) {
207-
async.series([
208-
function createTable(callback) {
209-
var sqlCreate = assist.sqlCreateTable(tableName);
210-
connection.execute(
211-
sqlCreate,
212-
function(err) {
213-
should.not.exist(err);
214-
callback();
215-
}
216-
);
217-
},
218-
function insertDataSQL(callback) {
219-
async.forEach(dates, function(date, cb) {
220-
var sql = "INSERT INTO " + tableName + " VALUES(:no, " + date + " )";
221-
var bv = dates.indexOf(date);
222-
223-
connection.execute(
224-
sql,
225-
{ no: bv },
226-
function(err) {
227-
should.not.exist(err);
228-
cb();
229-
}
230-
);
231-
}, function(err) {
232-
should.not.exist(err);
233-
callback();
234-
});
235-
}
236-
], done);
237-
}) // before
108+
assist.setUp4sql(connection, tableName, dates, done);
109+
})
238110

239111
after(function(done) {
240112
connection.execute(
@@ -244,179 +116,32 @@ describe('32. dataTypeDate.js', function() {
244116
done();
245117
}
246118
);
247-
}) // after
119+
})
120+
121+
it('32.3.1 SELECT query - original data', function(done) {
122+
assist.selectOriginalData(connection, tableName, dates, done);
123+
})
248124

249-
it('32.2.1 works well with SELECT query', function(done) {
125+
it('32.3.2 SELECT query - formatted data for comparison', function(done) {
250126
async.forEach(dates, function(date, cb) {
251127
var bv = dates.indexOf(date);
252128
connection.execute(
253-
"SELECT content FROM " + tableName + " WHERE num = :no",
129+
"SELECT num, TO_CHAR(content, 'DD-MM-YYYY') AS TS_DATA FROM " + tableName + " WHERE num = :no",
254130
{ no: bv },
255131
{ outFormat: oracledb.OBJECT },
256132
function(err, result) {
257133
should.not.exist(err);
258-
(result.rows[0].CONTENT.toUTCString()).should.equal(assist.content.dates[bv]);
134+
// console.log(result.rows);
135+
(result.rows[0].TS_DATA).should.equal(assist.content.dates[bv]);
259136
cb();
260137
}
261138
);
262139
}, function(err) {
263140
should.not.exist(err);
264141
done();
265142
});
266-
}) // 32.2.1
267-
268-
it('32.2.2 works well with result set', function(done) {
269-
connection.execute(
270-
"SELECT * FROM " + tableName,
271-
[],
272-
{ resultSet: true, outFormat: oracledb.OBJECT },
273-
function(err, result) {
274-
should.not.exist(err);
275-
(result.resultSet.metaData[0]).name.should.eql('NUM');
276-
(result.resultSet.metaData[1]).name.should.eql('CONTENT');
277-
var array = assist.content.dates;
278-
fetchOneRowFromRS(result.resultSet, array, done);
279-
}
280-
);
281-
}) // 32.2.2
282-
283-
it.skip('32.2.3 works well with REF Cursor', function(done) {
284-
async.series([
285-
function createProcedure(callback) {
286-
var proc = assist.sqlCreateProcedure(tableName);
287-
connection.execute(
288-
proc,
289-
function(err) {
290-
should.not.exist(err);
291-
callback();
292-
}
293-
);
294-
},
295-
function verifyRefCursor(callback) {
296-
connection.execute(
297-
"BEGIN testproc(:o); END;",
298-
[
299-
{ type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
300-
],
301-
function(err, result) {
302-
should.not.exist(err);
303-
console.log(result.outBinds.o);
304-
callback();
305-
// fetchRowsFromRS(result.outBinds.o, dates, callback);
306-
}
307-
);
308-
},
309-
function dropProcedure(callback) {
310-
connection.execute(
311-
"DROP PROCEDURE testproc",
312-
function(err) {
313-
should.not.exist(err);
314-
callback();
315-
}
316-
);
317-
}
318-
], done);
319-
}) // 32.2.3
320-
321-
function fetchOneRowFromRS(rs, array, cb)
322-
{
323-
rs.getRow( function(err, row) {
324-
should.not.exist(err);
325-
if(row) {
326-
(row.CONTENT.toUTCString()).should.eql(array[row.NUM]);
327-
return fetchOneRowFromRS(rs, array, cb);
328-
} else {
329-
rs.close( function(err) {
330-
should.not.exist(err);
331-
cb();
332-
});
333-
}
334-
});
335-
}
336-
337-
}) // 32.2 suite
338-
339-
describe('32.3 stores null value correctly', function(done) {
340-
beforeEach(function(done) {
341-
var sqlCreate = assist.sqlCreateTable(tableName);
342-
connection.execute(
343-
sqlCreate,
344-
function(err) {
345-
should.not.exist(err);
346-
done();
347-
}
348-
);
349-
}) // before
350-
351-
afterEach(function(done) {
352-
connection.execute(
353-
"DROP table " + tableName,
354-
function(err) {
355-
should.not.exist(err);
356-
done();
357-
}
358-
);
359-
}) // after
360-
361-
var sqlInsert = "INSERT INTO " + tableName + " VALUES(1, :bindValue)";
362-
363-
it('32.3.1 JS null - empty string', function(done) {
364-
connection.execute(
365-
sqlInsert,
366-
{ bindValue: '' },
367-
function(err) {
368-
should.not.exist(err);
369-
verifyNull(done);
370-
}
371-
);
372143
})
373144

374-
it('32.3.2 JS null - null keyword', function(done) {
375-
connection.execute(
376-
sqlInsert,
377-
{ bindValue: null },
378-
function(err) {
379-
should.not.exist(err);
380-
verifyNull(done);
381-
}
382-
);
383-
})
384-
385-
it('32.3.3 JS null - undefined', function(done) {
386-
var foobar; // undefined value
387-
connection.execute(
388-
sqlInsert,
389-
{ bindValue: foobar },
390-
function(err) {
391-
should.not.exist(err);
392-
verifyNull(done);
393-
}
394-
);
395-
})
396-
397-
it('32.3.4 SQL null keyword', function(done) {
398-
connection.execute(
399-
"INSERT INTO " + tableName + " VALUES(1, NULL)",
400-
function(err) {
401-
should.not.exist(err);
402-
verifyNull(done);
403-
}
404-
);
405-
})
406-
407-
function verifyNull(cb)
408-
{
409-
connection.execute(
410-
"SELECT content FROM " + tableName + " WHERE num = 1",
411-
function(err, result) {
412-
should.not.exist(err);
413-
// console.log(result);
414-
result.rows.should.eql([ [null] ]);
415-
cb();
416-
}
417-
);
418-
}
145+
}) // end of 32.3 suite
419146

420-
}) // end of 32.3 suite
421-
422147
})

0 commit comments

Comments
 (0)