我对测试有点陌生,正在为 yeoman angular-fullstack 生成器生成的 MEAN-stack Web 应用程序编辑测试。我已经将一个虚拟对象发布到我的 mongo 数据库中,并且可以ID
通过 mongo shell 查看该对象及其。
我可以对对象执行GET
和请求;PUT
但是,尝试对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 内部服务器错误。我的记录器返回 OPERATION_PATH_UNRESOLVABLE