PATCH请求对一个端点失败,但对其他端点有效

时间:2019-01-15 14:03:49

标签: angularjs mocha angular-fullstack sinon-chai json-patch

我对测试有点陌生,并且正在为由yeoman角满堆栈生成器生成的MEAN堆栈Web应用程序编辑测试。我已经将一个虚拟对象发布到我的mongo数据库中,并且可以通过mongo shell查看该对象及其ID

我可以对对象执行GETPUT请求;但是,尝试在ID上执行PATCH请求将返回OPERATION_PATH_UNRESOLVABLE。 有人对为什么会发生这种情况有任何建议吗?

我在下面提供了代码示例,此代码可完美地用于我的其他端点。我只收到一个特定端点的错误。

describe('PATCH /api/objects/:id', function() {
  var patchedObject;
    beforeEach(function(done) {
    newObject.title = 'Patched Object';
    newObject.section.Title = 'Patched Object Sec Title';
    newObject.section.Body = 'Patched Object Sec Body';
    newObject.section.Lists = ['Patched  Sec List Item 0'];
    newObject.images = ['N/A'];
    newObject.date.startDate = '1/5/19';
    newObject.date.endDate = '1/10/19';
    newObject.duration = '5 Days';
    newObject.location = 'VA';
    newObject.isProgram = true;
    newObject.hasRegistration = true;
    newObject.linksOut.title = 'Patched Link';
    newObject.linksOut.address = 'Patched Address';
    newObject.backGround = 'black';
    newObject.orderIndex = objects.length;
      request(app)
        .patch(`/api/promotions/${newObject._id}`)
        .set('authorization', 'Bearer ' + token)
        .send(newObject)
        .expect(200)
        .expect('Content-Type', /json/)
        .end(function(err, res) {
          if(err) {
            return done(err);
          }
          patchedObject = res.body;
          done();
        });
    });

    afterEach(function() {
      patchedObject = {};
    });

    it('should respond with the patched promotion when authenticated', 
    function() {
      expect(patchedObject.title).to.equal('Patched Object');
    });
  });

我希望输出为200,但是会收到500 Internal Server Error。 我的记录仪返回OPERATION_PATH_UNRESOLVABLE

0 个答案:

没有答案