Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding initial tests for database queryTransaction method.

  • Loading branch information...
commit e0d4693348be8958a64c274648710ad0e5f20af6 1 parent 46e5757
thehunmonkgroup authored

Showing 1 changed file with 155 additions and 0 deletions. Show diff stats Hide diff stats

  1. 155  test/queryTransaction.js
155  test/queryTransaction.js
... ...
@@ -0,0 +1,155 @@
  1
+var util = require('./util');
  2
+var should = require('should');
  3
+
  4
+// For all tests, the dummy driver spits back the passed queries as the result
  5
+// data, so testing that the result matches the query will confirm that the
  6
+// result data is from the correct query.
  7
+describe('Database', function() {
  8
+  describe('#queryTransaction()', function() {
  9
+    var db = util.get_driver();
  10
+    beforeEach(function() {
  11
+      db.driver.clear_query_stack();
  12
+    });
  13
+    describe('with one successful query (custom)', function() {
  14
+      it('should not return an error object', function(done) {
  15
+        var query = util.query_string;
  16
+        var cb = function(err, data) {
  17
+          should.not.exist(err);
  18
+          done();
  19
+        }
  20
+        db.queryTransaction(query, cb);
  21
+      });
  22
+      it('should return query data to the callback', function(done) {
  23
+        var query = util.query_string;
  24
+        var query_data = query();
  25
+        var cb = function(err, data) {
  26
+          data.query.should.equal(query_data);
  27
+          done();
  28
+        }
  29
+        db.queryTransaction(query, cb);
  30
+      });
  31
+    });
  32
+    describe('with one successful query (object)', function() {
  33
+      it('should not return an error object', function(done) {
  34
+        var query = util.query_object;
  35
+        var cb = function(err, data) {
  36
+          should.not.exist(err);
  37
+          done();
  38
+        }
  39
+        db.queryTransaction(query, cb);
  40
+      });
  41
+      it('should return query data to the callback', function(done) {
  42
+        var query = util.query_object;
  43
+        var query_data = "object";
  44
+        var cb = function(err, data) {
  45
+          data.query.should.equal(query_data);
  46
+          done();
  47
+        }
  48
+        db.queryTransaction(query, cb);
  49
+      });
  50
+    });
  51
+    describe('with one failed query', function() {
  52
+      it('should return an error object', function(done) {
  53
+        var query = util.query_error;
  54
+        var error_data = 'ERROR';
  55
+        var cb = function(err, data) {
  56
+          err.should.equal(error_data);
  57
+          done();
  58
+        }
  59
+        db.queryTransaction(query, cb);
  60
+      });
  61
+      it('should not return a data object', function(done) {
  62
+        var query = util.query_error;
  63
+        var cb = function(err, data) {
  64
+          should.not.exist(data);
  65
+          done();
  66
+        }
  67
+        db.queryTransaction(query, cb);
  68
+      });
  69
+    });
  70
+    describe('with one query returning false', function() {
  71
+      it('should not return an error object', function(done) {
  72
+        var query = util.query_false;
  73
+        var cb = function(err, data) {
  74
+          should.not.exist(err);
  75
+          done();
  76
+        }
  77
+        db.queryTransaction(query, cb);
  78
+      });
  79
+      it('should return data as false', function(done) {
  80
+        var query = util.query_false;
  81
+        var cb = function(err, data) {
  82
+          data.should.be.false;
  83
+          done();
  84
+        }
  85
+        db.queryTransaction(query, cb);
  86
+      });
  87
+    });
  88
+    describe('with two queries (both succeed)', function() {
  89
+      it('should not return an error object', function(done) {
  90
+        var query1 = util.query_string;
  91
+        var query2 = function(data1, query) {
  92
+          util.query_object(query);
  93
+        }
  94
+        var cb = function(err, data2) {
  95
+          should.not.exist(err);
  96
+          done();
  97
+        }
  98
+        db.queryTransaction(query1, query2, cb);
  99
+      });
  100
+      it('should return query1 data as the second argument to query2', function(done) {
  101
+        var query1 = util.query_string;
  102
+        var query2 = function(data1) {
  103
+          data1.query.should.equal(query1_data);
  104
+          return util.query_array();
  105
+        }
  106
+        var query1_data = query1();
  107
+        var cb = function(err, data2) {
  108
+          done();
  109
+        }
  110
+        db.queryTransaction(query1, query2, cb);
  111
+      });
  112
+      it('should return query2 data as the second argument to user callback', function(done) {
  113
+        var query1 = util.query_array;
  114
+        var query2 = function(data1) {
  115
+          return util.query_string();
  116
+        }
  117
+        var query2_data = util.query_string();
  118
+        var cb = function(err, data2) {
  119
+          data2.query.should.equal(query2_data);
  120
+          done();
  121
+        }
  122
+        db.queryTransaction(query1, query2, cb);
  123
+      });
  124
+    });
  125
+    describe('with two queries (first fails)', function() {
  126
+      it('should return an error object', function(done) {
  127
+        var query1 = util.query_error;
  128
+        var query2 = function(data1) {
  129
+          return util.query_string();
  130
+        }
  131
+        var error_data = 'ERROR';
  132
+        var cb = function(err, data2) {
  133
+          err.should.equal(error_data);
  134
+          done();
  135
+        }
  136
+        db.queryTransaction(query1, query2, cb);
  137
+      });
  138
+    });
  139
+    describe('with two queries (second fails)', function() {
  140
+      it('should return an error object', function(done) {
  141
+        var query1 = util.query_string;
  142
+        var query2 = function(data1) {
  143
+          return util.query_error();
  144
+        }
  145
+        var error_data = 'ERROR';
  146
+        var cb = function(err, data2) {
  147
+          err.should.equal(error_data);
  148
+          done();
  149
+        }
  150
+        db.queryTransaction(query1, query2, cb);
  151
+      });
  152
+    });
  153
+  });
  154
+});
  155
+

0 notes on commit e0d4693

Please sign in to comment.
Something went wrong with that request. Please try again.