Skip to content

Commit f77535a

Browse files
committed
reverts
1 parent 4cf49be commit f77535a

File tree

2 files changed

+115
-1
lines changed

2 files changed

+115
-1
lines changed

.fernignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Specify files that shouldn't be modified by Fern
22
src/wrapper/
3-
test/wrapper/
3+
tests/wrapper/
44
src/index.ts
55
examples/
66
.vscode/

tests/wrapper/webhooks.test.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import {
2+
createWebhookSignature,
3+
verifyWebhookEventSignature,
4+
zWebhookSchema,
5+
zWebhookTimestamp,
6+
} from "../../src/wrapper/lib/webhooks";
7+
8+
describe("webhooks", () => {
9+
describe("parse", () => {
10+
test("timestamp", () => {
11+
expect(zWebhookTimestamp.parse("2025-05-25T09:22:22.269116+00:00")).toBeDefined();
12+
expect(zWebhookTimestamp.parse("2025-08-15T18:09:11.881540")).toBeDefined();
13+
});
14+
15+
test("agent.task.status_update", () => {
16+
const MOCK: unknown = {
17+
type: "agent.task.status_update",
18+
timestamp: "2025-05-25T09:22:22.269116+00:00",
19+
payload: {
20+
session_id: "cd9cc7bf-e3af-4181-80a2-73f083bc94b4",
21+
task_id: "5b73fb3f-a3cb-4912-be40-17ce9e9e1a45",
22+
status: "finished",
23+
metadata: {
24+
campaign: "q4-automation",
25+
team: "marketing",
26+
},
27+
},
28+
};
29+
30+
const response = zWebhookSchema.parse(MOCK);
31+
32+
expect(response).toBeDefined();
33+
});
34+
35+
test("test", () => {
36+
const MOCK: unknown = {
37+
type: "test",
38+
timestamp: "2025-05-25T09:22:22.269116+00:00",
39+
payload: { test: "ok" },
40+
};
41+
42+
const response = zWebhookSchema.parse(MOCK);
43+
44+
expect(response).toBeDefined();
45+
});
46+
47+
test("invalid", () => {
48+
const MOCK: unknown = {
49+
type: "invalid",
50+
timestamp: "2025-05-25T09:22:22.269116+00:00",
51+
payload: { test: "ok" },
52+
};
53+
54+
expect(() => zWebhookSchema.parse(MOCK)).toThrow();
55+
});
56+
});
57+
58+
describe("verify", () => {
59+
test("correctly calculates signature", async () => {
60+
const timestamp = "2025-05-26:22:22.269116+00:00";
61+
62+
const MOCK = {
63+
type: "agent.task.status_update",
64+
timestamp: "2025-05-25T09:22:22.269116+00:00",
65+
payload: {
66+
session_id: "cd9cc7bf-e3af-4181-80a2-73f083bc94b4",
67+
task_id: "5b73fb3f-a3cb-4912-be40-17ce9e9e1a45",
68+
status: "finished",
69+
metadata: {
70+
campaign: "q4-automation",
71+
team: "marketing",
72+
},
73+
},
74+
};
75+
76+
const signature = createWebhookSignature({
77+
payload: MOCK.payload,
78+
secret: "secret",
79+
timestamp,
80+
});
81+
82+
const validJSON = await verifyWebhookEventSignature(
83+
{
84+
body: MOCK,
85+
signature: signature,
86+
timestamp,
87+
},
88+
{ secret: "secret" },
89+
);
90+
91+
const validString = await verifyWebhookEventSignature(
92+
{
93+
body: JSON.stringify(MOCK),
94+
signature: signature,
95+
timestamp,
96+
},
97+
{ secret: "secret" },
98+
);
99+
100+
const invalid = await verifyWebhookEventSignature(
101+
{
102+
body: JSON.stringify(MOCK),
103+
signature: "invalid",
104+
timestamp,
105+
},
106+
{ secret: "secret" },
107+
);
108+
109+
expect(validJSON.ok).toBe(true);
110+
expect(validString.ok).toBe(true);
111+
expect(invalid.ok).toBe(false);
112+
});
113+
});
114+
});

0 commit comments

Comments
 (0)