first commit
This commit is contained in:
32
tests/unit/response.helper.test.js
Normal file
32
tests/unit/response.helper.test.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const ResponseHelper = require('../../app/helpers/response.helper');
|
||||
|
||||
describe('ResponseHelper', () => {
|
||||
let mockRes;
|
||||
|
||||
beforeEach(() => {
|
||||
mockRes = {
|
||||
status: jest.fn().mockReturnThis(),
|
||||
json: jest.fn().mockReturnThis()
|
||||
};
|
||||
});
|
||||
|
||||
it('should send success response', () => {
|
||||
ResponseHelper.success(mockRes, 'Success test', { id: 1 });
|
||||
expect(mockRes.status).toHaveBeenCalledWith(200);
|
||||
expect(mockRes.json).toHaveBeenCalledWith(expect.objectContaining({
|
||||
success: true,
|
||||
message: 'Success test',
|
||||
data: { id: 1 }
|
||||
}));
|
||||
});
|
||||
|
||||
it('should send error response', () => {
|
||||
ResponseHelper.error(mockRes, 'Error test', 400, { field: 'required' });
|
||||
expect(mockRes.status).toHaveBeenCalledWith(400);
|
||||
expect(mockRes.json).toHaveBeenCalledWith(expect.objectContaining({
|
||||
success: false,
|
||||
message: 'Error test',
|
||||
errors: { field: 'required' }
|
||||
}));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user