Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn test:unit
npm run test:unit
15 changes: 8 additions & 7 deletions server/src/controllers/__tests__/admin.controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jest.mock('../../utils/getPluginService', () => ({
getPluginService: jest.fn(),
}));


jest.mock('../../validators/api', () => ({
admin: {
getCommentFindAllValidator: jest.fn(),
Expand Down Expand Up @@ -35,7 +36,7 @@ describe('Admin controller', () => {
resolveAllAbuseReportsForComment: jest.fn(),
resolveAllAbuseReportsForThread: jest.fn(),
resolveMultipleAbuseReports: jest.fn(),
postComment: jest.fn(),
postCommentThread: jest.fn(),
updateComment: jest.fn(),
approveComment: jest.fn(),
rejectComment: jest.fn(),
Expand Down Expand Up @@ -219,8 +220,8 @@ describe('Admin controller', () => {
});
});

describe('postComment', () => {
it('should post comment when validation passes', async () => {
describe('postCommentThread', () => {
it('should post comment to thread when validation passes', async () => {
const ctx = {
params: { id: '1' },
request: { body: { content: 'Test content', author: 'Test author' } }
Expand All @@ -229,12 +230,12 @@ describe('Admin controller', () => {
const expectedResult = { id: 1, content: 'Test content' };

caster<jest.Mock>(adminValidator.getCommentPostValidator).mockReturnValue({ right: validatedData });
mockAdminService.postComment.mockResolvedValue(expectedResult);
mockAdminService.postCommentThread.mockResolvedValue(expectedResult);

const result = await getController(getStrapi()).postComment(ctx);
const result = await getController(getStrapi()).postCommentThread(ctx);

expect(result).toEqual(expectedResult);
expect(mockAdminService.postComment).toHaveBeenCalledWith(validatedData);
expect(mockAdminService.postCommentThread).toHaveBeenCalledWith(validatedData);
});

it('should throw error when validation fails', async () => {
Expand All @@ -246,7 +247,7 @@ describe('Admin controller', () => {

caster<jest.Mock>(adminValidator.getCommentPostValidator).mockReturnValue({ left: error });

await expect(getController(getStrapi()).postComment(ctx)).rejects.toThrow();
await expect(getController(getStrapi()).postCommentThread(ctx)).rejects.toThrow();
});
});

Expand Down
4 changes: 2 additions & 2 deletions server/src/controllers/admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ const controllers = ({ strapi }: StrapiContext) => ({
throw throwError(ctx, unwrapEither(either));
},

async postComment(ctx: RequestContext<Omit<adminValidator.CommentPostValidatorSchema, 'id'>, Pick<adminValidator.CommentPostValidatorSchema, 'id'>>) {
async postCommentThread(ctx: RequestContext<Omit<adminValidator.CommentPostValidatorSchema, 'id'>, Pick<adminValidator.CommentPostValidatorSchema, 'id'>>) {
const either = adminValidator.getCommentPostValidator({
id: ctx.params.id,
content: ctx.request.body.content,
author: ctx.request.body.author,
});
if (isRight(either)) {
return this.getService('admin').postComment(unwrapEither(either));
return this.getService('admin').postCommentThread(unwrapEither(either));
}
throw throwError(ctx, unwrapEither(either));
},
Expand Down
2 changes: 1 addition & 1 deletion server/src/routes/admin.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const adminRoutes: StrapiRoute<'admin'>[] = [
{
method: 'POST',
path: '/moderate/thread/:id/postComment',
handler: 'admin.postComment',
handler: 'admin.postCommentThread',
config: {
policies: [],
},
Expand Down
Loading