File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,10 @@ describe('client.service', () => {
52
52
findOne : jest . fn ( ) ,
53
53
} ) ;
54
54
55
+ const mockEmailService = {
56
+ send : jest . fn ( ) ,
57
+ } ;
58
+
55
59
beforeEach ( ( ) => {
56
60
jest . clearAllMocks ( ) ;
57
61
caster < jest . Mock > ( getPluginService ) . mockReturnValue ( mockCommonService ) ;
@@ -220,6 +224,31 @@ describe('client.service', () => {
220
224
} ) ;
221
225
} ) ;
222
226
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
+
223
252
it ( 'should throw error when relation does not exist' , async ( ) => {
224
253
const strapi = getStrapi ( ) ;
225
254
const service = getService ( strapi ) ;
Original file line number Diff line number Diff line change @@ -294,10 +294,6 @@ export const clientService = ({ strapi }: StrapiContext) => {
294
294
const emailSender = await this . getCommonService ( ) . getConfig ( 'client.contactEmail' , superAdmin . email ) ;
295
295
const clientAppUrl = await this . getCommonService ( ) . getConfig ( 'client.url' , 'our site' ) ;
296
296
297
- if ( ! emailSender ) {
298
- return ;
299
- }
300
-
301
297
try {
302
298
await strapi
303
299
. plugin ( 'email' )
You can’t perform that action at this time.
0 commit comments