add(feat): verification

This commit is contained in:
2026-02-18 17:01:41 +07:00
parent c52ecd6514
commit dd09ff0511
15 changed files with 90 additions and 16 deletions

View File

@@ -8,17 +8,20 @@ const NotificationController = require('../../app/modules/notification/controlle
describe('NotificationController', () => {
let mockReq, mockRes;
const routerToken = 'TEST_ROUTER_TOKEN';
beforeEach(() => {
jest.clearAllMocks();
process.env.ROUTER_CALLBACK_TOKEN = routerToken;
mockRes = {
status: jest.fn().mockReturnThis(),
json: jest.fn().mockReturnThis()
};
});
it('should handle notification successfully', async () => {
it('should handle notification successfully when token and signature are valid', async () => {
mockReq = {
headers: { 'x-callback-token': routerToken },
body: { order_id: 'I-123', transaction_status: 'settlement' }
};
@@ -32,8 +35,22 @@ describe('NotificationController', () => {
expect(responseHelper.success).toHaveBeenCalledWith(mockRes, expect.stringContaining('Handled'));
});
it('should return 401 if x-callback-token is invalid', async () => {
mockReq = {
headers: { 'x-callback-token': 'wrong-token' },
body: {}
};
await NotificationController.handle(mockReq, mockRes);
expect(responseHelper.error).toHaveBeenCalledWith(mockRes, expect.stringContaining('Unauthorized token'), 401);
});
it('should return 403 if signature invalid', async () => {
mockReq = { body: { signature_key: 'invalid' } };
mockReq = {
headers: { 'x-callback-token': routerToken },
body: { signature_key: 'invalid' }
};
notificationService.verifySignature.mockReturnValue(false);
await NotificationController.handle(mockReq, mockRes);
@@ -42,7 +59,10 @@ describe('NotificationController', () => {
});
it('should return error on service error', async () => {
mockReq = { body: { order_id: 'I-123' } };
mockReq = {
headers: { 'x-callback-token': routerToken },
body: { order_id: 'I-123' }
};
notificationService.verifySignature.mockReturnValue(true);
notificationService.processNotification.mockRejectedValue(new Error('DB Error'));