Skip to content

Commit f9cd012

Browse files
committed
Do not display duration if it's < 1s and update tests
1 parent 4f3ec82 commit f9cd012

File tree

2 files changed

+16
-38
lines changed

2 files changed

+16
-38
lines changed

apps/meteor/server/services/media-call/getHistoryMessagePayload.spec.ts

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -57,58 +57,49 @@ describe('callStateToIcon', () => {
5757

5858
describe('getFormattedCallDuration', () => {
5959
it('should return undefined when callDuration is undefined', () => {
60-
const result = getFormattedCallDuration(undefined, 'ended');
60+
const result = getFormattedCallDuration(undefined);
6161
expect(result).toBeUndefined();
6262
});
6363

64-
it('should return 00:00 when callDuration is 0', () => {
65-
const result = getFormattedCallDuration(0, 'ended');
66-
expect(result).toEqual({ type: 'mrkdwn', text: '*00:00*' });
64+
it('should return undefined when callDuration is 0', () => {
65+
const result = getFormattedCallDuration(0);
66+
expect(result).toBeUndefined();
6767
});
6868

6969
it('should format duration correctly for seconds only (less than 60 seconds)', () => {
70-
const result = getFormattedCallDuration(30, 'ended');
70+
const result = getFormattedCallDuration(30);
7171
expect(result).toEqual({ type: 'mrkdwn', text: '*00:30*' });
7272
});
7373

7474
it('should format duration correctly for minutes and seconds (less than 1 hour)', () => {
75-
const result = getFormattedCallDuration(125, 'ended'); // 2 minutes 5 seconds
75+
const result = getFormattedCallDuration(125); // 2 minutes 5 seconds
7676
expect(result).toEqual({ type: 'mrkdwn', text: '*02:05*' });
7777
});
7878

7979
it('should format duration correctly for exactly 1 minute', () => {
80-
const result = getFormattedCallDuration(60, 'ended');
80+
const result = getFormattedCallDuration(60);
8181
expect(result).toEqual({ type: 'mrkdwn', text: '*01:00*' });
8282
});
8383

8484
it('should format duration correctly for hours, minutes, and seconds', () => {
85-
const result = getFormattedCallDuration(3665, 'ended'); // 1 hour 1 minute 5 seconds
85+
const result = getFormattedCallDuration(3665); // 1 hour 1 minute 5 seconds
8686
expect(result).toEqual({ type: 'mrkdwn', text: '*01:01:05*' });
8787
});
8888

8989
it('should format duration correctly for multiple hours', () => {
90-
const result = getFormattedCallDuration(7325, 'ended'); // 2 hours 2 minutes 5 seconds
90+
const result = getFormattedCallDuration(7325); // 2 hours 2 minutes 5 seconds
9191
expect(result).toEqual({ type: 'mrkdwn', text: '*02:02:05*' });
9292
});
9393

9494
it('should pad single digit values with zeros', () => {
95-
const result = getFormattedCallDuration(61, 'ended'); // 1 minute 1 second
95+
const result = getFormattedCallDuration(61); // 1 minute 1 second
9696
expect(result).toEqual({ type: 'mrkdwn', text: '*01:01*' });
9797
});
9898

9999
it('should handle large durations correctly', () => {
100-
const result = getFormattedCallDuration(36661, 'ended'); // 10 hours 11 minutes 1 second
100+
const result = getFormattedCallDuration(36661); // 10 hours 11 minutes 1 second
101101
expect(result).toEqual({ type: 'mrkdwn', text: '*10:11:01*' });
102102
});
103-
104-
it('should return undefined when callState is not "ended" or "transferred"', () => {
105-
const resultNotAnswered = getFormattedCallDuration(125, 'not-answered');
106-
const resultFailed = getFormattedCallDuration(125, 'failed');
107-
const resultError = getFormattedCallDuration(125, 'error');
108-
expect(resultNotAnswered).toBeUndefined();
109-
expect(resultFailed).toBeUndefined();
110-
expect(resultError).toBeUndefined();
111-
});
112103
});
113104

114105
describe('getHistoryMessagePayload', () => {
@@ -270,11 +261,10 @@ describe('getHistoryMessagePayload', () => {
270261
});
271262

272263
it('should handle all call states with duration correctly', () => {
273-
const activeStates = ['ended', 'transferred'] as const;
274-
const notActiveStates = ['not-answered', 'failed', 'error'] as const;
264+
const states = ['ended', 'transferred', 'not-answered', 'failed', 'error'] as const;
275265
const duration = 125;
276266

277-
activeStates.forEach((state) => {
267+
states.forEach((state) => {
278268
const result = getHistoryMessagePayload(state, duration);
279269
expect(result.msg).toBe('');
280270
expect(result.groupable).toBe(false);
@@ -284,13 +274,5 @@ describe('getHistoryMessagePayload', () => {
284274
expect(result.blocks[0].rows[1].background).toBe('secondary');
285275
expect(result.blocks[0].rows[1].elements[0].type).toBe('mrkdwn');
286276
});
287-
notActiveStates.forEach((state) => {
288-
const result = getHistoryMessagePayload(state, duration);
289-
expect(result.msg).toBe('');
290-
expect(result.groupable).toBe(false);
291-
expect(result.blocks).toHaveLength(1);
292-
expect(result.blocks[0].type).toBe('info_card');
293-
expect(result.blocks[0].rows).toHaveLength(1);
294-
});
295277
});
296278
});

apps/meteor/server/services/media-call/getHistoryMessagePayload.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,8 @@ const buildDurationString = (...values: number[]): string => {
3737
return values.map((value) => value.toString().padStart(2, '0')).join(':');
3838
};
3939

40-
export const getFormattedCallDuration = (callDuration: number | undefined, callState: CallHistoryItemState): TextObject | undefined => {
41-
if (callState !== 'ended' && callState !== 'transferred') {
42-
return undefined;
43-
}
44-
45-
if (typeof callDuration !== 'number') {
40+
export const getFormattedCallDuration = (callDuration: number | undefined): TextObject | undefined => {
41+
if (!callDuration || typeof callDuration !== 'number') {
4642
return undefined;
4743
}
4844

@@ -66,7 +62,7 @@ export const getHistoryMessagePayload = (
6662
): Pick<IMessage, 'msg' | 'groupable'> & { blocks: [InfoCardBlock] } => {
6763
const callStateTranslationKey = callStateToTranslationKey(callState);
6864
const icon = callStateToIcon(callState);
69-
const callDurationFormatted = getFormattedCallDuration(callDuration, callState);
65+
const callDurationFormatted = getFormattedCallDuration(callDuration);
7066

7167
return {
7268
msg: '',

0 commit comments

Comments
 (0)