1

I'm a bit new to testing and am working on editing tests for a MEAN-stack web app generated by the yeoman angular-fullstack generator. I've POSTed a dummy object into my mongo database and can see the object and its ID through the mongo shell.

I can perform GET and PUT requests on the object; however, trying to perform a PATCH request on the ID returns OPERATION_PATH_UNRESOLVABLE. Does anyone have any suggestions as to why this may be happening?

I've included a sample of the code below, this code works perfectly for my other endpoints. I'm only receiving the error with one specific endpoint.

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');
    });
  });

I expect the output to be 200 but receive 500 Internal Server Error. My Logger returns OPERATION_PATH_UNRESOLVABLE

Roman Skydan
  • 5,478
  • 4
  • 19
  • 39
  • Yes if you resolve your problem before somebody do that you can post the answer there. Maybe it will help other peoples who have the same issue. – Roman Skydan Jan 15 '19 at 14:11
  • I am not sure how your API works, but I can't seem to find an "operation" attribute (e.g. 'add', 'replace')? Please note, `PATCH` requests tend to have a different format when compared to `POST` or `PUT`. For more info on PATCH requests - https://williamdurand.fr/2014/02/14/please-do-not-patch-like-an-idiot/ – Mo A Jan 25 '19 at 23:36

0 Answers0