Skip to content

Commit ef7fadf

Browse files
Merge pull request #381 from VirtusLab-Open-Source/fix/design-system-instance
Fix/design system instance
2 parents bfb22da + 0ecd5fa commit ef7fadf

File tree

17 files changed

+1682
-326
lines changed

17 files changed

+1682
-326
lines changed
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { DesignSystemProvider } from '@strapi/design-system';
21
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
32
import { FC, ReactNode } from 'react';
4-
import { usePluginTheme } from '@sensinum/strapi-utils';
53
import { UserProvider } from '../../contexts/UserContext';
64

75
const queryClient = new QueryClient({
@@ -13,15 +11,11 @@ const queryClient = new QueryClient({
1311
},
1412
});
1513
export const CommonProviders: FC<{ children: ReactNode }> = ({ children }) => {
16-
const { theme } = usePluginTheme();
17-
1814
return (
1915
<QueryClientProvider client={queryClient}>
20-
<DesignSystemProvider theme={theme}>
21-
<UserProvider>
22-
{children}
23-
</UserProvider>
24-
</DesignSystemProvider>
16+
<UserProvider>
17+
{children}
18+
</UserProvider>
2519
</QueryClientProvider>
2620
);
2721
};

admin/src/utils/__tests__/getMessage.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ describe("getMessage()", () => {
3333
id: "comments.message.key",
3434
});
3535
});
36+
it("should handle config object with empty id (fallback to formattedId)", () => {
37+
expect(getMessage({ id: "" })).toEqual({
38+
defaultMessage: "",
39+
id: "comments.",
40+
});
41+
});
42+
it("should handle config object with props", () => {
43+
expect(
44+
getMessage(
45+
{
46+
id: "message.key",
47+
props: { count: 5 },
48+
},
49+
"default"
50+
)
51+
).toEqual({
52+
defaultMessage: "default",
53+
id: "comments.message.key",
54+
count: 5,
55+
});
56+
});
3657
it("should allow out of scope translates", () => {
3758
expect(
3859
getMessage(

admin/src/utils/__tests__/resolveCommentStatus.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,25 @@ describe('resolveCommentStatus()', () => {
5353
}),
5454
).toEqual("UNKNOWN");
5555
});
56+
it('should handle to review status when reviewFlowEnabled is true', () => {
57+
expect(
58+
resolveCommentStatus({
59+
removed: false,
60+
blocked: false,
61+
blockedThread: false,
62+
approvalStatus: 'PENDING',
63+
reviewFlowEnabled: true,
64+
}),
65+
).toEqual("TO_REVIEW");
66+
});
67+
it('should return OPEN when approvalStatus is null and no other conditions match', () => {
68+
expect(
69+
resolveCommentStatus({
70+
removed: false,
71+
blocked: false,
72+
blockedThread: false,
73+
approvalStatus: null,
74+
}),
75+
).toEqual("OPEN");
76+
});
5677
});

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "strapi-plugin-comments",
3-
"version": "3.2.1",
3+
"version": "3.2.2",
44
"description": "Strapi - Comments plugin",
55
"strapi": {
66
"name": "comments",
@@ -63,12 +63,12 @@
6363
"devDependencies": {
6464
"@jest/types": "29.5.x",
6565
"@sensinum/strapi-utils": "^1.0.10",
66-
"@strapi/plugin-cloud": "^5.33.4",
67-
"@strapi/plugin-graphql": "^5.33.4",
68-
"@strapi/plugin-users-permissions": "^5.33.4",
66+
"@strapi/plugin-cloud": "^5.37.0",
67+
"@strapi/plugin-graphql": "^5.37.0",
68+
"@strapi/plugin-users-permissions": "^5.37.0",
6969
"@strapi/sdk-plugin": "^5.3.2",
70-
"@strapi/strapi": "^5.33.4",
71-
"@strapi/types": "^5.33.4",
70+
"@strapi/strapi": "^5.37.0",
71+
"@strapi/types": "^5.37.0",
7272
"@types/jest": "^30.0.0",
7373
"@types/koa": "^2.15.0",
7474
"@types/minimatch": "3.0.5",

server/src/controllers/__tests__/admin.controller.test.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ describe('Admin controller', () => {
8888
expect(result).toEqual(expectedResult);
8989
expect(mockAdminService.findReports).toHaveBeenCalledWith(validatedData);
9090
});
91+
92+
it('should throw error when validation fails', async () => {
93+
const ctx = { query: {} } as RequestContext;
94+
const error = new Error('Validation failed');
95+
96+
caster<jest.Mock>(adminValidator.getReportFindReportsValidator).mockReturnValue({ left: error });
97+
98+
await expect(getController(getStrapi()).findReports(ctx)).rejects.toThrow();
99+
});
91100
});
92101

