Skip to content

Commit 2850383

Browse files
committed
improved negative ai test
1 parent ab9ebfe commit 2850383

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

test/integration/connection/test-insert-negative-ai.js

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,50 @@ var common = require('../../common');
22
var connection = common.createConnection();
33
var assert = require('assert');
44

5-
// common.useTestDb(connection);
6-
7-
var table = 'insert_negative_ai_test';
8-
var text = ' test test test ';
9-
connection.query([
10-
'CREATE TEMPORARY TABLE `' + table + '` (',
11-
'`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
12-
'`title` varchar(255),',
13-
'PRIMARY KEY (`id`)',
14-
') ENGINE=InnoDB DEFAULT CHARSET=utf8'
15-
].join('\n'));
16-
17-
var result, result2;
18-
connection.query('INSERT INTO ' + table + ' (id, title) values (-999, "' + text + '")', function (err, _result) {
19-
if (err) {
20-
throw err;
21-
}
22-
result = _result;
23-
connection.query('SELECT * FROM ' + table + ' WHERE id = ' + result.insertId, function (err, _result2) {
24-
result2 = _result2;
25-
connection.end();
5+
var testTable = 'neg-ai-test';
6+
var testData = 'test negative ai';
7+
8+
var selectResult, insertResult;
9+
10+
var prepareAndTest = function (cb) {
11+
connection.query(
12+
'CREATE TEMPORARY TABLE `' + testTable + '` (' +
13+
'`id` int(11) signed NOT NULL AUTO_INCREMENT,' +
14+
'`title` varchar(255),' +
15+
'PRIMARY KEY (`id`)' +
16+
') ENGINE=InnoDB DEFAULT CHARSET=utf8', testNegativeAI);
17+
};
18+
19+
var testNegativeAI = function (err) {
20+
assert.ifError(err);
21+
// insert the negative AI
22+
connection.query(
23+
'INSERT INTO `' + testTable + '`' +
24+
' (id, title) values (-999, "' + testData + '")'
25+
, function (err, result) {
26+
27+
assert.ifError(err);
28+
insertResult = result;
29+
30+
// select the row with negative AI
31+
connection.query('SELECT * FROM `' + testTable + '`' +
32+
' WHERE id = ' + result.insertId
33+
,function (err, result_) {
34+
35+
assert.ifError(err);
36+
selectResult = result_;
37+
38+
connection.end();
39+
});
2640
});
27-
});
41+
};
42+
43+
prepareAndTest();
2844

2945
process.on('exit', function () {
30-
assert.strictEqual(result.insertId, 1);
31-
assert.strictEqual(result2.length, 1);
32-
// TODO: type conversions
33-
assert.equal(result2[0].id, String(result.insertId));
34-
assert.equal(result2[0].title, text);
46+
assert.strictEqual(insertResult.insertId, -999);
47+
assert.strictEqual(selectResult.length, 1);
48+
49+
assert.equal(selectResult[0].id, String(insertResult.insertId));
50+
assert.equal(selectResult[0].title, testData);
3551
});

0 commit comments

Comments
 (0)