feat: implement notification controller for handling incoming notifications with signature verification and add corresponding unit tests.
This commit is contained in:
@@ -19,9 +19,8 @@ describe('NotificationController', () => {
|
||||
};
|
||||
});
|
||||
|
||||
it('should handle notification successfully when token and signature are valid', async () => {
|
||||
it('should handle notification successfully when signature is valid', async () => {
|
||||
mockReq = {
|
||||
headers: { 'x-callback-token': routerToken },
|
||||
body: { order_id: 'I-123', transaction_status: 'settlement' }
|
||||
};
|
||||
|
||||
@@ -35,20 +34,9 @@ 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 = {
|
||||
headers: { 'x-callback-token': routerToken },
|
||||
body: { signature_key: 'invalid' }
|
||||
};
|
||||
notificationService.verifySignature.mockReturnValue(false);
|
||||
@@ -60,7 +48,6 @@ describe('NotificationController', () => {
|
||||
|
||||
it('should return error on service error', async () => {
|
||||
mockReq = {
|
||||
headers: { 'x-callback-token': routerToken },
|
||||
body: { order_id: 'I-123' }
|
||||
};
|
||||
notificationService.verifySignature.mockReturnValue(true);
|
||||
|
||||
Reference in New Issue
Block a user