Skip to content

Commit

Permalink
Treat empty strings as an empty set of contacts (#10)
Browse files Browse the repository at this point in the history
* entity contacts should be disregarded when check contacts are present

* treat empty string values as no contacts
  • Loading branch information
Cameron Johnston authored Jun 27, 2019
1 parent 313e4d6 commit a414eb9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
22 changes: 17 additions & 5 deletions lib/no_contacts.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
function no_contacts(event) {
var check_contacts = [];
var entity_contacts = [];

if (event.hasOwnProperty("check") && event.check.hasOwnProperty("labels") && event.check.labels.hasOwnProperty("contacts")) {
return false;
check_contacts = event.check.labels.contacts.split(",");
// filter out any elements which do not contain at least one non-whitespace character
check_contacts = check_contacts.filter(function(entry) { return /\S/.test(entry); });
}
else if (event.hasOwnProperty("entity") && event.entity.hasOwnProperty("labels") && event.entity.labels.hasOwnProperty("contacts")) {
return false;
} else {

if (event.hasOwnProperty("entity") && event.entity.hasOwnProperty("labels") && event.entity.labels.hasOwnProperty("contacts")) {
entity_contacts = event.entity.labels.contacts.split(",");
// filter out any elements which do not contain at least one non-whitespace character
entity_contacts = entity_contacts.filter(function(entry) { return /\S/.test(entry); });
}

if (check_contacts.length == 0 && entity_contacts.length == 0) {
return true;
} else {
return false;
}
}
}
14 changes: 13 additions & 1 deletion spec/no_contacts_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,16 @@ describe("no_contacts", function() {

expect(no_contacts(event)).toBe(true);
});
});

it("returns true when labels are empty strings", function() {
var event = {
check: {
labels: {
contacts: ""
}
}
}

expect(no_contacts(event)).toBe(true);
});
});

0 comments on commit a414eb9

Please sign in to comment.