<commit_before>// numtel:mysql
// MIT License, <EMAIL>
// test/MysqlSubscription.js

var SUITE_PREFIX = 'numtel:mysql - MysqlSubscription - ';
var POLL_WAIT = 700; // update allowance
var LOAD_COUNT = 10;

// Test error handling (should output to console, not hang app)
errorSub = new MysqlSubscription('errorRaising');

players = new MysqlSubscription('allPlayers');
myScore = new MysqlSubscription('playerScore', 'Maxwell');

expectedRows = [ // test/index.es6 :: insertSampleData()
  { name: 'Planck', score: 70 },
  { name: 'Maxwell', score: 60 },
  { name: 'Leibniz', score: 50 },
  { name: 'Kepler', score: 40 }
];

Tinytest.addAsync(SUITE_PREFIX + 'Initialization', function(test, done){
  Meteor.setTimeout(function(){
    test.isTrue(players.ready());
    test.equal(expectResult(players, expectedRows), true);
    done();
  }, POLL_WAIT);
});

Tinytest.addAsync(SUITE_PREFIX + 'Insert / Delete Row Sync',
function(test, done){
  var newPlayer = 'Archimedes';
  var updateCount = 0;
  players.addEventListener('update.test1', function(diff, data){
    switch(updateCount) {
      case 0: test.equal(data.length, 5); break;
      case 1: test.equal(data.length, 4); break;
    }
    updateCount++;
  });
  Meteor.call('insPlayer', newPlayer, 100);
  Meteor.setTimeout(function(){
    var newExpected = expectedRows.slice();
    newExpected.unshift({ name: newPlayer, score: 100 });
    test.equal(expectResult(players, newExpected), true, 'Row inserted');
    Meteor.call('delPlayer', newPlayer);
    Meteor.setTimeout(function(){
      players.removeEventListener(/test1/);
      test.equal(expectResult(players, expectedRows), true, 'Row removed');
      done();
    }, POLL_WAIT);
  }, POLL_WAIT);
});

Tinytest.addAsync(SUITE_PREFIX + 'Conditional Trigger Update',
function(test, done){
  Meteor.setTimeout(function(){
    test.equal(myScore.length, 1);
    test.equal(myScore[0].score, 60);
    if(Meteor.isClient){
      var testEl = document.getElementById('myScoreTest');
      var testElVal = parseInt($.trim(testEl.textContent), 10);
      test.equal(testElVal, 60, 'Reactive template');
    }
    Meteor.call('setScore', myScore[0].id, 30);
    Meteor.setTimeout(function(){
      test.equal(myScore[0].score, 30);
      if(Meteor.isClient){
        testElVal = parseInt($.trim(testEl.textContent), 10);
        test.equal(testElVal, 30, 'Reactive template');
      }
      Meteor.call('setScore', myScore[0].id, 60);
      done();
    }, POLL_WAIT);
  }, POLL_WAIT);
});

testAsyncMulti(SUITE_PREFIX + 'Event Listeners', [
  function(test, expect){
    var buffer = 0;
    players.addEventListener('test.cow', function(){ buffer++; });
    players.dispatchEvent('test');
    test.equal(buffer, 1, 'Call suffixed listener without specified suffix');
    players.removeEventListener('test');
    players.dispatchEvent('test');
    test.equal(buffer, 1, 'Remove suffixed listener without specified suffix');
  },
  function(test, expect){
    var buffer = 0;<commit_msg>Remove unneeded jQuery call since not included by default in Meteor 1.2<commit_after>// numtel:mysql
// MIT License, <EMAIL>
// test/MysqlSubscription.js

var SUITE_PREFIX = 'numtel:mysql - MysqlSubscription - ';
var POLL_WAIT = 700; // update allowance
var LOAD_COUNT = 10;

// Test error handling (should output to console, not hang app)
errorSub = new MysqlSubscription('errorRaising');

players = new MysqlSubscription('allPlayers');
myScore = new MysqlSubscription('playerScore', 'Maxwell');

expectedRows = [ // test/index.es6 :: insertSampleData()
  { name: 'Planck', score: 70 },
  { name: 'Maxwell', score: 60 },
  { name: 'Leibniz', score: 50 },
  { name: 'Kepler', score: 40 }
];

Tinytest.addAsync(SUITE_PREFIX + 'Initialization', function(test, done){
  Meteor.setTimeout(function(){
    test.isTrue(players.ready());
    test.equal(expectResult(players, expectedRows), true);
    done();
  }, POLL_WAIT);
});

Tinytest.addAsync(SUITE_PREFIX + 'Insert / Delete Row Sync',
function(test, done){
  var newPlayer = 'Archimedes';
  var updateCount = 0;
  players.addEventListener('update.test1', function(diff, data){
    switch(updateCount) {
      case 0: test.equal(data.length, 5); break;
      case 1: test.equal(data.length, 4); break;
    }
    updateCount++;
  });
  Meteor.call('insPlayer', newPlayer, 100);
  Meteor.setTimeout(function(){
    var newExpected = expectedRows.slice();
    newExpected.unshift({ name: newPlayer, score: 100 });
    test.equal(expectResult(players, newExpected), true, 'Row inserted');
    Meteor.call('delPlayer', newPlayer);
    Meteor.setTimeout(function(){
      players.removeEventListener(/test1/);
      test.equal(expectResult(players, expectedRows), true, 'Row removed');
      done();
    }, POLL_WAIT);
  }, POLL_WAIT);
});

Tinytest.addAsync(SUITE_PREFIX + 'Conditional Trigger Update',
function(test, done){
  Meteor.setTimeout(function(){
    test.equal(myScore.length, 1);
    test.equal(myScore[0].score, 60);
    if(Meteor.isClient){
      var testEl = document.getElementById('myScoreTest');
      var testElVal = parseInt(testEl.textContent, 10);
      test.equal(testElVal, 60, 'Reactive template');
    }
    Meteor.call('setScore', myScore[0].id, 30);
    Meteor.setTimeout(function(){
      test.equal(myScore[0].score, 30);
      if(Meteor.isClient){
        testElVal = parseInt(testEl.textContent, 10);
        test.equal(testElVal, 30, 'Reactive template');
      }
      Meteor.call('setScore', myScore[0].id, 60);
      done();
    }, POLL_WAIT);
  }, POLL_WAIT);
});

testAsyncMulti(SUITE_PREFIX + 'Event Listeners', [
  function(test, expect){
    var buffer = 0;
    players.addEventListener('test.cow', function(){ buffer++; });
    players.dispatchEvent('test');
    test.equal(buffer, 1, 'Call suffixed listener without specified suffix');
    players.removeEventListener('test');
    players.dispatchEvent('test');
    test.equal(buffer, 1, 'Remove suffixed listener without specified suffix');
  },
  function(test, expect){
    var buffer = 0;
{'fraction_non_alphanumeric': 0.15541888297872342, 'fraction_numerical': 0.01761968085106383, 'mean_word_length': 4.182601205857019, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3069724', 'n_tokens_mistral': 2045, 'n_tokens_neox': 1932, 'n_words': 416}