-
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.
Merge branch 'timeout-faq' of github.com:Enterprise-CMCS/macpro-mako …
…into timeout-faq
- Loading branch information
Showing
35 changed files
with
1,550 additions
and
158 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
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
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,50 @@ | ||
import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
import { getSystemNotifs } from "./getSystemNotifs"; | ||
import * as util from "shared-utils"; | ||
|
||
vi.mock("shared-utils", () => ({ | ||
getExport: vi.fn(), | ||
getSecret: vi.fn(), | ||
})); | ||
|
||
describe("notif handler", () => { | ||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
}); | ||
|
||
it("returns 200 and notifs if secret exists", async () => { | ||
vi.stubEnv("notificationSecretArn", "test_secret"); | ||
vi.spyOn(util, "getSecret").mockImplementation(async () => "[]"); | ||
const result = await getSystemNotifs(); | ||
expect(result.statusCode).toBe(200); | ||
expect(result.body).toBe("[]"); | ||
}); | ||
|
||
it("returns 200 and empty array if no notifs", async () => { | ||
vi.stubEnv("notificationSecretArn", "test_secret"); | ||
vi.spyOn(util, "getSecret").mockImplementation(async () => null as unknown as string); | ||
const result = await getSystemNotifs(); | ||
expect(result.statusCode).toBe(200); | ||
expect(result.body).toBe("[]"); | ||
}); | ||
|
||
it("returns 502 with specific error", async () => { | ||
vi.stubEnv("notificationSecretArn", "error"); | ||
vi.spyOn(util, "getSecret").mockImplementation(async () => { | ||
throw new Error("test error"); | ||
}); | ||
const result = await getSystemNotifs(); | ||
expect(result.statusCode).toBe(502); | ||
expect(JSON.parse(result.body).error).toBe("test error"); | ||
}); | ||
|
||
it("returns 502 with generic error", async () => { | ||
vi.stubEnv("notificationSecretArn", undefined); | ||
vi.spyOn(util, "getSecret").mockImplementation(async () => { | ||
throw new Error(); | ||
}); | ||
const result = await getSystemNotifs(); | ||
expect(result.statusCode).toBe(502); | ||
expect(JSON.parse(result.body).error).toBe("Internal server error"); | ||
}); | ||
}); |
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,23 @@ | ||
import { getSecret } from "shared-utils"; | ||
import { response } from "libs/handler-lib"; | ||
|
||
export const getSystemNotifs = async () => { | ||
try { | ||
const notifs = await getSecret(process.env.notificationSecretArn!); | ||
|
||
return response({ | ||
statusCode: 200, | ||
body: JSON.parse(notifs) || [], | ||
}); | ||
} catch (error: any) { | ||
console.error("Error:", error); | ||
return response({ | ||
statusCode: 502, | ||
body: { | ||
error: error.message ? error.message : "Internal server error", | ||
}, | ||
}); | ||
} | ||
}; | ||
|
||
export const handler = getSystemNotifs; |
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
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
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
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
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,9 @@ | ||
export interface BannerNotification { | ||
notifId: string; | ||
header: string; | ||
body: string; | ||
buttonText?: string; | ||
buttonLink?: string; | ||
pubDate: string; | ||
expDate?: string; | ||
} |
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
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
Oops, something went wrong.