-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add no_contacts function to support fallback case (#6)
- Loading branch information
Cameron Johnston
authored
Jun 18, 2019
1 parent
191959a
commit c39b2b5
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |