A Twitch.tv viewer reward and games system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.2 KiB

12 years ago
  1. var common = require('../../common');
  2. var connection = common.createConnection();
  3. var assert = require('assert');
  4. common.useTestDb(connection);
  5. var table = 'zerofill_results_test';
  6. connection.query([
  7. 'CREATE TEMPORARY TABLE `' + table + '` (',
  8. '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
  9. '`num` int(5) UNSIGNED ZEROFILL,',
  10. 'PRIMARY KEY (`id`)',
  11. ') ENGINE=InnoDB DEFAULT CHARSET=utf8'
  12. ].join('\n'));
  13. var test_numbers = [ "00000", "00001", "00012", "00123", "01234", "12345", null ];
  14. var results = {};
  15. for (var i = 0; i < test_numbers.length; i++) {
  16. connection.query('INSERT INTO ' + table + ' SET ?', {
  17. id: (i + 1),
  18. num: (test_numbers[i] !== null ? parseInt(test_numbers[i], 10) : null)
  19. }, function (err, _result) {
  20. if (err) throw err;
  21. });
  22. }
  23. connection.query('SELECT * FROM ' + table, function (err, _results) {
  24. if (err) throw err;
  25. results = _results;
  26. });
  27. connection.end();
  28. process.on('exit', function() {
  29. assert.strictEqual(results.length, test_numbers.length);
  30. for (var i = 0; i < results.length; i++) {
  31. assert.strictEqual(test_numbers[results[i].id - 1], (results[i].num !== null ? "" + results[i].num : null));
  32. }
  33. });