Skip to content

Commit

Permalink
Merge pull request #33 from brianphillips/fix-oncall-api-users
Browse files Browse the repository at this point in the history
fix(oncall-api): return all users from lowest escalation level
  • Loading branch information
t1agob authored Mar 1, 2024
2 parents fb013b7 + a1cdf32 commit 495e7c3
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
65 changes: 65 additions & 0 deletions src/apis/pagerduty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion src/apis/pagerduty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export async function getOncallUsers(escalationPolicy: string): Promise<PagerDut
});

const oncallsFiltered = oncallsSorted.filter((oncall) => {
return oncall.escalation_level === result.oncalls[0].escalation_level;
return oncall.escalation_level === oncallsSorted[0].escalation_level;
});

usersItem = [...oncallsFiltered]
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12300,9 +12300,9 @@ __metadata:
linkType: hard

"ip@npm:^2.0.0":
version: 2.0.0
resolution: "ip@npm:2.0.0"
checksum: cfcfac6b873b701996d71ec82a7dd27ba92450afdb421e356f44044ed688df04567344c36cbacea7d01b1c39a4c732dc012570ebe9bebfb06f27314bca625349
version: 2.0.1
resolution: "ip@npm:2.0.1"
checksum: d765c9fd212b8a99023a4cde6a558a054c298d640fec1020567494d257afd78ca77e37126b1a3ef0e053646ced79a816bf50621d38d5e768cdde0431fa3b0d35
languageName: node
linkType: hard

Expand Down

0 comments on commit 495e7c3

Please sign in to comment.