diff options
author | Ben Langfeld <ben@langfeld.me> | 2015-07-27 00:12:40 +0300 |
---|---|---|
committer | Ben Langfeld <ben@langfeld.me> | 2015-07-27 00:12:40 +0300 |
commit | cbf6356cd42160d8320e7a4c7a0958457feef047 (patch) | |
tree | a7549e01a4c1465de8f683c099d03d4d18223f42 | |
parent | 120a2128e7f196d9eaef87e0dc9c5478cff8de07 (diff) | |
parent | 6f3b2a6cf286628bdd55712d9d5ea4e22151bc36 (diff) |
Merge pull request #408 from candy-chat/fix/empty_priority
Fix handling an empty priority
-rw-r--r-- | src/core/contact.js | 7 | ||||
-rw-r--r-- | tests/candy/unit/core/contact.js | 16 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/core/contact.js b/src/core/contact.js index 04c3cf5..cc97f02 100644 --- a/src/core/contact.js +++ b/src/core/contact.js @@ -112,7 +112,12 @@ Candy.Core.Contact.prototype.getStatus = function() { highestResourcePriority; $.each(this.data.resources, function(resource, obj) { - var resourcePriority = parseInt(obj.priority, 10); + var resourcePriority; + if (obj.priority === undefined || obj.priority === '') { + resourcePriority = 0; + } else { + resourcePriority = parseInt(obj.priority, 10); + } if (obj.show === '' || obj.show === null || obj.show === undefined) { // TODO: Submit this as a bugfix to strophejs-plugins' roster plugin diff --git a/tests/candy/unit/core/contact.js b/tests/candy/unit/core/contact.js index 2059630..2e926dc 100644 --- a/tests/candy/unit/core/contact.js +++ b/tests/candy/unit/core/contact.js @@ -47,6 +47,22 @@ define([ expect(contact.getGroups()).to.eql(['Friends']); }); + bdd.it('defaults the priority to 0 when not defined', function() { + contact.data.resources = { + 'resource1': { + show: 'away', + status: 'Hanging out', + priority: 0 + }, + 'resource2': { + show: 'available', + status: 'Not Hanging out', + priority: "" + } + }; + expect(contact.getStatus()).to.eql('available'); + }); + bdd.describe('aggregate status', function () { bdd.describe('when there are no online resources', function () { bdd.it('is unavailable when there are no online resources', function () { |