From c39b2b57956e9030782b776742b0432c60506a19 Mon Sep 17 00:00:00 2001 From: Cameron Johnston Date: Tue, 18 Jun 2019 09:23:50 -0600 Subject: [PATCH] add no_contacts function to support fallback case (#6) --- lib/no_contacts.js | 10 +++++++ spec/no_contacts_spec.js | 57 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 lib/no_contacts.js create mode 100644 spec/no_contacts_spec.js diff --git a/lib/no_contacts.js b/lib/no_contacts.js new file mode 100644 index 0000000..ea1fa8a --- /dev/null +++ b/lib/no_contacts.js @@ -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; + } +} \ No newline at end of file diff --git a/spec/no_contacts_spec.js b/spec/no_contacts_spec.js new file mode 100644 index 0000000..6870c6e --- /dev/null +++ b/spec/no_contacts_spec.js @@ -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); + }); +}); \ No newline at end of file