Skip to content

Commit 14be93e

Browse files
chore: add coverage to common.service
1 parent 3279a1e commit 14be93e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

server/src/services/__tests__/common.service.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,38 @@ describe('common.service', () => {
223223
skip: 0,
224224
});
225225

226+
expect(result.data).toHaveLength(2);
227+
expect(mockCommentRepository.findWithCount).toHaveBeenCalled();
228+
});
229+
it('should return flat list of comments with populated user properties', async () => {
230+
const strapi = getStrapi();
231+
const service = getService(strapi);
232+
const mockComments = [
233+
{ id: 1, content: 'Comment 1', avatar: { url: 'avatar2.png' } },
234+
{ id: 2, content: 'Comment 2', avatar: { url: 'avatar2.png' } },
235+
];
236+
237+
mockCommentRepository.findWithCount.mockResolvedValue({
238+
results: mockComments,
239+
pagination: { total: 2 },
240+
});
241+
caster<jest.Mock>(getOrderBy).mockReturnValue(['createdAt', 'desc']);
242+
243+
mockStoreRepository.getConfig.mockResolvedValue([]);
244+
245+
const result = await service.findAllFlat({
246+
fields: ['id', 'content'],
247+
limit: 10,
248+
skip: 0,
249+
populate: {
250+
authorUser: {
251+
avatar: {
252+
populate: true
253+
}
254+
}
255+
}
256+
});
257+
226258
expect(result.data).toHaveLength(2);
227259
expect(mockCommentRepository.findWithCount).toHaveBeenCalled();
228260
});

0 commit comments

Comments
 (0)