@@ -2,6 +2,7 @@ import { EventNotification, SeveralEventsNotification } from 'hawk-worker-sender
22import { DecodedGroupedEvent , ProjectDBScheme } from '@hawk.so/types' ;
33import TelegramProvider from 'hawk-worker-telegram/src/provider' ;
44import templates from '../src/templates' ;
5+ import EventTpl from '../src/templates/event' ;
56import { ObjectId } from 'mongodb' ;
67
78/**
@@ -64,6 +65,54 @@ describe('TelegramProvider', () => {
6465
6566 expect ( message ) . toBeDefined ( ) ;
6667 } ) ;
68+ /**
69+ * Event URL should include repetitionId when provided
70+ */
71+ describe ( 'event URL contains correct repetitionId' , ( ) => {
72+ const eventId = new ObjectId ( '5d206f7f9aaf7c0071d64597' ) ;
73+ const projectId = new ObjectId ( '5d206f7f9aaf7c0071d64596' ) ;
74+ const host = 'https://garage.hawk.so' ;
75+
76+ const basePayload = {
77+ events : [ {
78+ event : {
79+ _id : eventId ,
80+ totalCount : 1 ,
81+ timestamp : Date . now ( ) ,
82+ payload : { title : 'Err' , backtrace : [ ] } ,
83+ } as DecodedGroupedEvent ,
84+ daysRepeated : 1 ,
85+ newCount : 1 ,
86+ } ] ,
87+ period : 60 ,
88+ host,
89+ hostOfStatic : '' ,
90+ project : {
91+ _id : projectId ,
92+ token : 'tok' ,
93+ name : 'P' ,
94+ workspaceId : projectId ,
95+ uidAdded : projectId ,
96+ notifications : [ ] ,
97+ } as ProjectDBScheme ,
98+ } ;
99+
100+ it ( 'should include repetitionId and /overview in URL when repetitionId is set' , ( ) => {
101+ const repetitionId = '5d206f7f9aaf7c0071d64599' ;
102+ const payload = { ...basePayload , events : [ { ...basePayload . events [ 0 ] , repetitionId } ] } ;
103+ const message = EventTpl ( payload ) ;
104+
105+ expect ( message ) . toContain ( `/event/${ eventId } /${ repetitionId } /overview` ) ;
106+ } ) ;
107+
108+ it ( 'should omit repetitionId from URL when repetitionId is not set' , ( ) => {
109+ const message = EventTpl ( basePayload ) ;
110+
111+ expect ( message ) . toContain ( `/event/${ eventId } /` ) ;
112+ expect ( message ) . not . toContain ( '/overview' ) ;
113+ } ) ;
114+ } ) ;
115+
67116 /**
68117 * Check that rendering of a several events message works without errors
69118 */
0 commit comments