93102
describe('findOne', () => {
@@ -141,6 +150,15 @@ describe('Admin controller', () => {
141150
expect(result).toEqual(expectedResult);
142151
expect(mockAdminService.changeBlockedComment).toHaveBeenCalledWith('1', true);
143152
});
153+
154+
it('should throw error when validation fails', async () => {
155+
const ctx = { params: { id: 'invalid' } } as RequestContext<object, { id: string }>;
156+
const error = new Error('Validation failed');
157+
158+
caster<jest.Mock>(adminValidator.getIdValidator).mockReturnValue({ left: error });
159+
160+
await expect(getController(getStrapi()).blockComment(ctx)).rejects.toThrow();
161+
});
144162
});
145163

146164
describe('resolveAbuseReport', () => {
@@ -157,6 +175,15 @@ describe('Admin controller', () => {
157175
expect(result).toEqual(expectedResult);
158176
expect(mockAdminService.resolveAbuseReport).toHaveBeenCalledWith(validatedData);
159177
});
178+
179+
it('should throw error when validation fails', async () => {
180+
const ctx = { params: { id: 'invalid', reportId: '2' } } as RequestContext<object, { id: string; reportId: string }>;
181+
const error = new Error('Validation failed');
182+
183+
caster<jest.Mock>(adminValidator.getCommentResolveAbuseReportValidator).mockReturnValue({ left: error });
184+
185+
await expect(getController(getStrapi()).resolveAbuseReport(ctx)).rejects.toThrow();
186+
});
160187
});
161188

162189
describe('resolveCommentMultipleAbuseReports', () => {
@@ -209,6 +236,18 @@ describe('Admin controller', () => {
209236
expect(result).toEqual(expectedResult);
210237
expect(mockAdminService.postComment).toHaveBeenCalledWith(validatedData);
211238
});
239+
240+
it('should throw error when validation fails', async () => {
241+
const ctx = {
242+
params: { id: '1' },
243+
request: { body: { content: 'Test content', author: 'Test author' } }
244+
} as RequestContext<any, any>;
245+
const error = new Error('Validation failed');
246+
247+
caster<jest.Mock>(adminValidator.getCommentPostValidator).mockReturnValue({ left: error });
248+
249+
await expect(getController(getStrapi()).postComment(ctx)).rejects.toThrow();
250+
});
212251
});
213252

214253
describe('unblockComment', () => {
@@ -225,6 +264,15 @@ describe('Admin controller', () => {
225264
expect(result).toEqual(expectedResult);
226265
expect(mockAdminService.changeBlockedComment).toHaveBeenCalledWith('1', false);
227266
});
267+
268+
it('should throw error when validation fails', async () => {
269+
const ctx = { params: { id: 'invalid' } } as RequestContext<object, { id: string }>;
270+
const error = new Error('Validation failed');
271+
272+
caster<jest.Mock>(adminValidator.getIdValidator).mockReturnValue({ left: error });
273+
274+
await expect(getController(getStrapi()).unblockComment(ctx)).rejects.toThrow();
275+
});
228276
});
229277

230278
describe('deleteComment', () => {
@@ -241,6 +289,15 @@ describe('Admin controller', () => {
241289
expect(result).toEqual(expectedResult);
242290
expect(mockAdminService.deleteComment).toHaveBeenCalledWith('1');
243291
});
292+
293+
it('should throw error when validation fails', async () => {
294+
const ctx = { params: { id: 'invalid' } } as RequestContext<object, { id: string }>;
295+
const error = new Error('Validation failed');
296+
297+
caster<jest.Mock>(adminValidator.getIdValidator).mockReturnValue({ left: error });
298+
299+
await expect(getController(getStrapi()).deleteComment(ctx)).rejects.toThrow();
300+
});
244301
});
245302

