Skip to content

Commit 9c765e3

Browse files
committed
cover empty and blank title with test
1 parent b63db31 commit 9c765e3

1 file changed

Lines changed: 25 additions & 15 deletions

File tree

test/resolvers/project-daily-events-portion.test.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ describe('Project resolver dailyEventsPortion', () => {
119119
);
120120
});
121121

122-
it('should apply fallback title when payload title is missing and log warning', async () => {
123-
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
122+
it('should apply fallback title for null, empty and blank payload titles', async () => {
124123
const findDailyEventsPortion = jest.fn().mockResolvedValue({
125124
nextCursor: null,
126125
dailyEvents: [
@@ -135,6 +134,28 @@ describe('Project resolver dailyEventsPortion', () => {
135134
},
136135
},
137136
},
137+
{
138+
id: 'daily-2',
139+
groupHash: 'group-2',
140+
event: {
141+
_id: 'repetition-2',
142+
originalEventId: 'event-2',
143+
payload: {
144+
title: '',
145+
},
146+
},
147+
},
148+
{
149+
id: 'daily-3',
150+
groupHash: 'group-3',
151+
event: {
152+
_id: 'repetition-3',
153+
originalEventId: 'event-3',
154+
payload: {
155+
title: ' ',
156+
},
157+
},
158+
},
138159
],
139160
});
140161
(getEventsFactory as unknown as jest.Mock).mockReturnValue({
@@ -155,19 +176,8 @@ describe('Project resolver dailyEventsPortion', () => {
155176
};
156177

157178
expect(result.dailyEvents[0].event.payload.title).toBe('Unknown');
158-
expect(warnSpy).toHaveBeenCalledTimes(1);
159-
expect(warnSpy).toHaveBeenCalledWith(
160-
'[ProjectResolver.dailyEventsPortion] Missing event payload title. Fallback title applied.',
161-
expect.objectContaining({
162-
projectId: 'project-1',
163-
dailyEventId: 'daily-1',
164-
dailyEventGroupHash: 'group-1',
165-
eventOriginalId: 'event-1',
166-
eventId: 'repetition-1',
167-
})
168-
);
169-
170-
warnSpy.mockRestore();
179+
expect(result.dailyEvents[1].event.payload.title).toBe('Unknown');
180+
expect(result.dailyEvents[2].event.payload.title).toBe('Unknown');
171181
});
172182

173183
it('should keep payload title when it is valid', async () => {

0 commit comments

Comments
 (0)