Skip to content

Commit

Permalink
Merge branch 'master' into roomswagger
Browse files Browse the repository at this point in the history
* master:
  Fix subject hierarchy level on put (#372)
  • Loading branch information
tausifmuzaffar committed May 18, 2017
2 parents d3e4752 + 34eac0f commit f7f636d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/v1/helpers/verbs/doPut.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ function doPut(req, res, next, props) {
// take nullified fields out of changed fields
o.changed(key, false);
} else {

// value may have changed. set changed to true to
// trigger checks in the model
o.changed(key, true);
o.set(key, toPut[key]);
}
}
Expand Down
71 changes: 71 additions & 0 deletions tests/api/v1/subjects/putWithParent.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,77 @@ describe(`api: PUT ${path} with parents`, () => {
afterEach(u.forceDelete);
after(tu.forceDeleteUser);

describe('with identical parent: ', () => {
it('with parentId does NOT' +
' update the hierarchyLevel', (done) => {
api.put(`${path}/${i1}`)
.set('Authorization', token)
.send({
name: n1.name,
isPublished: p1.isPublished,
parentId: i0,
})
.expect(constants.httpStatus.OK)
.end((err, res ) => {
if (err) {
done(err);
}

// not a root
expect(res.body.hierarchyLevel).to.equal(TWO);
expect(res.body.parentId).to.equal(i0);
expect(res.body.parentAbsolutePath).to.equal(n0.name);
done();
});
});

it('with parentAbsolutePath does NOT' +
' update the hierarchyLevel', (done) => {
api.put(`${path}/${i1}`)
.set('Authorization', token)
.send({
name: n1.name,
isPublished: p1.isPublished,
parentAbsolutePath: n0.name
})
.expect(constants.httpStatus.OK)
.end((err, res ) => {
if (err) {
done(err);
}

// not a root
expect(res.body.hierarchyLevel).to.equal(TWO);
expect(res.body.parentId).to.equal(i0);
expect(res.body.parentAbsolutePath).to.equal(n0.name);
done();
});
});

it('with BOTH parentId and parentAbsolutePath does NOT' +
' update the hierarchyLevel', (done) => {
api.put(`${path}/${i1}`)
.set('Authorization', token)
.send({
name: n1.name,
isPublished: p1.isPublished,
parentAbsolutePath: n0.name
})
.expect(constants.httpStatus.OK)
.end((err, res ) => {
if (err) {
done(err);
}

// not a root
expect(res.body.hierarchyLevel).to.equal(TWO);
expect(res.body.parentId).to.equal(i0);
expect(res.body.parentAbsolutePath).to.equal(n0.name);
done();
});
});
});

/**
(0) PUT /v1/subjects/{key} unpublishing child subject with parentId or parentAbsolutePath field should re-parent the subject
(1) PUT /v1/subjects/{key} unpublishing child subject without parentId nor parentAbsolutePath field should set the subject as top level subject
Expand Down

0 comments on commit f7f636d

Please sign in to comment.