Skip to content

Commit

Permalink
add no_contacts function to support fallback case (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Johnston authored Jun 18, 2019
1 parent 191959a commit c39b2b5
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/no_contacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function no_contacts(event) {
if (event.hasOwnProperty("check") && event.check.hasOwnProperty("labels") && event.check.labels.hasOwnProperty("contacts")) {
return false;
}
else if (event.hasOwnProperty("entity") && event.entity.hasOwnProperty("labels") && event.entity.labels.hasOwnProperty("contacts")) {
return false;
} else {
return true;
}
}
57 changes: 57 additions & 0 deletions spec/no_contacts_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
describe("no_contacts", function() {
it("returns true when event has no labels", function() {
var event = {}

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

it("returns true when event has only some of the expected labels", function() {
var event = {
check: {},
entity: {
labels: {}
}
};

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

it("returns false when event has only entity contacts", function() {
var event = {
check: {},
entity: {
labels: {
contacts: "foo,bar,baz"
}
}
};

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

it("returns false when event has only check contacts", function() {
var event = {
check: {
labels: {
contacts: "foo,bar,baz"
}
},
entity: {}
};

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

it("returns true when check and entity labels are empty", function() {
var event = {
check: {
labels: {}
},
entity: {
labels: {}
}
};

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

0 comments on commit c39b2b5

Please sign in to comment.