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
4 changes: 2 additions & 2 deletions src/modules/admin/admin.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AsyncController } from '../../types/auth.types';
import {
sendSuccess,
sendValidationError,
sendNotFound,
sendCreatorParamNotFound,
sendForbidden,
} from '../../utils/api-response.utils';
import { prisma } from '../../utils/prisma.utils';
Expand Down Expand Up @@ -61,7 +61,7 @@ export const httpUpdateCreatorMetadata: AsyncController = async (
});

if (!creator) {
return sendNotFound(res, 'Creator');
return sendCreatorParamNotFound(res);
}

const previousValues = {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/api-response.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ export function sendNotFound(res: Response, resource: string): void {
sendError(res, 404, ErrorCode.NOT_FOUND, `${resource} not found`);
}

export function sendCreatorParamNotFound(res: Response): void {
sendNotFound(res, 'Creator');
}

export function sendUnauthorized(
res: Response,
message = 'Unauthorized access',
Expand Down
17 changes: 17 additions & 0 deletions src/utils/test/api-response.utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Response } from 'express';
import {
sendForbidden,
sendUnauthorized,
sendCreatorParamNotFound,
buildErrorResponse,
zodIssuesToDetails,
ErrorCode,
Expand All @@ -17,6 +18,7 @@ describe('api-response.utils', () => {
jsonMock = jest.fn();
statusMock = jest.fn().mockReturnValue({ json: jsonMock });
mockResponse = {
setHeader: jest.fn(),
status: statusMock,
};
});
Expand Down Expand Up @@ -65,6 +67,21 @@ describe('api-response.utils', () => {
});
});
});

describe('sendCreatorParamNotFound', () => {
it('should send the shared creator parameter not-found response', () => {
sendCreatorParamNotFound(mockResponse as Response);

expect(statusMock).toHaveBeenCalledWith(404);
expect(jsonMock).toHaveBeenCalledWith({
success: false,
error: {
code: ErrorCode.NOT_FOUND,
message: 'Creator not found',
},
});
});
});
});

describe('buildErrorResponse', () => {
Expand Down
Loading