Skip to content

Commit

Permalink
Allow empty strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtolar committed Dec 5, 2016
1 parent 1805ee9 commit 44b7099
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/client.js
Expand Up @@ -14,7 +14,7 @@ function getValue (field, callback) {
timeout: this.timeout,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200 && body.value) {
if (!error && response.statusCode === 200 && (body.value || body.value === "")) {
callback(null, body.value);
} else {
if (!error) {
Expand Down
40 changes: 40 additions & 0 deletions tests/client.test.js
Expand Up @@ -39,6 +39,46 @@ Y.TestRunner.add(new Y.TestCase({
test.wait(100);
},

'Can retrieve an empty value': function () {
var test = this,
instance = new Client('http://fakeserver');

nock('http://fakeserver/')
.get('/foo')
.reply(200, {
field: 'foo',
value: ''
});
instance.get('foo', function (error, value) {
test.resume(function () {
Assert.isNull(error);
Assert.areEqual('', value);
});
});
test.wait(100);
},

'Can fail to retrieve a missing value': function () {
var test = this,
instance = new Client('http://fakeserver');

nock('http://fakeserver/')
.get('/something-else')
.reply(200, {
field: 'something-else',
value: undefined
});
instance.get('something-else', function (error, value) {
test.resume(function () {

Assert.areEqual('Error: Unable to get value of "something-else" - [object Object]',
error.toString());
Assert.isUndefined(value);
});
});
test.wait(100);
},

'Can fail to retrieve a value': function () {
var test = this,
instance = new Client('http://fakeserver/');
Expand Down

0 comments on commit 44b7099

Please sign in to comment.