mvndaai/testrail-promise

ifNeededCreateThenAddResultForCase() fails because section_id is null

peggybear opened this issue · 9 comments

So my testrail project is using the Use multiple test suites to manage cases mode which means that when we call getSections, suite_id is required.

To get section_id by section_name, it requires suite_id.

Get section_id method is called before the suite_id, could you switch the two methods and call getSuiteIdByName() before getSectionIdByName?

At least that's what I think is not working. I keep getting error: 'Field :case_id is not a valid ID.'

I have the same setup as your automated test doc

var obj = {
    "project_name":"123",
    "plan_name":"234",
    "suite_name":"asdf",
    "section_name":"sdf",
    "title":jasmine.results.spec.fullName,
    "status_name":(jasmine.results.spec.failedExpectations.length === 0 ? "passed" : "failed")
};

Could you please help me?

I am willing to do that if it helps. Can you replace "section_name" with "section_id" and actually put the ID there. If that succeeds I will figure out how to rearrange it right. Currently the order of getting sections vs suites is mostly ignored.

Oh yes, that's how I found out the issue at first. I was using "section_id" the whole time, but I wanted to not hard-code an ID into my code so I tried "section_name" and then everything blew up. Please and thank you!

Awesome. I don't have something to test it on this moment, can you change the function in your local node_modules folder to this and let me know if it works, if so I will push the change now, otherwise I will probably be able to figure it out this weekend.

redacted... 

Here is the code I should have had above:

TestRail.prototype.ifNeededCreateThenAddResultForCase = function(obj) {
  if(!obj.estimate) obj.estimate = "";
  if(!obj.refs) obj.refs = "";
  if(!obj.type_id) obj.type_id = 3; //Automated
  if(!obj.suite_name) obj.suite_name = "Master";
  if(obj.status_name) obj.status_id = statusIdByName(obj.status_name);
  var tr = this;
  return tr.getProjectIdByName(obj)
    .then(function(project_id){
      obj.project_id = project_id;
      return tr.getSectionIdByName(obj);
    })
    .then(function(section_id){
      obj.section_id = section_id;
      var s,p;
      s = tr.getSuiteIdByName(obj)
          .then(function(suite_id){obj.suite_id = suite_id; });
      p = tr.getLatestRunInPlan(obj)
        .then(function(run_id){ obj.run_id = run_id ;});
      return Promise.all([s,p]);
    })
    .then(function(){
      return tr.ifNeededAddThenGetCaseId(obj).then(function(case_id){
        obj.case_id = case_id;
        return tr.addResultForCase(obj);
      });
    });
};

Hello, sorry for the delay. I tested your last method and it is still the same issue. I noticed you are still calling getSectionIdByName first before getSuiteIdByName when to get section_id by section_name, it requires suite_id.

I tested this code below and it works.

TestRail.prototype.ifNeededCreateThenAddResultForCase = function(obj) {
  if(!obj.estimate) obj.estimate = "";
  if(!obj.refs) obj.refs = "";
  if(!obj.type_id) obj.type_id = 3; //Automated
  if(!obj.suite_name) obj.suite_name = "Master";
  if(obj.status_name) obj.status_id = statusIdByName(obj.status_name);
  var tr = this;
  return tr.getProjectIdByName(obj)
    .then(function(project_id){
      obj.project_id = project_id;
      return tr.getSuiteIdByName(obj);   // switched this from getSectionIdByName
    })
    .then(function(suite_id){
      obj.suite_id = suite_id;
      var s,p;
      s = tr.getSectionIdByName(obj)    // switched this from getSuiteIdByName
          .then(function(section_id){obj.section_id = section_id; });
      p = tr.getLatestRunInPlan(obj)
        .then(function(run_id){ obj.run_id = run_id ;});
      return Promise.all([s,p]);
    })
    .then(function(){
      return tr.ifNeededAddThenGetCaseId(obj).then(function(case_id){
        obj.case_id = case_id;
        return tr.addResultForCase(obj);
      });
    });
};

See if this passes your tests?

Thank you so much. That is working in is now uploaded to NPM under version 0.1.12 e0f6f3c

Let me know if there are any problem. Thank you so much for contributing!

With the same setup as in doc and additional parameters:

    const obj = {
      project_name: '--',
      project_id: --,
      suite_name: '--',
      suite_id: --,
      section_name: '--',
      section_id: --,
      plan_name: '--',
      plan_id: --,
      run_id: --,
      // case_id: --,
      title: jasmine.results.spec.fullName,
      status_name: (jasmine.results.spec.failedExpectations.length === 0 ? 'passed' : 'failed')
    };

is still not working if you need to add a new case to suites's section.
Error remains the same:
Result ==> { error: 'Field :case_id is not a valid ID.' }

Also; in testrail-promise 0.1.19: the part of code peggybear suggested:

TestRail.prototype.ifNeededCreateThenAddResultForCase = function(obj) {
 ...
    .then(function(){
      return tr.ifNeededAddThenGetCaseId(obj).then(function(case_id){
        obj.case_id = case_id;
        return tr.addResultForCase(obj);
      });
    });
};

is not present any more (which also doesn't work as it seems); instead the old code is in place:

      .then(function(){
        return tr.ifNeededAddThenGetCaseId(obj);
      })
      .then(function(case_id){
        obj.case_id = case_id;
        return tr.addResultForCase(obj);
      })

Any help would be appreciated.

If your case_id is not valid it seems like there is something wrong with ifNeededAddThenGetCaseId can you call that function directly with the other parts like project_id, run_id, and suite_id filled in.

The change above about moving the then into the function shouldn't actually change anything. If you change it locally and it works I would be willing to change it, but it really shouldn't.