Monday, 17 April 2017

Mocha how to Mongoose Schema Arrays of objects

currently saving an Array type with Mongoose, I don't pass the test

let resourcePublic = {
  name: 'RS123',
  description: 'RS123Description',
  owner: newUser.id,
  permissions: [{ level: 'group', level_id: newGroup.id, canWrite: true }],
  private: false
};

it('should create a new public resource', (done) => {
  request(app)
    .post('/api/v1/resources')
    .send(resourcePublic)
    .expect(httpStatus.OK)
    .then((res) => {
      ...
      expect(res.body.permissions).to.have.same.members(resourcePublic.permissions);
      ...
      resourcePublic = res.body;
      done();
    })
    .catch(done);
});

the ACTUAL Array has the object_id field inserted after the document being saved.. which the expected does not have

  ACTUAL
  res.body.permissions:  [ 
      { level: 'group',
      level_id: '58f4b9c7110e5e7abd4f0425',
      _id: '58f4b9cb110e5e7abd4f042d',
      canWrite: true } 
  ]
  EXPECTED
  resourcePublic.permissions:  [
  { level: 'group',
      level_id: '58f4b9c7110e5e7abd4f0425',
      canWrite: true }
  ]

Is there any way to pass the test ? thanks for feedback



via erwin

No comments:

Post a Comment