Skip to content

Commit

Permalink
trying to increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pallavi2209 committed Mar 10, 2017
1 parent 301676f commit fa2c0aa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
15 changes: 6 additions & 9 deletions cache/models/samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,11 @@ function upsertOneSample(sampleQueryBodyObj, method, isBulk) {
explanation: 'Incorrect sample name.',
});

Promise.resolve({ isFailed: true, explanation: err });
if (isBulk) {
return Promise.reject({ isFailed: true, explanation: err });
}

return Promise.reject(err);
}

const subjKey = sampleStore.toKey(
Expand Down Expand Up @@ -579,14 +583,7 @@ module.exports = {
* @returns {Promise} - Resolves to upserted sample
*/
upsertSample(qbObj, logObject, method) {
return upsertOneSample(qbObj, method)
.then((response) => {
if (response.isFailed) {
throw response.explanation;
}

return response;
});
return upsertOneSample(qbObj, method);
},

/**
Expand Down
10 changes: 9 additions & 1 deletion cache/sampleStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* Redis Sample Store Constants and Util Functions
*/
'use strict'; // eslint-disable-line strict
const redisErrors = require('./redisErrors');

const PFX = 'samsto';
const SEP = ':';
const ONE = 1;
Expand Down Expand Up @@ -47,7 +49,13 @@ const constants = {
* @returns {String} the generated redis key
*/
function toKey(type, name) {
return PFX + SEP + type + SEP + name.toLowerCase();
if (name) {
return PFX + SEP + type + SEP + name.toLowerCase();
}

throw new redisErrors.ResourceNotFoundError({
explanation: `${name} not found`,
});
} // toKey

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

it('Incorrect sample name BAD_REQUEST', (done) => {
api.post(path)
.set('Authorization', token)
.send({
name: `${subject.name}xxxxx`,
value: '2',
})
.expect(constants.httpStatus.BAD_REQUEST)
.end((err, res) => {
if (err) {
done(err);
}

expect(res.body.errors[0].description).to.be.equal(
'Incorrect sample name.');
done();
});
});

describe('upsert when the sample already exists', () => {
beforeEach((done) => {
const subjKey = sampleStore.toKey(
Expand Down

0 comments on commit fa2c0aa

Please sign in to comment.