@eagleeye-solutions/integration-events-common
Version:
Eagle Eye CDP connector common functionality
110 lines • 3.82 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const supertest_1 = __importDefault(require("supertest"));
const src_1 = require("../../src");
const express_1 = require("express");
const configWithNoInRouter = {
platformConfig: {
platform: 'GCP',
projectId: 'some-project',
internalMessagesTopicName: 'internal-messages-topic',
cdpDeadLetterQueue: 'internal-messages-dlq-topic',
pubSubAuthenticatedPushServiceAccount: 'fake@example.org',
pubSubAuthenticatedPushAudience: 'https://example.org/internal',
},
configPlatform: 'GENERIC',
configUrl: 'https://example.org/api',
routes: {
internal: {
path: '/internal',
getInternalMessageFromRequest: jest.fn(),
handlers: {
'cdp-outbound-event': jest.fn(),
'ee-air-outbound-event': jest.fn(),
'cdp-inbound-event': jest.fn(),
'ee-air-inbound-event': jest.fn(),
},
},
},
appMetadata: {
name: 'some-app-name',
version: 'some-version',
tagline: 'some-tag-line',
},
handlePermanentMessageDeliveryFailure: jest.fn(),
traceIdName: 'some-trace-id-name',
includeTraceIdInHttpResponseHeaders: false,
};
const inRouter = (0, express_1.Router)();
inRouter.get('/status', src_1.handleStatus);
inRouter.get('/some-path', (_req, res) => {
res.status(200).send({ data: 'some-path' });
});
inRouter.get('/some-other-path', (_req, res) => {
res.status(200).send({ data: 'some-other-path' });
});
const configWithInRouterThatHandlesStatusAndOtherEndpoints = {
...configWithNoInRouter,
routes: {
...configWithNoInRouter.routes,
in: inRouter,
},
};
describe('status endpoints', () => {
it.each([
{
direction: 'in',
config: configWithNoInRouter,
path: 'status',
expectedResponse: {
api: 'some-app-name',
version: 'some-version',
tagline: 'some-tag-line',
},
},
{
direction: 'in',
config: configWithInRouterThatHandlesStatusAndOtherEndpoints,
path: 'status',
expectedResponse: {
api: 'some-app-name',
version: 'some-version',
tagline: 'some-tag-line',
},
},
{
direction: 'in',
config: configWithInRouterThatHandlesStatusAndOtherEndpoints,
path: 'some-path',
expectedResponse: { data: 'some-path' },
},
{
direction: 'in',
config: configWithInRouterThatHandlesStatusAndOtherEndpoints,
path: 'some-other-path',
expectedResponse: { data: 'some-other-path' },
},
{
direction: 'out',
config: configWithNoInRouter,
path: 'status',
expectedResponse: {
api: 'some-app-name',
version: 'some-version',
tagline: 'some-tag-line',
},
},
])('GET /$direction/generic/$path returns a 200 OK with response body $expectedResponse', async ({ direction, config, path, expectedResponse }) => {
// Arrange
const app = await (0, src_1.connector)(config);
// Act
const response = await (0, supertest_1.default)(app).get(`/${direction}/generic/${path}`);
// Assert
expect(response.status).toEqual(200);
expect(response.body).toEqual(expectedResponse);
});
});
//# sourceMappingURL=status-endpoints.spec.js.map