Skip to content

Commit

Permalink
implement the changes Shriram suggested
Browse files Browse the repository at this point in the history
  • Loading branch information
annyhe committed Apr 12, 2017
1 parent 4f4c31a commit b547e08
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
20 changes: 10 additions & 10 deletions cache/models/samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,17 +404,7 @@ function handleUpsertError(objectType, isBulk) {
*/
function upsertOneSample(sampleQueryBodyObj, isBulk, userName) {
const sampleName = sampleQueryBodyObj.name;
const sampleKey = sampleStore.toKey(
constants.objectType.sample, sampleName
);
const subjAspArr = sampleName.toLowerCase().split('|');
const aspectName = subjAspArr[ONE];
const subjKey = sampleStore.toKey(
constants.objectType.subject, subjAspArr[ZERO]
);
let aspectObj = {};
let subjectId = '';

if (subjAspArr.length < TWO) {
const err = new redisErrors.ValidationError({
explanation: 'Incorrect sample name.',
Expand All @@ -427,6 +417,16 @@ function upsertOneSample(sampleQueryBodyObj, isBulk, userName) {
return Promise.reject(err);
}

const sampleKey = sampleStore.toKey(
constants.objectType.sample, sampleName
);
const aspectName = subjAspArr[ONE];
const subjKey = sampleStore.toKey(
constants.objectType.subject, subjAspArr[ZERO]
);
let aspectObj = {};
let subjectId = '';

return checkWritePermission(aspectName, sampleName, userName, isBulk)

/*
Expand Down
9 changes: 5 additions & 4 deletions tests/cache/models/samples/upsert.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe(`api::redisEnabled::POST::upsert ${path}`, () => {
});
});
});

it('name field is required', (done) => {
api.post(path)
.set('Authorization', token)
Expand All @@ -111,15 +111,15 @@ describe(`api::redisEnabled::POST::upsert ${path}`, () => {
if (err) {
done(err);
}

const error = res.body.errors[0];
expect(error.message).to.contain('name');
expect(error.type)
.to.equal(tu.schemaValidationErrorName);
done();
});
});
});

it('returns aspectId, subjectId, and aspect object', (done) => {
api.post(path)
.set('Authorization', token)
Expand All @@ -129,6 +129,7 @@ describe(`api::redisEnabled::POST::upsert ${path}`, () => {
})
.expect(constants.httpStatus.OK)
.end((err, res) => {
console.log(res.error)
if (err) {
done(err);
}
Expand Down

0 comments on commit b547e08

Please sign in to comment.