246303
describe('blockCommentThread', () => {
@@ -257,6 +314,15 @@ describe('Admin controller', () => {
257314
expect(result).toEqual(expectedResult);
258315
expect(mockAdminService.blockCommentThread).toHaveBeenCalledWith('1', true);
259316
});
317+
318+
it('should throw error when validation fails', async () => {
319+
const ctx = { params: { id: 'invalid' } } as RequestContext<object, { id: string }>;
320+
const error = new Error('Validation failed');
321+
322+
caster<jest.Mock>(adminValidator.getIdValidator).mockReturnValue({ left: error });
323+
324+
await expect(getController(getStrapi()).blockCommentThread(ctx)).rejects.toThrow();
325+
});
260326
});
261327

262328
describe('unblockCommentThread', () => {
@@ -298,6 +364,15 @@ describe('Admin controller', () => {
298364
expect(result).toEqual(expectedResult);
299365
expect(mockAdminService.resolveAllAbuseReportsForComment).toHaveBeenCalledWith('1');
300366
});
367+
368+
it('should throw error when validation fails', async () => {
369+
const ctx = { params: { id: 'invalid' } } as RequestContext<object, { id: string }>;
370+
const error = new Error('Validation failed');
371+
372+
caster<jest.Mock>(adminValidator.getIdValidator).mockReturnValue({ left: error });
373+
374+
await expect(getController(getStrapi()).resolveAllAbuseReportsForComment(ctx)).rejects.toThrow();
375+
});
301376
});
302377

303378
describe('resolveAllAbuseReportsForThread', () => {
@@ -340,6 +415,16 @@ describe('Admin controller', () => {
340415
expect(result).toEqual(expectedResult);
341416
expect(mockAdminService.resolveMultipleAbuseReports).toHaveBeenCalledWith(reportIds);
342417
});
418+
419+
it('should throw error when validation fails', async () => {
420+
const reportIds = ['invalid'];
421+
const ctx = { request: { body: reportIds } } as RequestContext<Array<string>>;
422+
const error = new Error('Validation failed');
423+
424+
caster<jest.Mock>(adminValidator.getReportsMultipleAbuseValidator).mockReturnValue({ left: error });
425+
426+
await expect(getController(getStrapi()).resolveMultipleAbuseReports(ctx)).rejects.toThrow();
427+
});
343428
});
344429

345430
describe('updateComment', () => {
@@ -359,6 +444,18 @@ describe('Admin controller', () => {
359444
expect(result).toEqual(expectedResult);
360445
expect(mockAdminService.updateComment).toHaveBeenCalledWith(validatedData);
361446
});
447+
448+
it('should throw error when validation fails', async () => {
449+
const ctx = {
450+
params: { id: '1' },
451+
request: { body: { content: '' } }
452+
} as RequestContext<any, any>;
453+
const error = new Error('Validation failed');
454+
455+
caster<jest.Mock>(adminValidator.getUpdateCommentValidator).mockReturnValue({ left: error });
456+
457+
await expect(getController(getStrapi()).updateComment(ctx)).rejects.toThrow();
458+
});
362459
});
363460

364461
describe('approveComment', () => {
@@ -375,6 +472,15 @@ describe('Admin controller', () => {
375472
expect(result).toEqual(expectedResult);
376473
expect(mockAdminService.approveComment).toHaveBeenCalledWith('1');
377474
});
475+
476+
it('should throw error when validation fails', async () => {
477+
const ctx = { params: { id: 'invalid' } } as RequestContext<any, any>;
478+
const error = new Error('Validation failed');
479+
480+
caster<jest.Mock>(adminValidator.getIdValidator).mockReturnValue({ left: error });
481+
482+
await expect(getController(getStrapi()).approveComment(ctx)).rejects.toThrow();
483+
});
378484
});
379485

380486
describe('rejectComment', () => {
@@ -391,5 +497,14 @@ describe('Admin controller', () => {
391497
expect(result).toEqual(expectedResult);
392498
expect(mockAdminService.rejectComment).toHaveBeenCalledWith('1');
393499
});
500+
501+
it('should throw error when validation fails', async () => {
502+
const ctx = { params: { id: 'invalid' } } as RequestContext<any, any>;
503+
const error = new Error('Validation failed');
504+
505+
caster<jest.Mock>(adminValidator.getIdValidator).mockReturnValue({ left: error });
506+
507+
await expect(getController(getStrapi()).rejectComment(ctx)).rejects.toThrow();
508+
});
394509
});
395510
});

0 commit comments

Comments
 (0)