From 8022f5c6b55d99765fbb102eb73cb5acbc5866f9 Mon Sep 17 00:00:00 2001 From: Anurag Date: Sat, 28 Jan 2023 20:18:16 +0530 Subject: [PATCH] chore: minor changes in pat info --- api/status/pat-info.js | 14 +++++++++++--- tests/pat-info.test.js | 9 ++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/api/status/pat-info.js b/api/status/pat-info.js index 720611d424919..775e06896427c 100644 --- a/api/status/pat-info.js +++ b/api/status/pat-info.js @@ -6,7 +6,7 @@ */ import { logger, request, dateDiff } from "../../src/common/utils.js"; -export const RATE_LIMIT_SECONDS = 60 * 10; // 1 request per 10 minutes +export const RATE_LIMIT_SECONDS = 60 * 5; // 1 request per 10 minutes /** * Simple uptime check fetcher for the PATs. @@ -98,12 +98,20 @@ const getPATInfo = async (fetcher, variables) => { return Object.keys(details).filter((pat) => details[pat].status === status); }; + const sortedDetails = Object.keys(details) + .sort() + .reduce((obj, key) => { + obj[key] = details[key]; + return obj; + }, {}); + return { validPATs: filterPATsByStatus("valid"), expiredPATs: filterPATsByStatus("expired"), - exhaustedPATS: filterPATsByStatus("exhausted"), + exhaustedPATs: filterPATsByStatus("exhausted"), + suspendedPATs: filterPATsByStatus("suspended"), errorPATs: filterPATsByStatus("error"), - details, + details: sortedDetails, }; }; diff --git a/tests/pat-info.test.js b/tests/pat-info.test.js index 9635ab24c837c..23aca8c40e5ca 100644 --- a/tests/pat-info.test.js +++ b/tests/pat-info.test.js @@ -88,7 +88,8 @@ describe("Test /api/status/pat-info", () => { { validPATs: ["PAT_2", "PAT_3", "PAT_4"], expiredPATs: [], - exhaustedPATS: ["PAT_1"], + exhaustedPATs: ["PAT_1"], + suspendedPATs: [], errorPATs: [], details: { PAT_1: { @@ -132,7 +133,8 @@ describe("Test /api/status/pat-info", () => { { validPATs: ["PAT_2", "PAT_3", "PAT_4"], expiredPATs: [], - exhaustedPATS: [], + exhaustedPATs: [], + suspendedPATs: [], errorPATs: ["PAT_1"], details: { PAT_1: { @@ -178,7 +180,8 @@ describe("Test /api/status/pat-info", () => { { validPATs: ["PAT_2", "PAT_3", "PAT_4"], expiredPATs: ["PAT_1"], - exhaustedPATS: [], + exhaustedPATs: [], + suspendedPATs: [], errorPATs: [], details: { PAT_1: {