first commit

This commit is contained in:
2026-02-18 16:03:43 +07:00
commit c52ecd6514
54 changed files with 8270 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
const notificationService = require('../../app/modules/notification/services/notification.service');
const responseHelper = require('../../app/helpers/response.helper');
jest.mock('../../app/modules/notification/services/notification.service');
jest.mock('../../app/helpers/response.helper');
const NotificationController = require('../../app/modules/notification/controllers/notification.controller');
describe('NotificationController', () => {
let mockReq, mockRes;
beforeEach(() => {
jest.clearAllMocks();
mockRes = {
status: jest.fn().mockReturnThis(),
json: jest.fn().mockReturnThis()
};
});
it('should handle notification successfully', async () => {
mockReq = {
body: { order_id: 'I-123', transaction_status: 'settlement' }
};
notificationService.verifySignature.mockReturnValue(true);
notificationService.processNotification.mockResolvedValue();
await NotificationController.handle(mockReq, mockRes);
expect(notificationService.verifySignature).toHaveBeenCalledWith(mockReq.body);
expect(notificationService.processNotification).toHaveBeenCalledWith(mockReq.body);
expect(responseHelper.success).toHaveBeenCalledWith(mockRes, expect.stringContaining('Handled'));
});
it('should return 403 if signature invalid', async () => {
mockReq = { body: { signature_key: 'invalid' } };
notificationService.verifySignature.mockReturnValue(false);
await NotificationController.handle(mockReq, mockRes);
expect(responseHelper.error).toHaveBeenCalledWith(mockRes, expect.stringContaining('Invalid Signature'), 403);
});
it('should return error on service error', async () => {
mockReq = { body: { order_id: 'I-123' } };
notificationService.verifySignature.mockReturnValue(true);
notificationService.processNotification.mockRejectedValue(new Error('DB Error'));
await NotificationController.handle(mockReq, mockRes);
expect(responseHelper.error).toHaveBeenCalledWith(mockRes, expect.stringContaining('DB Error'));
});
});