Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hawk.workers",
"private": true,
"version": "0.1.3",
"version": "0.1.4",
"description": "Hawk workers",
"repository": "git@github.com:codex-team/hawk.workers.git",
"license": "BUSL-1.1",
Expand Down
3 changes: 2 additions & 1 deletion workers/loop/src/templates/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function renderBacktrace(event: GroupedEventDBScheme): string {
export default function render(tplData: EventsTemplateVariables): string {
const eventInfo = tplData.events[0] as TemplateEventData;
const event = eventInfo.event;
const eventURL = tplData.host + '/project/' + tplData.project._id + '/event/' + event._id + '/';
const repetitionId = eventInfo.repetitionId;
const eventURL = tplData.host + '/project/' + tplData.project._id + '/event/' + event._id + '/' + (repetitionId ? repetitionId + '/overview' : '');
let location = 'Неизвестное место';

if (event.payload.backtrace && event.payload.backtrace.length > 0) {
Expand Down
48 changes: 48 additions & 0 deletions workers/loop/tests/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,54 @@ describe('LoopProvider', () => {
expect(message).toBeDefined();
});

/**
* Event URL should include repetitionId when provided
*/
describe('event URL contains correct repetitionId', () => {
const eventId = new ObjectId('5d206f7f9aaf7c0071d64597');
const projectId = new ObjectId('5d206f7f9aaf7c0071d64596');
const host = 'https://garage.hawk.so';

const basePayload = {
events: [ {
event: {
_id: eventId,
totalCount: 1,
timestamp: Date.now(),
payload: { title: 'Err', backtrace: [] },
} as DecodedGroupedEvent,
daysRepeated: 1,
newCount: 1,
} ],
period: 60,
host,
hostOfStatic: '',
project: {
_id: projectId,
token: 'tok',
name: 'P',
workspaceId: projectId,
uidAdded: projectId,
notifications: [],
} as ProjectDBScheme,
};

it('should include repetitionId and /overview in URL when repetitionId is set', () => {
const repetitionId = '5d206f7f9aaf7c0071d64599';
const payload = { ...basePayload, events: [ { ...basePayload.events[0], repetitionId } ] };
const message = templates.EventTpl(payload);

expect(message).toContain(`/event/${eventId}/${repetitionId}/overview`);
});

it('should omit repetitionId from URL when repetitionId is not set', () => {
const message = templates.EventTpl(basePayload);

expect(message).toContain(`/event/${eventId}/`);
expect(message).not.toContain('/overview');
});
});

/**
* Check that rendering of a several events message works without errors
*/
Expand Down
2 changes: 1 addition & 1 deletion workers/slack/src/templates/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function renderBacktrace(event: GroupedEventDBScheme): string {
export default function render(tplData: EventsTemplateVariables): IncomingWebhookSendArguments {
const eventInfo = tplData.events[0] as TemplateEventData;
const event = eventInfo.event;
const eventURL = getEventUrl(tplData.host, tplData.project, event);
const eventURL = getEventUrl(tplData.host, tplData.project, event, eventInfo.repetitionId);
const location = getEventLocation(event);

const blocks = [
Expand Down
7 changes: 5 additions & 2 deletions workers/slack/src/templates/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ export function getEventLocation(event: DecodedGroupedEvent): string {
* @param host - garage host. Also, can be accessed from process.env.GARAGE_URL
* @param project - parent project
* @param event - event to compose its URL
* @param repetitionId - id of the specific repetition that triggered the notification
*/
export function getEventUrl(host: string, project: ProjectDBScheme, event: GroupedEventDBScheme): string {
return host + '/project/' + project._id + '/event/' + event._id + '/';
export function getEventUrl(host: string, project: ProjectDBScheme, event: GroupedEventDBScheme, repetitionId?: string | null): string {
const base = host + '/project/' + project._id + '/event/' + event._id + '/';

return repetitionId ? base + repetitionId + '/overview' : base;
}

/**
Expand Down
40 changes: 40 additions & 0 deletions workers/slack/tests/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ObjectId } from 'mongodb';
import { ProjectDBScheme, GroupedEventDBScheme } from '@hawk.so/types';
import { getEventUrl } from '../src/templates/utils';

const project = {
_id: new ObjectId('5d206f7f9aaf7c0071d64596'),
token: 'project-token',
name: 'Project',
workspaceId: new ObjectId('5d206f7f9aaf7c0071d64596'),
uidAdded: new ObjectId('5d206f7f9aaf7c0071d64596'),
notifications: [],
} as ProjectDBScheme;

const event = {
_id: new ObjectId('5d206f7f9aaf7c0071d64597'),
payload: { title: 'Error' },
} as unknown as GroupedEventDBScheme;

const host = 'https://garage.hawk.so';

describe('getEventUrl', () => {
it('should return base URL with trailing slash when no repetitionId', () => {
const url = getEventUrl(host, project, event);

expect(url).toBe(`${host}/project/${project._id}/event/${event._id}/`);
});

it('should return base URL with trailing slash when repetitionId is null', () => {
const url = getEventUrl(host, project, event, null);

expect(url).toBe(`${host}/project/${project._id}/event/${event._id}/`);
});

it('should append repetitionId and /overview when repetitionId is provided', () => {
const repetitionId = '5d206f7f9aaf7c0071d64599';
const url = getEventUrl(host, project, event, repetitionId);

expect(url).toBe(`${host}/project/${project._id}/event/${event._id}/${repetitionId}/overview`);
});
});
3 changes: 2 additions & 1 deletion workers/telegram/src/templates/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import type { EventsTemplateVariables, TemplateEventData } from 'hawk-worker-sen
export default function render(tplData: EventsTemplateVariables): string {
const eventInfo = tplData.events[0] as TemplateEventData;
const event = eventInfo.event;
const eventURL = tplData.host + '/project/' + tplData.project._id + '/event/' + event._id + '/';
const repetitionId = eventInfo.repetitionId;
const eventURL = tplData.host + '/project/' + tplData.project._id + '/event/' + event._id + '/' + (repetitionId ? repetitionId + '/overview' : '');
let location = '';

if (event.payload.backtrace && event.payload.backtrace.length > 0) {
Expand Down
49 changes: 49 additions & 0 deletions workers/telegram/tests/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EventNotification, SeveralEventsNotification } from 'hawk-worker-sender
import { DecodedGroupedEvent, ProjectDBScheme } from '@hawk.so/types';
import TelegramProvider from 'hawk-worker-telegram/src/provider';
import templates from '../src/templates';
import EventTpl from '../src/templates/event';
import { ObjectId } from 'mongodb';

/**
Expand Down Expand Up @@ -64,6 +65,54 @@ describe('TelegramProvider', () => {

expect(message).toBeDefined();
});
/**
* Event URL should include repetitionId when provided
*/
describe('event URL contains correct repetitionId', () => {
const eventId = new ObjectId('5d206f7f9aaf7c0071d64597');
const projectId = new ObjectId('5d206f7f9aaf7c0071d64596');
const host = 'https://garage.hawk.so';

const basePayload = {
events: [ {
event: {
_id: eventId,
totalCount: 1,
timestamp: Date.now(),
payload: { title: 'Err', backtrace: [] },
} as DecodedGroupedEvent,
daysRepeated: 1,
newCount: 1,
} ],
period: 60,
host,
hostOfStatic: '',
project: {
_id: projectId,
token: 'tok',
name: 'P',
workspaceId: projectId,
uidAdded: projectId,
notifications: [],
} as ProjectDBScheme,
};

it('should include repetitionId and /overview in URL when repetitionId is set', () => {
const repetitionId = '5d206f7f9aaf7c0071d64599';
const payload = { ...basePayload, events: [ { ...basePayload.events[0], repetitionId } ] };
const message = EventTpl(payload);

expect(message).toContain(`/event/${eventId}/${repetitionId}/overview`);
});

it('should omit repetitionId from URL when repetitionId is not set', () => {
const message = EventTpl(basePayload);

expect(message).toContain(`/event/${eventId}/`);
expect(message).not.toContain('/overview');
});
});

/**
* Check that rendering of a several events message works without errors
*/
Expand Down
Loading