0
  • How can I stub @ra.do_post so that it goes into "Step 2"

    • Right now when I run my spec inside Async.Waterfall after Step1 it goes to Step 5
    • What I think is in my spec I am not returning the callback properly for it to go into step2

scroll to end to see what I am doing. Thanks a bunch in advance

RA = require('./request_adapter')

class QueryHandler
  constructor: (@adapter) ->
    @ra = new RA()


  create_test: (id, data, cb) ->
    self = this

    _url    =  url + adapter_apis.CREATE
    bll_url = "http://localhost:" + 11 + "/" + bll_apis.PKG_SWITCH  

    Async.waterfall [
      (done) ->
        console.info("Step 1 ==================")
        @ra.do_post some_url, data, done

      , (resp, done) ->
        console.info("Step 2 ==================")
        console.info(resp)
        if resp? and resp.status isnt "SUCCESS"
          console.info("Step 3a ==================")
          cb({error: true, message: "error."})
        else
          console.info("Step 3b ==================")
          fn = () -> self.ra.do_post _url, data , done
          helper.delay 500, fn

      , (resp, done) ->
        console.info("Step 4 ==================")
        cb(null,resp)

    ], (error, resp) ->
      console.info("Step 5 ==================")
      if error
        cb({error: true, message: "errored out"})

this is what I tried in my spec

  var qh      = require(query_handler");
  var qh_obj  = new qh("FAKE");

  var fn = function(ccb){
    ccb(undefined, 10);
  };

  stub = sinon.stub(qh_obj.ra,'do_post').returns(fn);

  qh_obj.create_test("fake_id", {switch_data: {a: 11}}, function(e,r) {
    console.log(e);
    (e.error).should.be.true
    done();
  });
Rockyboy_ruby
  • 233
  • 1
  • 4
  • 15

1 Answers1

0

My Bad, i had a mistake in my spec.

var fn = function(a,b,ccb){
    ccb(undefined, true);
  };

  stub = sinon.stub(qh_obj.ra,'do_post', fn)
Rockyboy_ruby
  • 233
  • 1
  • 4
  • 15