Skip to content

Commit

Permalink
entity contacts should be disregarded when check contacts are present (
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Johnston authored Jun 27, 2019
1 parent cc2439c commit 313e4d6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
13 changes: 7 additions & 6 deletions lib/has_contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ function has_contact(event, contact) {
if (check_contacts.indexOf(contact) >= 0) {
return true;
}
// allow the event if contact is present in entity contacts
else if (entity_contacts.indexOf(contact) >= 0) {

// allow the event if there are no check contacts and contact is present in entity contacts
if (check_contacts.length == 0 && entity_contacts.indexOf(contact) >= 0) {
return true;
// otherwise event is not allowed
} else {
return false;
}
}

// otherwise event is not allowed
return false;
}
20 changes: 19 additions & 1 deletion spec/has_contact_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,22 @@ describe("has_contact", function() {

expect(has_contact(event, contact)).toBe(true);
});
});

it("returns false when check has contacts which do not match and entity contains contacts that do match", function() {
var contact = "qux"
var event = {
entity: {
labels: {
contacts: `foo,${contact},bar`
}
},
check: {
labels: {
contacts: "baz"
}
}
}

expect(has_contact(event, contact)).toBe(false);
});
});

0 comments on commit 313e4d6

Please sign in to comment.