Skip to content

Commit 3279a1e

Browse files
chore: add coverage to client.service
1 parent 9b78310 commit 3279a1e

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ describe('client.service', () => {
5252
findOne: jest.fn(),
5353
});
5454

55+
const mockEmailService = {
56+
send: jest.fn(),
57+
};
58+
5559
beforeEach(() => {
5660
jest.clearAllMocks();
5761
caster<jest.Mock>(getPluginService).mockReturnValue(mockCommonService);
@@ -220,6 +224,31 @@ describe('client.service', () => {
220224
});
221225
});
222226

227+
it('should throw error when no user is provided', async () => {
228+
const strapi = getStrapi();
229+
const service = getService(strapi);
230+
231+
const mockEntity = { id: 1, content: 'Test comment' };
232+
const mockSanitizedEntity = { id: 1, content: 'Clean comment' };
233+
234+
mockCommonService.parseRelationString.mockReturnValue({
235+
uid: 'api::test.test',
236+
relatedId: '1',
237+
});
238+
mockFindOne.mockResolvedValue({ id: 1 });
239+
mockCommonService.getConfig.mockResolvedValue([]);
240+
mockCommonService.isValidUserContext.mockReturnValue(false);
241+
mockCommonService.checkBadWords.mockResolvedValue('Test comment');
242+
mockCommentRepository.create.mockResolvedValue(mockEntity);
243+
mockCommonService.sanitizeCommentEntity.mockReturnValue(
244+
mockSanitizedEntity
245+
);
246+
247+
await expect(service.create(mockPayload)).rejects.toThrow(
248+
PluginError
249+
);
250+
});
251+
223252
it('should throw error when relation does not exist', async () => {
224253
const strapi = getStrapi();
225254
const service = getService(strapi);

server/src/services/client.service.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,6 @@ export const clientService = ({ strapi }: StrapiContext) => {
294294
const emailSender = await this.getCommonService().getConfig('client.contactEmail', superAdmin.email);
295295
const clientAppUrl = await this.getCommonService().getConfig('client.url', 'our site');
296296

297-
if (!emailSender) {
298-
return;
299-
}
300-
301297
try {
302298
await strapi
303299
.plugin('email')

0 commit comments

Comments
 (0)