jeudi 9 juin 2016

Node.JS functional test to execute in order?

I need some assistance in building this node test.

I need to post data to an endpoint and then validate that data using a MariaDB sql query.

/************************************************************************
Validating Database Insertion
*************************************************************************/
describe('Validating DB insertion for individual key monitoring', function () {
  it('Should successfully insert POST values into MariaDB', function (done) {
    setTimeout(function () {
      request({
        uri: "http://localhost:3000/store",
        method: "POST",
        form: {
          initial_timestamp: '1465496079',
          secret_ref: 'secret_ref_key_01',
          ip_addr: '192.168.0.1'
        }
      }, function(error, response, body) {
        done();
      });
    }, 1000);
  });
  it('Query the results in JSON format', function () {
    var x = c.query('SELECT * FROM individual_key_log WHERE ip_addr = "192.168.0.1"',
    function(err, rows) {
      if (err)
        throw err;
      console.dir(rows);
    });
  });
});

My first question is how should I design this to first insert the DB info, then second, get the info in a json, then last, start asserting data matches with what's expected and what the JSON outputted.

Aucun commentaire:

Enregistrer un commentaire