Skip to content

Commit

Permalink
removed rejection and unnecessary test cases as well
Browse files Browse the repository at this point in the history
  • Loading branch information
hkothari committed Oct 24, 2016
1 parent a402180 commit 6a3178d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 102 deletions.
3 changes: 2 additions & 1 deletion db/helpers/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function augmentSampleWithSubjectInfo(seq, inst) {
inst.dataValues.subject = sub;

// adding absolutePath to sample instance
inst.dataValues.absolutePath = sub.absolutePath;
if (sub)
inst.dataValues.absolutePath = sub.absolutePath;
inst.subject = sub;
resolve(inst);
})
Expand Down
4 changes: 4 additions & 0 deletions tests/api/v1/subjects/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ describe(`api: PATCH ${path}`, () => {
done();
});
});

it('cannot patch tags with names starting with a dash (-)', (done) => {
const tags = ['-tag1'];
p1.tags = tags;
Expand All @@ -299,6 +300,7 @@ describe(`api: PATCH ${path}`, () => {
done();
});
});

it('patch tags multiple', (done) => {
const tags = [
'tag0',
Expand Down Expand Up @@ -465,9 +467,11 @@ describe(`api: PATCH ${path}`, () => {
if (err) {
return done(err);
}

expect(res.body.errors[0].message).to
.equal('You cannot unpublish this subject until ' +
'all its descendants are unpublished.');

done();
});
});
Expand Down
72 changes: 0 additions & 72 deletions tests/api/v1/subjects/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,78 +231,6 @@ describe(`api: PUT ${path}`, () => {
done();
});
});

it('geolocation array must not contain null elements while patching',
(done) => {
const toPatch = {
isPublished: p1.isPublished,
name: p1.name,
geolocation: [null, null],
};
api.put(`${path}/${i0}`)
.set('Authorization', token)
.send(toPatch)
.expect(constants.httpStatus.BAD_REQUEST)
.end((err, res) => {
if (err) {
return done(err);
}

expect(res.body.errors[0].message).to
.equal('Expected type number but found type null');
expect(res.body.errors[0].source).to
.equal('geolocation');
done();
});
});

it('geolocation array cant contain less than two elements in patching',
(done) => {
const toPatch = {
isPublished: p1.isPublished,
name: p1.name,
geolocation: [1],
};
api.put(`${path}/${i0}`)
.set('Authorization', token)
.send(toPatch)
.expect(constants.httpStatus.BAD_REQUEST)
.end((err, res) => {
if (err) {
return done(err);
}

expect(res.body.errors[0].message).to
.equal('A non-null range must include two elements');
expect(res.body.errors[0].source).to
.equal('geolocation');
done();
});
});

it('geolocation array cant contain more than three elements in patching',
(done) => {
const toPatch = {
isPublished: p1.isPublished,
name: p1.name,
geolocation: [1,2,3],
};
api.put(`${path}/${i0}`)
.set('Authorization', token)
.send(toPatch)
.expect(constants.httpStatus.BAD_REQUEST)
.end((err, res) => {
if (err) {
return done(err);
}

expect(res.body.errors[0].message).to
.equal('A non-null range must include two elements');
expect(res.body.errors[0].source).to
.equal('geolocation');
done();
});
});
});

describe('api: PUT subjects with related links', () => {
Expand Down
45 changes: 16 additions & 29 deletions tests/db/model/subject/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('db: subject: update: ', () => {
Subject.create({ name: parentName })
.then((parent) => {
oldParentId = parent.id;
return Subject.findById(childId1);
return Subject.findById(childId2);
})
.then((child) => {
return child.update({ parentAbsolutePath: parentName });
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('db: subject: update: ', () => {
Subject.create({ name: parentName })
.then((parent) => {
oldParentId = parent.id;
return Subject.findById(childId1);
return Subject.findById(childId2);
})
.then((child) => {
return child.update({ parentAbsolutePath: parentName });
Expand All @@ -114,13 +114,18 @@ describe('db: subject: update: ', () => {

it('on update child name, child should remain parented', (done) => {
const childName = 'achoo';
Subject.findById(childId1)
let oldParentId = null;
let oldParentAbsolutePath = null;
Subject.findById(childId2)
.then((child) => {
oldParentId = child.parentId;
oldParentAbsolutePath = child.parentAbsolutePath;
return child.update({ name: childName });
})
.then((child) => {
expect(child.dataValues.parentAbsolutePath).to.not.be.null;
expect(child.dataValues.absolutePath).to.contain('.');
expect(child.dataValues.parentId).to.equal(oldParentId);
expect(child.dataValues.parentAbsolutePath)
.to.equal(oldParentAbsolutePath);
done();
})
.catch((err) => {
Expand Down Expand Up @@ -179,14 +184,14 @@ describe('db: subject: update: ', () => {
const parentName = `${tu.namePrefix}parent3`;
Subject.create({ name: parentName })
.then(() => {
return Subject.findById(childId1);
return Subject.findById(childId2);
})
.then((child) => {
return child.update({ parentAbsolutePath: parentName });
})
.then((child) => {
expect(child.dataValues.absolutePath).to
.equal(`${parentName}.${tu.namePrefix}child1`);
.equal(`${parentName}.${tu.namePrefix}child2`);
expect(child.dataValues.parentAbsolutePath).to.equal(parentName);
done();
})
Expand All @@ -200,15 +205,15 @@ describe('db: subject: update: ', () => {
const parentName = `${tu.namePrefix}parent2`;
Subject.create({ name: parentName })
.then(() => {
return Subject.findById(childId1);
return Subject.findById(childId2);
})
.then((subj) => {
return subj.update({ parentAbsolutePath: parentName });
})
.then((subj) => {
expect(subj.dataValues.parentAbsolutePath).to.equal(parentName);
expect(subj.dataValues.absolutePath).to
.equal(`${tu.namePrefix}parent2.${tu.namePrefix}child1`);
.equal(`${tu.namePrefix}parent2.${tu.namePrefix}child2`);
done();
})
.catch((err) => {
Expand Down Expand Up @@ -293,24 +298,6 @@ describe('db: subject: update: ', () => {
.catch((err) => done(err));
});

it('update parent isPublished to false, should not change child subject',
(done) => {
Subject.findById(subjId1)
.then((parent) => {
expect(parent.get('isPublished')).to.equal(true);
parent.update({ isPublished: false });
expect(parent.get('isPublished')).to.equal(false);
})
.then(() => {
return Subject.findById(childId1);
})
.then((child) => {
expect(child.get('isPublished')).to.equal(true);
done();
})
.catch((err) => done(err));
});

it('update child helpEmail, should not change parent subject',
(done) => {
Subject.findById(childId1)
Expand Down Expand Up @@ -370,14 +357,14 @@ describe('db: subject: update: ', () => {

it('update child isPublished, should not change parent subject',
(done) => {
Subject.findById(childId1)
Subject.findById(childId2)
.then((child) => {
expect(child.get('isPublished')).to.equal(true);
child.update({ isPublished: false });
expect(child.get('isPublished')).to.equal(false);
})
.then(() => {
return Subject.findById(subjId1);
return Subject.findById(childId1);
})
.then((parent) => {
expect(parent.get('isPublished')).to.equal(true);
Expand Down

0 comments on commit 6a3178d

Please sign in to comment.