Skip to content

Commit 4029f33

Browse files
authored
Update linkry edge redirect unit tests (#411)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Enhanced test coverage with additional host-specific scenarios to verify response handling consistency across different configurations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 26bcec3 commit 4029f33

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

tests/unit/linkryEdgeFunction/main.test.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe("CloudFront Lambda@Edge Handler", () => {
8686
});
8787

8888
describe("Successful redirect from DynamoDB", () => {
89-
it("should return 302 redirect when link is found in DynamoDB", async () => {
89+
it("should return 302 redirect when link is found in DynamoDB for go.acm", async () => {
9090
const redirectUrl = "https://example.com/target";
9191
dynamoMock.on(QueryCommand).resolves({
9292
Items: [
@@ -98,7 +98,35 @@ describe("CloudFront Lambda@Edge Handler", () => {
9898
],
9999
});
100100

101-
const event = createEvent("/test-link");
101+
const event = createEvent("/test-link", "go.acm.illinois.edu");
102+
const result = await handler(event);
103+
assertIsResponse(result);
104+
105+
expect(result).toEqual({
106+
status: "302",
107+
statusDescription: "Found",
108+
headers: {
109+
location: [{ key: "Location", value: redirectUrl }],
110+
"cache-control": [
111+
{ key: "Cache-Control", value: "public, max-age=30" },
112+
],
113+
},
114+
});
115+
});
116+
117+
it("should return 302 redirect when link is found in DynamoDB for acm.gg", async () => {
118+
const redirectUrl = "https://example.com/target";
119+
dynamoMock.on(QueryCommand).resolves({
120+
Items: [
121+
{
122+
slug: { S: "testgg" },
123+
access: { S: "OWNER#user123" },
124+
redirect: { S: redirectUrl },
125+
},
126+
],
127+
});
128+
129+
const event = createEvent("/testgg", "acm.gg");
102130
const result = await handler(event);
103131
assertIsResponse(result);
104132

0 commit comments

Comments
 (0)