-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(oncall-api): return all users from lowest escalation level
Instead of return all users that match the escalation level of the first user returned in the oncall list, return users that match the lowest escalation level. Previously, if a higher escalation level user was the first item in the array, only users at that same level would be returned. Fixes PagerDuty/backstage-plugin#77
- Loading branch information
1 parent
44e5600
commit a1cdf32
Showing
2 changed files
with
66 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -754,6 +754,71 @@ describe("PagerDuty API", () => { | |
expect(fetch).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it.each(testInputs)("should return relevant users from escalation policy level 1 even if another level is returned first", async () => { | ||
const escalationPolicyId = "12345"; | ||
const expectedResponse = [ | ||
{ | ||
id: "userId1", | ||
name: "John Doe", | ||
email: "[email protected]", | ||
avatar_url: "https://example.pagerduty.com/avatars/123", | ||
html_url: "https://example.pagerduty.com/users/123", | ||
summary: "John Doe", | ||
} | ||
]; | ||
|
||
const mockAPIResponse = { | ||
"oncalls": [ | ||
{ | ||
"user": { | ||
"id": "userId3", | ||
"summary": "Jane Doe", | ||
"name": "Jane Doe", | ||
"email": "[email protected]", | ||
"avatar_url": "https://example.pagerduty.com/avatars/123", | ||
"html_url": "https://example.pagerduty.com/users/123", | ||
}, | ||
"escalation_level": 3 | ||
}, | ||
{ | ||
"user": { | ||
"id": expectedResponse[0].id, | ||
"summary": expectedResponse[0].summary, | ||
"name": expectedResponse[0].name, | ||
"email": expectedResponse[0].email, | ||
"avatar_url": expectedResponse[0].avatar_url, | ||
"html_url": expectedResponse[0].html_url, | ||
}, | ||
"escalation_level": 1 | ||
}, | ||
{ | ||
"user": { | ||
"id": "userId2", | ||
"summary": "James Doe", | ||
"name": "James Doe", | ||
"email": "[email protected]", | ||
"avatar_url": "https://example.pagerduty.com/avatars/123", | ||
"html_url": "https://example.pagerduty.com/users/123", | ||
}, | ||
"escalation_level": 2 | ||
} | ||
] | ||
}; | ||
|
||
global.fetch = jest.fn(() => | ||
Promise.resolve({ | ||
status: 200, | ||
json: () => Promise.resolve(mockAPIResponse) | ||
}) | ||
) as jest.Mock; | ||
|
||
const result = await getOncallUsers(escalationPolicyId); | ||
|
||
expect(result).toEqual(expectedResponse); | ||
expect(result.length).toEqual(1); | ||
expect(fetch).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it.each(testInputs)("should return list of users ordered by name ASC from other escalation levels when level 1 is empty", async () => { | ||
const escalationPolicyId = "12345"; | ||
const expectedResponse = [ | ||
|
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