Skip to content

Commit 54af284

Browse files
MOL-357/PICT-241: update test cases
1 parent c9b5072 commit 54af284

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

processor/src/controllers/connector.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const install = async (request: Request, response: Response) => {
3737
const protocol = request.secure ? 'https' : 'http';
3838
const extensionUrl = `${protocol}://${request.hostname}/processor`;
3939

40-
if (!extensionUrl) {
40+
if (!request.hostname) {
4141
logger.debug('SCTM - install - Missing body parameters {extensionUrl}.');
4242
return apiError(response, formatErrorResponse(new CustomError(400, 'Missing body parameters.')).errors);
4343
}

processor/tests/controllers/connector.controller.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ describe('Test connector.controller.ts', () => {
3939

4040
it('should return status code 200 with a successful install response', async () => {
4141
req = {
42-
body: { extensionUrl: 'https://example.com/extensionUrl' },
42+
hostname: 'test.com',
43+
secure: true,
44+
protocol: 'https',
4345
};
4446
await install(req as Request, res as Response);
4547
expect(logger.debug).toBeCalledTimes(1);

processor/tests/routes/processor.route.spec.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('Test src/route/processor.route.ts', () => {
9595
});
9696

9797
describe('POST /install/', () => {
98-
it('should return 200 if extensionUrl is provided', async () => {
98+
it('should return 200 if hostname is provided', async () => {
9999
const layer = webhookRouter.stack.find(
100100
//@ts-expect-error route should be always available
101101
(layer) => layer.route.path === '/install' && layer.route.methods.post,
@@ -105,23 +105,23 @@ describe('Test src/route/processor.route.ts', () => {
105105
//@ts-expect-error handler should be always available
106106
const handler = layer.route.stack[0].handle;
107107

108-
req = {
109-
body: {
110-
extensionUrl: 'https://example.com',
111-
},
112-
};
113-
114108
(createPaymentExtension as jest.Mock).mockReturnValueOnce(Promise.resolve());
115109
(createCustomPaymentType as jest.Mock).mockReturnValueOnce(Promise.resolve());
116110
(createCustomPaymentInterfaceInteractionType as jest.Mock).mockReturnValueOnce(Promise.resolve());
117111
(createCustomPaymentTransactionCancelReasonType as jest.Mock).mockReturnValueOnce(Promise.resolve());
118112

113+
req = {
114+
hostname: 'test.com',
115+
secure: true,
116+
protocol: 'https',
117+
};
118+
119119
await handler(req as Request, res as Response, next);
120120

121121
expect(res.status).toHaveBeenCalledWith(200);
122122
});
123123

124-
it('should return 400 if extensionUrl is not provided', async () => {
124+
it('should return 400 if hostname is not provided', async () => {
125125
const layer = webhookRouter.stack.find(
126126
//@ts-expect-error route should be always available
127127
(layer) => layer.route.path === '/install' && layer.route.methods.post,
@@ -133,6 +133,12 @@ describe('Test src/route/processor.route.ts', () => {
133133

134134
expect(handler).toBeDefined();
135135

136+
req = {
137+
hostname: '',
138+
secure: true,
139+
protocol: 'https',
140+
};
141+
136142
await handler(req as Request, res as Response, next);
137143

138144
expect(logger.debug).toBeCalledTimes(1);

0 commit comments

Comments
 (0)