Skip to content

Commit ef40375

Browse files
committed
feat(webhook): add assignee information to webhook payload and update related tests
1 parent 77d1f32 commit ef40375

File tree

6 files changed

+37
-7
lines changed

6 files changed

+37
-7
lines changed

workers/sender/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ export default abstract class SenderWorker extends Worker {
253253
project,
254254
event,
255255
whoAssigned,
256+
assignee,
256257
daysRepeated,
257258
},
258259
} as AssigneeNotification);

workers/sender/types/template-variables/assignee.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export interface AssigneeTemplateVariables extends CommonTemplateVariables {
2121
*/
2222
whoAssigned: UserDBScheme;
2323

24+
/**
25+
* User who was assigned to resolve the event
26+
*/
27+
assignee: UserDBScheme;
28+
2429
/**
2530
* Number of event repetitions
2631
*/

workers/webhook/src/deliverer.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,23 @@ export default class WebhookDeliverer {
4747
* @param delivery - webhook delivery { type, payload }
4848
*/
4949
public async deliver(endpoint: string, delivery: WebhookDelivery): Promise<void> {
50+
let url: URL;
51+
52+
try {
53+
url = new URL(endpoint);
54+
} catch {
55+
this.logger.log('error', `Webhook delivery skipped — invalid URL: ${endpoint}`);
56+
57+
return;
58+
}
59+
60+
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
61+
this.logger.log('error', `Webhook delivery skipped — unsupported protocol: ${url.protocol}`);
62+
63+
return;
64+
}
65+
5066
const body = JSON.stringify(delivery);
51-
const url = new URL(endpoint);
5267
const transport = url.protocol === 'https:' ? https : http;
5368

5469
return new Promise<void>((resolve) => {

workers/webhook/src/templates/generic.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ const projectors: Record<string, PayloadProjector> = {
120120
'assignee': (p) => ({
121121
project: p.project ? projectDTO(p.project as ProjectDBScheme) : null,
122122
event: p.event ? eventDTO(p.event as DecodedGroupedEvent) : null,
123-
whoAssigned: p.whoAssigned ? userDTO(p.whoAssigned as UserDBScheme) : null,
123+
assignedBy: p.whoAssigned ? userDTO(p.whoAssigned as UserDBScheme) : null,
124+
assignee: p.assignee ? userDTO(p.assignee as UserDBScheme) : null,
124125
daysRepeated: p.daysRepeated ?? null,
125126
}),
126127

workers/webhook/tests/__mocks__/assignee-notify.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export default {
2828
name: 'John Doe',
2929
email: 'john@example.com',
3030
},
31+
assignee: {
32+
name: 'Jane Smith',
33+
email: 'jane@example.com',
34+
},
3135
daysRepeated: 3,
3236
},
3337
} as AssigneeNotification;

workers/webhook/tests/provider.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,16 +283,20 @@ describe('WebhookProvider', () => {
283283
});
284284
});
285285

286-
it('should include whoAssigned DTO for "assignee"', async () => {
286+
it('should include assignedBy, assignee and event DTOs for "assignee"', async () => {
287287
const provider = new WebhookProvider();
288288

289289
await provider.send(webhookEndpointSample, AssigneeNotifyMock);
290290

291291
const payload = getDeliveredPayload();
292-
const who = payload.whoAssigned as Record<string, unknown>;
293-
294-
expect(who).toHaveProperty('name', 'John Doe');
295-
expect(who).toHaveProperty('email', 'john@example.com');
292+
const assignedBy = payload.assignedBy as Record<string, unknown>;
293+
const assignee = payload.assignee as Record<string, unknown>;
294+
295+
expect(assignedBy).toHaveProperty('name', 'John Doe');
296+
expect(assignedBy).toHaveProperty('email', 'john@example.com');
297+
expect(assignee).toHaveProperty('name', 'Jane Smith');
298+
expect(assignee).toHaveProperty('email', 'jane@example.com');
299+
expect(payload).toHaveProperty('event');
296300
expect(payload).toHaveProperty('daysRepeated', 3);
297301
});
298302

0 commit comments

Comments
 (0)