From 2b4a128792167a684db030926079a9cc57551e49 Mon Sep 17 00:00:00 2001 From: NatalieShaked Date: Wed, 24 Dec 2025 12:36:56 +0200 Subject: [PATCH 01/10] feat: added prefix option to redis --- config/default.json | 3 ++- config/test.json | 4 +++- .../middlewares/feedbackApi.middleware.ts | 4 +++- tests/integration/mgrs/mgrs.spec.ts | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/config/default.json b/config/default.json index e32de7a..0187c00 100644 --- a/config/default.json +++ b/config/default.json @@ -79,7 +79,8 @@ "cert": "" }, "dbIndex": 0, - "ttl": 600 + "ttl": 600, + "prefix": "geocoding" } }, "application": { diff --git a/config/test.json b/config/test.json index 6eeb44d..bb65134 100644 --- a/config/test.json +++ b/config/test.json @@ -45,7 +45,9 @@ "key": "", "cert": "" }, - "dbIndex": 1 + "dbIndex": 1, + "ttl": 300, + "prefix": "test" } }, "application": { diff --git a/src/common/middlewares/feedbackApi.middleware.ts b/src/common/middlewares/feedbackApi.middleware.ts index 67507b5..b368774 100644 --- a/src/common/middlewares/feedbackApi.middleware.ts +++ b/src/common/middlewares/feedbackApi.middleware.ts @@ -21,6 +21,7 @@ export class FeedbackApiMiddlewareManager { const reqId = res.getHeader(XApi.REQUEST); const redisClient = this.redis; const logger = this.logger; + const prefix = this.config.get(redisConfigPath).prefix; const drSite = this.config.get(siteConfig); @@ -36,10 +37,11 @@ export class FeedbackApiMiddlewareManager { const { ttl: redisTtl } = this.config.get(redisConfigPath); const originalJson = res.json; + const fullRequestId = prefix != undefined ? `${prefix}:${reqId as string}` : (reqId as string); const logJson = function (this: Response, body: JSON): Response { geocodingResponseDetails.response = body; redisClient - .setEx(reqId as string, redisTtl ?? defaultRedisTtl, JSON.stringify(geocodingResponseDetails)) + .setEx(fullRequestId, redisTtl ?? defaultRedisTtl, JSON.stringify(geocodingResponseDetails)) .then(() => { logger.info({ msg: `response ${reqId?.toString() ?? ''} saved to redis` }); }) diff --git a/tests/integration/mgrs/mgrs.spec.ts b/tests/integration/mgrs/mgrs.spec.ts index 6371aff..3d827ad 100644 --- a/tests/integration/mgrs/mgrs.spec.ts +++ b/tests/integration/mgrs/mgrs.spec.ts @@ -5,6 +5,8 @@ import { CleanupRegistry } from '@map-colonies/cleanup-registry'; import jsLogger from '@map-colonies/js-logger'; import { trace } from '@opentelemetry/api'; import httpStatusCodes from 'http-status-codes'; +import { IConfig } from 'config'; +import { RedisClient } from '@src/common/redis'; import { getApp } from '../../../src/app'; import { SERVICES } from '../../../src/common/constants'; import { S3_REPOSITORY_SYMBOL } from '../../../src/common/s3/s3Repository'; @@ -89,6 +91,22 @@ describe('/search/MGRS', function () { }, }); }); + + describe('Redis uses prefix key', () => { + it('should return 200 status code and add key to Redis with prefix', async function () { + const config = depContainer.resolve(SERVICES.CONFIG); + const prefix = config.get('redis.prefix'); + const redisConnection = depContainer.resolve(SERVICES.REDIS); + + const response = await requestSender.getTile({ tile: '18SUJ2339007393' }); + + const keys = prefix !== undefined ? await redisConnection.keys(prefix + '*') : await redisConnection.keys('*'); + + expect(keys.length).toBeGreaterThanOrEqual(1); + + expect(response.status).toBe(httpStatusCodes.OK); + }); + }); }); describe('Bad Path', function () { From ded59c130b12735f5f72cfd6c9d497d933ddf1d1 Mon Sep 17 00:00:00 2001 From: NatalieShaked Date: Wed, 24 Dec 2025 12:56:27 +0200 Subject: [PATCH 02/10] feat: updated mapcolonies schemas package --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index e8b2872..0549eef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@map-colonies/js-logger": "^2.0.0", "@map-colonies/openapi-express-viewer": "^4.0.0", "@map-colonies/read-pkg": "^1.0.0", - "@map-colonies/schemas": "^1.12.2", + "@map-colonies/schemas": "^1.14.0", "@map-colonies/telemetry": "^10.0.1", "@opentelemetry/api": "^1.9.0", "@smithy/node-http-handler": "^3.1.4", @@ -4258,9 +4258,9 @@ } }, "node_modules/@map-colonies/schemas": { - "version": "1.12.2", - "resolved": "https://ghatmpstorage.blob.core.windows.net/npm-packages/schemas-d7b33710c7a41d83f15469ca6c1d6800b0b6bd2d.tgz", - "integrity": "sha512-V5Wvo4yIfc+mkLUE3RYna8ME2Bn5sQfH+2KyyVB8kN+IgmvGqx47W0kPSiw3xtXhliuDFw9psT2/1m8mSSsI5g==", + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/@map-colonies/schemas/-/schemas-1.14.0.tgz", + "integrity": "sha512-EBR36xOnIrRrXc+HG1MnGUKe/epXF5HAyEZc5jwV0RQzvn66Buo70+/jW9A/yb/mtrroSqHn2bdlLuH5kml6iQ==", "license": "MIT" }, "node_modules/@map-colonies/standard-version-update-helm-version": { @@ -27511,9 +27511,9 @@ } }, "@map-colonies/schemas": { - "version": "1.12.2", - "resolved": "https://ghatmpstorage.blob.core.windows.net/npm-packages/schemas-d7b33710c7a41d83f15469ca6c1d6800b0b6bd2d.tgz", - "integrity": "sha512-V5Wvo4yIfc+mkLUE3RYna8ME2Bn5sQfH+2KyyVB8kN+IgmvGqx47W0kPSiw3xtXhliuDFw9psT2/1m8mSSsI5g==" + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/@map-colonies/schemas/-/schemas-1.14.0.tgz", + "integrity": "sha512-EBR36xOnIrRrXc+HG1MnGUKe/epXF5HAyEZc5jwV0RQzvn66Buo70+/jW9A/yb/mtrroSqHn2bdlLuH5kml6iQ==" }, "@map-colonies/standard-version-update-helm-version": { "version": "2.0.1", diff --git a/package.json b/package.json index 13b48af..06295d9 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "@map-colonies/js-logger": "^2.0.0", "@map-colonies/openapi-express-viewer": "^4.0.0", "@map-colonies/read-pkg": "^1.0.0", - "@map-colonies/schemas": "^1.12.2", + "@map-colonies/schemas": "^1.14.0", "@map-colonies/telemetry": "^10.0.1", "@opentelemetry/api": "^1.9.0", "@smithy/node-http-handler": "^3.1.4", From c1b3f27f02df16c26d8384cf1c787f3d23917d5c Mon Sep 17 00:00:00 2001 From: NatalieShaked Date: Wed, 24 Dec 2025 13:25:47 +0200 Subject: [PATCH 03/10] feat: added redis to workflow --- .github/workflows/pull_request.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 385aca2..45cfdf2 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -77,6 +77,17 @@ jobs: --health-timeout 5s --health-retries 5 + redis: + # Docker Hub image + image: redis + + # Set health checks to wait until redis has started + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - name: Check out Git repository uses: actions/checkout@v4 From 2c76b544514a8738a91556ec5fe00c2a6aad7ff6 Mon Sep 17 00:00:00 2001 From: NatalieShaked Date: Wed, 24 Dec 2025 13:33:11 +0200 Subject: [PATCH 04/10] feat: added redis to workflow --- .github/workflows/pull_request.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 45cfdf2..f32471c 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -78,10 +78,12 @@ jobs: --health-retries 5 redis: - # Docker Hub image - image: redis + image: redis:7.2.3 + env: + ALLOW_EMPTY_PASSWORD: yes + ports: + - 6379:6379 - # Set health checks to wait until redis has started options: >- --health-cmd "redis-cli ping" --health-interval 10s From 63b45851a49f21106d5f3627eb04324cc30afae1 Mon Sep 17 00:00:00 2001 From: NatalieShaked Date: Wed, 24 Dec 2025 13:44:36 +0200 Subject: [PATCH 05/10] feat: added redis to workflow --- config/test.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/test.json b/config/test.json index bb65134..e32df84 100644 --- a/config/test.json +++ b/config/test.json @@ -35,7 +35,7 @@ "fileName": "table.json" }, "redis": { - "host": "localhost", + "host": "http://redis:6379", "port": 6379, "username": "", "password": "", From 8437f3a612fe6d74d41411807bdcb1394a2c8fdd Mon Sep 17 00:00:00 2001 From: NatalieShaked Date: Wed, 24 Dec 2025 13:53:48 +0200 Subject: [PATCH 06/10] feat: added redis to workflow --- .github/workflows/pull_request.yaml | 5 +---- config/test.json | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index f32471c..179efa5 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -78,12 +78,9 @@ jobs: --health-retries 5 redis: - image: redis:7.2.3 - env: - ALLOW_EMPTY_PASSWORD: yes + image: redis ports: - 6379:6379 - options: >- --health-cmd "redis-cli ping" --health-interval 10s diff --git a/config/test.json b/config/test.json index e32df84..c4dd6bc 100644 --- a/config/test.json +++ b/config/test.json @@ -35,7 +35,7 @@ "fileName": "table.json" }, "redis": { - "host": "http://redis:6379", + "host": "redis", "port": 6379, "username": "", "password": "", From b840dca461591121d1ffdeb379eed13b093018a7 Mon Sep 17 00:00:00 2001 From: NatalieShaked Date: Wed, 24 Dec 2025 17:49:46 +0200 Subject: [PATCH 07/10] fix: pr comments --- README.md | 3 ++- config/default.json | 3 +-- config/test.json | 3 +-- src/common/middlewares/feedbackApi.middleware.ts | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fe36e29..4da01df 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,9 @@ Almost all of our routes consists of the same common query parameters: `geo_cont | disable_fuzziness | Boolean | false | Fuzziness is on by default. If you want exact match, you may set `disable_fuzziness: true`. | > [!IMPORTANT] > We also have Feedback API. Each request is sent back with x-req-id which is the identifier of the request. We kindly ask our users to provide us with a request to Feedback API which contains x-api-key and clicked response. It enables us to research the request and response to be more accurate. -> Feedback API source code is built in a different repository at . +> Feedback API source code is built in a different repository at [feedback-api](https://github.com/MapColonies/feedback-api). > Geocoding API inserts the request and response to Redis before the response is sent. +Speaking of Redis, in the redis config you can add a `prefix` flag, if you'd like to add keys with prefixes to redis. ## Installation Setup Elasticsearch and S3 provider (For local environment, Minio as a personal recommendation). diff --git a/config/default.json b/config/default.json index 0187c00..e32de7a 100644 --- a/config/default.json +++ b/config/default.json @@ -79,8 +79,7 @@ "cert": "" }, "dbIndex": 0, - "ttl": 600, - "prefix": "geocoding" + "ttl": 600 } }, "application": { diff --git a/config/test.json b/config/test.json index c4dd6bc..8da55d3 100644 --- a/config/test.json +++ b/config/test.json @@ -46,8 +46,7 @@ "cert": "" }, "dbIndex": 1, - "ttl": 300, - "prefix": "test" + "ttl": 300 } }, "application": { diff --git a/src/common/middlewares/feedbackApi.middleware.ts b/src/common/middlewares/feedbackApi.middleware.ts index b368774..a968a3c 100644 --- a/src/common/middlewares/feedbackApi.middleware.ts +++ b/src/common/middlewares/feedbackApi.middleware.ts @@ -37,7 +37,7 @@ export class FeedbackApiMiddlewareManager { const { ttl: redisTtl } = this.config.get(redisConfigPath); const originalJson = res.json; - const fullRequestId = prefix != undefined ? `${prefix}:${reqId as string}` : (reqId as string); + const fullRequestId = prefix !== undefined ? `${prefix}:${reqId as string}` : (reqId as string); const logJson = function (this: Response, body: JSON): Response { geocodingResponseDetails.response = body; redisClient From ee27dc4c5139e587cc73229cc7382ff375d9af5e Mon Sep 17 00:00:00 2001 From: NatalieShaked Date: Wed, 24 Dec 2025 17:56:07 +0200 Subject: [PATCH 08/10] test: added redis prefix tests --- .../integration/control/item/helpers/index.ts | 19 ++++++ tests/integration/control/item/item.spec.ts | 58 ++++++++++++++----- .../control/route/helpers/index.ts | 19 ++++++ tests/integration/control/route/route.spec.ts | 57 +++++++++++++----- .../integration/control/tile/helpers/index.ts | 19 ++++++ tests/integration/control/tile/tile.spec.ts | 58 ++++++++++++++----- tests/integration/latLon/latLon.spec.ts | 46 ++++++++++++++- tests/integration/location/helpers/index.ts | 19 ++++++ tests/integration/location/location.spec.ts | 55 +++++++++++++----- tests/integration/mgrs/helpers/index.ts | 20 +++++++ tests/integration/mgrs/mgrs.spec.ts | 50 +++++++++------- 11 files changed, 337 insertions(+), 83 deletions(-) create mode 100644 tests/integration/control/item/helpers/index.ts create mode 100644 tests/integration/control/route/helpers/index.ts create mode 100644 tests/integration/control/tile/helpers/index.ts create mode 100644 tests/integration/location/helpers/index.ts create mode 100644 tests/integration/mgrs/helpers/index.ts diff --git a/tests/integration/control/item/helpers/index.ts b/tests/integration/control/item/helpers/index.ts new file mode 100644 index 0000000..52580f6 --- /dev/null +++ b/tests/integration/control/item/helpers/index.ts @@ -0,0 +1,19 @@ +import jsLogger from '@map-colonies/js-logger'; +import { trace } from '@opentelemetry/api'; +import { SERVICES } from '@src/common/constants'; +import { S3_REPOSITORY_SYMBOL } from '@src/common/s3/s3Repository'; +import { cronLoadTileLatLonDataSymbol } from '@src/latLon/DAL/latLonDAL'; +import { RegisterOptions } from '@src/containerConfig'; + +export const getBaseRegisterOptions = (): Required => { + return { + override: [ + { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, + { token: SERVICES.TRACER, provider: { useValue: trace.getTracer('testTracer') } }, + { token: S3_REPOSITORY_SYMBOL, provider: { useValue: {} } }, + { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, + { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, + ], + useChild: true, + }; +}; diff --git a/tests/integration/control/item/item.spec.ts b/tests/integration/control/item/item.spec.ts index 2e35f4e..2d8e374 100644 --- a/tests/integration/control/item/item.spec.ts +++ b/tests/integration/control/item/item.spec.ts @@ -1,35 +1,26 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import jsLogger from '@map-colonies/js-logger'; -import { trace } from '@opentelemetry/api'; import { CleanupRegistry } from '@map-colonies/cleanup-registry'; import { DependencyContainer } from 'tsyringe'; import httpStatusCodes from 'http-status-codes'; +import { IConfig } from 'config'; +import { RedisClient } from '@src/common/redis'; import { getApp } from '../../../../src/app'; -import { SERVICES } from '../../../../src/common/constants'; +import { redisConfigPath, SERVICES } from '../../../../src/common/constants'; import { GetItemsQueryParams } from '../../../../src/control/item/controllers/itemController'; import { Item } from '../../../../src/control/item/models/item'; import { CommonRequestParameters, GenericGeocodingResponse, GeoContext, GeoContextMode } from '../../../../src/common/interfaces'; -import { cronLoadTileLatLonDataSymbol } from '../../../../src/latLon/DAL/latLonDAL'; -import { S3_REPOSITORY_SYMBOL } from '../../../../src/common/s3/s3Repository'; import { expectedResponse } from '../utils'; import { ITEM_1234, ITEM_1235, ITEM_1236 } from '../../../mockObjects/items'; import { ItemRequestSender } from './helpers/requestSender'; +import { getBaseRegisterOptions } from './helpers'; describe('/search/control/items', function () { let requestSender: ItemRequestSender; let depContainer: DependencyContainer; beforeEach(async function () { - const [app, container] = await getApp({ - override: [ - { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, - { token: SERVICES.TRACER, provider: { useValue: trace.getTracer('testTracer') } }, - { token: S3_REPOSITORY_SYMBOL, provider: { useValue: {} } }, - { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, - { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, - ], - useChild: true, - }); + const [app, container] = await getApp(getBaseRegisterOptions()); + depContainer = container; requestSender = new ItemRequestSender(app); }); @@ -245,7 +236,44 @@ describe('/search/control/items', function () { expectedResponse(requestParams, [ITEM_1234, ITEM_1235], expect) ); }); + + describe('Redis uses prefix key', () => { + it('should return 200 status code and add key to Redis with prefix', async function () { + const realConfig = depContainer.resolve(SERVICES.CONFIG); + const prefix = 'test-prefix-item'; + + const configWithPrefix: IConfig = { + ...realConfig, + get(key: string): T { + if (key === redisConfigPath) { + const realRedisConfig = realConfig.get(redisConfigPath); + return { ...realRedisConfig, prefix } as T; + } + return realConfig.get(key); + }, + }; + + const mockRegisterOptions = getBaseRegisterOptions(); + mockRegisterOptions.override.push({ + token: SERVICES.CONFIG, + provider: { useValue: configWithPrefix }, + }); + + const [mockApp, localContainer] = await getApp(mockRegisterOptions); + const localRequestSender = new ItemRequestSender(mockApp); + + const redisConnection = localContainer.resolve(SERVICES.REDIS); + + const requestParams: GetItemsQueryParams = { command_name: '123', limit: 5, disable_fuzziness: false }; + const response = await localRequestSender.getItems(requestParams); + + const keys = await redisConnection.keys(prefix + '*'); + expect(keys.length).toBeGreaterThanOrEqual(1); + expect(response.status).toBe(httpStatusCodes.OK); + }); + }); }); + describe('Bad Path', function () { // All requests with status code of 400 it("should return 400 status code and error message when item's command_name", async function () { diff --git a/tests/integration/control/route/helpers/index.ts b/tests/integration/control/route/helpers/index.ts new file mode 100644 index 0000000..52580f6 --- /dev/null +++ b/tests/integration/control/route/helpers/index.ts @@ -0,0 +1,19 @@ +import jsLogger from '@map-colonies/js-logger'; +import { trace } from '@opentelemetry/api'; +import { SERVICES } from '@src/common/constants'; +import { S3_REPOSITORY_SYMBOL } from '@src/common/s3/s3Repository'; +import { cronLoadTileLatLonDataSymbol } from '@src/latLon/DAL/latLonDAL'; +import { RegisterOptions } from '@src/containerConfig'; + +export const getBaseRegisterOptions = (): Required => { + return { + override: [ + { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, + { token: SERVICES.TRACER, provider: { useValue: trace.getTracer('testTracer') } }, + { token: S3_REPOSITORY_SYMBOL, provider: { useValue: {} } }, + { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, + { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, + ], + useChild: true, + }; +}; diff --git a/tests/integration/control/route/route.spec.ts b/tests/integration/control/route/route.spec.ts index dd15157..ecce7da 100644 --- a/tests/integration/control/route/route.spec.ts +++ b/tests/integration/control/route/route.spec.ts @@ -1,16 +1,14 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import jsLogger from '@map-colonies/js-logger'; -import { trace } from '@opentelemetry/api'; import httpStatusCodes from 'http-status-codes'; import { DependencyContainer } from 'tsyringe'; import { CleanupRegistry } from '@map-colonies/cleanup-registry'; +import { IConfig } from 'config'; +import { RedisClient } from '@src/common/redis'; import { getApp } from '../../../../src/app'; -import { SERVICES } from '../../../../src/common/constants'; +import { redisConfigPath, SERVICES } from '../../../../src/common/constants'; import { GetRoutesQueryParams } from '../../../../src/control/route/controllers/routeController'; import { Route } from '../../../../src/control/route/models/route'; import { CommonRequestParameters, GenericGeocodingResponse, GeoContext, GeoContextMode } from '../../../../src/common/interfaces'; -import { S3_REPOSITORY_SYMBOL } from '../../../../src/common/s3/s3Repository'; -import { cronLoadTileLatLonDataSymbol } from '../../../../src/latLon/DAL/latLonDAL'; import { expectedResponse } from '../utils'; import { ROUTE_VIA_CAMILLUCCIA_A, @@ -19,22 +17,14 @@ import { CONTROL_POINT_OLIMPIADE_112, } from '../../../mockObjects/routes'; import { RouteRequestSender } from './helpers/requestSender'; +import { getBaseRegisterOptions } from './helpers'; describe('/search/control/route', function () { let requestSender: RouteRequestSender; let depContainer: DependencyContainer; beforeEach(async function () { - const [app, container] = await getApp({ - override: [ - { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, - { token: SERVICES.TRACER, provider: { useValue: trace.getTracer('testTracer') } }, - { token: S3_REPOSITORY_SYMBOL, provider: { useValue: {} } }, - { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, - { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, - ], - useChild: true, - }); + const [app, container] = await getApp(getBaseRegisterOptions()); depContainer = container; requestSender = new RouteRequestSender(app); @@ -382,7 +372,44 @@ describe('/search/control/route', function () { bbox: null, }); }); + + describe('Redis uses prefix key', () => { + it('should return 200 status code and add key to Redis with prefix', async function () { + const realConfig = depContainer.resolve(SERVICES.CONFIG); + const prefix = 'test-prefix-route'; + + const configWithPrefix: IConfig = { + ...realConfig, + get(key: string): T { + if (key === redisConfigPath) { + const realRedisConfig = realConfig.get(redisConfigPath); + return { ...realRedisConfig, prefix } as T; + } + return realConfig.get(key); + }, + }; + + const mockRegisterOptions = getBaseRegisterOptions(); + mockRegisterOptions.override.push({ + token: SERVICES.CONFIG, + provider: { useValue: configWithPrefix }, + }); + + const [mockApp, localContainer] = await getApp(mockRegisterOptions); + const localRequestSender = new RouteRequestSender(mockApp); + + const redisConnection = localContainer.resolve(SERVICES.REDIS); + + const requestParams: GetRoutesQueryParams = { command_name: 'via camilluccia', limit: 5, disable_fuzziness: false }; + const response = await localRequestSender.getRoutes(requestParams); + + const keys = await redisConnection.keys(prefix + '*'); + expect(keys.length).toBeGreaterThanOrEqual(1); + expect(response.status).toBe(httpStatusCodes.OK); + }); + }); }); + describe('Bad Path', function () { // All requests with status code of 400 it('should return 400 status code and error message when empty object is passed', async function () { diff --git a/tests/integration/control/tile/helpers/index.ts b/tests/integration/control/tile/helpers/index.ts new file mode 100644 index 0000000..52580f6 --- /dev/null +++ b/tests/integration/control/tile/helpers/index.ts @@ -0,0 +1,19 @@ +import jsLogger from '@map-colonies/js-logger'; +import { trace } from '@opentelemetry/api'; +import { SERVICES } from '@src/common/constants'; +import { S3_REPOSITORY_SYMBOL } from '@src/common/s3/s3Repository'; +import { cronLoadTileLatLonDataSymbol } from '@src/latLon/DAL/latLonDAL'; +import { RegisterOptions } from '@src/containerConfig'; + +export const getBaseRegisterOptions = (): Required => { + return { + override: [ + { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, + { token: SERVICES.TRACER, provider: { useValue: trace.getTracer('testTracer') } }, + { token: S3_REPOSITORY_SYMBOL, provider: { useValue: {} } }, + { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, + { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, + ], + useChild: true, + }; +}; diff --git a/tests/integration/control/tile/tile.spec.ts b/tests/integration/control/tile/tile.spec.ts index 5e8cd8a..e4e10f4 100644 --- a/tests/integration/control/tile/tile.spec.ts +++ b/tests/integration/control/tile/tile.spec.ts @@ -1,36 +1,26 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import jsLogger from '@map-colonies/js-logger'; -import { trace } from '@opentelemetry/api'; import { DependencyContainer } from 'tsyringe'; import { CleanupRegistry } from '@map-colonies/cleanup-registry'; import httpStatusCodes from 'http-status-codes'; import type { BBox } from 'geojson'; +import { IConfig } from 'config'; +import { RedisClient } from '@src/common/redis'; import { getApp } from '../../../../src/app'; -import { SERVICES } from '../../../../src/common/constants'; +import { redisConfigPath, SERVICES } from '../../../../src/common/constants'; import { GetTilesQueryParams } from '../../../../src/control/tile/controllers/tileController'; import { Tile } from '../../../../src/control/tile/models/tile'; import { CommonRequestParameters, GenericGeocodingResponse, GeoContext, GeoContextMode } from '../../../../src/common/interfaces'; -import { S3_REPOSITORY_SYMBOL } from '../../../../src/common/s3/s3Repository'; -import { cronLoadTileLatLonDataSymbol } from '../../../../src/latLon/DAL/latLonDAL'; import { expectedResponse } from '../utils'; import { RIC_TILE, RIT_TILE, SUB_TILE_65, SUB_TILE_66 } from '../../../mockObjects/tiles'; import { TileRequestSender } from './helpers/requestSender'; +import { getBaseRegisterOptions } from './helpers'; describe('/search/control/tiles', function () { let requestSender: TileRequestSender; let depContainer: DependencyContainer; beforeEach(async function () { - const [app, container] = await getApp({ - override: [ - { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, - { token: SERVICES.TRACER, provider: { useValue: trace.getTracer('testTracer') } }, - { token: S3_REPOSITORY_SYMBOL, provider: { useValue: {} } }, - { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, - { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, - ], - useChild: true, - }); + const [app, container] = await getApp(getBaseRegisterOptions()); depContainer = container; requestSender = new TileRequestSender(app); @@ -356,7 +346,45 @@ describe('/search/control/tiles', function () { expectedResponse(requestParams, [RIC_TILE, RIT_TILE], expect) ); }); + + describe('Redis uses prefix key', () => { + it('should return 200 status code and add key to Redis with prefix', async function () { + const realConfig = depContainer.resolve(SERVICES.CONFIG); + const prefix = 'test-prefix-tile'; + + const configWithPrefix: IConfig = { + ...realConfig, + get(key: string): T { + if (key === redisConfigPath) { + const realRedisConfig = realConfig.get(redisConfigPath); + return { ...realRedisConfig, prefix } as T; + } + return realConfig.get(key); + }, + }; + + const mockRegisterOptions = getBaseRegisterOptions(); + mockRegisterOptions.override.push({ + token: SERVICES.CONFIG, + provider: { useValue: configWithPrefix }, + }); + + const [mockApp, localContainer] = await getApp(mockRegisterOptions); + const localRequestSender = new TileRequestSender(mockApp); + + const redisConnection = localContainer.resolve(SERVICES.REDIS); + + const requestParams: GetTilesQueryParams = { tile: 'RIT', limit: 5, disable_fuzziness: false }; + + const response = await localRequestSender.getTiles(requestParams); + + const keys = await redisConnection.keys(prefix + '*'); + expect(keys.length).toBeGreaterThanOrEqual(1); + expect(response.status).toBe(httpStatusCodes.OK); + }); + }); }); + describe('Bad Path', function () { // All requests with status code of 400 it('should return 400 status code and error message when tile or mgrs is not defined', async function () { diff --git a/tests/integration/latLon/latLon.spec.ts b/tests/integration/latLon/latLon.spec.ts index dfa305a..b8a7258 100644 --- a/tests/integration/latLon/latLon.spec.ts +++ b/tests/integration/latLon/latLon.spec.ts @@ -5,8 +5,10 @@ import { trace } from '@opentelemetry/api'; import { DependencyContainer } from 'tsyringe'; import { CleanupRegistry } from '@map-colonies/cleanup-registry'; import httpStatusCodes from 'http-status-codes'; +import { IConfig } from 'config'; +import { RedisClient } from '@src/common/redis'; import { getApp } from '../../../src/app'; -import { SERVICES } from '../../../src/common/constants'; +import { redisConfigPath, SERVICES } from '../../../src/common/constants'; import { LatLonDAL } from '../../../src/latLon/DAL/latLonDAL'; import { GenericGeocodingFeatureResponse } from '../../../src/common/interfaces'; import { LatLonRequestSender } from './helpers/requestSender'; @@ -139,6 +141,48 @@ describe('/lookup', function () { }, }); }); + + describe('Redis uses prefix key', () => { + it('should return 200 status code and add key to Redis with prefix', async function () { + const realConfig = depContainer.resolve(SERVICES.CONFIG); + const prefix = 'test-prefix-latlon'; + + const configWithPrefix: IConfig = { + ...realConfig, + get(key: string): T { + if (key === redisConfigPath) { + const realRedisConfig = realConfig.get(redisConfigPath); + return { ...realRedisConfig, prefix } as T; + } + return realConfig.get(key); + }, + }; + + const mockRegisterOptions = { + override: [ + { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, + { token: SERVICES.TRACER, provider: { useValue: trace.getTracer('testTracer') } }, + { token: SERVICES.CONFIG, provider: { useValue: configWithPrefix } }, + ], + useChild: true, + }; + + const [mockApp, localContainer] = await getApp(mockRegisterOptions); + const localRequestSender = new LatLonRequestSender(mockApp); + + const redisConnection = localContainer.resolve(SERVICES.REDIS); + + const response = await localRequestSender.convertCoordinatesToGrid({ + lat: 52.57326537485767, + lon: 12.948781146422107, + target_grid: 'MGRS', + }); + + const keys = await redisConnection.keys(prefix + '*'); + expect(keys.length).toBeGreaterThanOrEqual(1); + expect(response.status).toBe(httpStatusCodes.OK); + }); + }); }); describe('Bad Path', function () { diff --git a/tests/integration/location/helpers/index.ts b/tests/integration/location/helpers/index.ts new file mode 100644 index 0000000..52580f6 --- /dev/null +++ b/tests/integration/location/helpers/index.ts @@ -0,0 +1,19 @@ +import jsLogger from '@map-colonies/js-logger'; +import { trace } from '@opentelemetry/api'; +import { SERVICES } from '@src/common/constants'; +import { S3_REPOSITORY_SYMBOL } from '@src/common/s3/s3Repository'; +import { cronLoadTileLatLonDataSymbol } from '@src/latLon/DAL/latLonDAL'; +import { RegisterOptions } from '@src/containerConfig'; + +export const getBaseRegisterOptions = (): Required => { + return { + override: [ + { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, + { token: SERVICES.TRACER, provider: { useValue: trace.getTracer('testTracer') } }, + { token: S3_REPOSITORY_SYMBOL, provider: { useValue: {} } }, + { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, + { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, + ], + useChild: true, + }; +}; diff --git a/tests/integration/location/location.spec.ts b/tests/integration/location/location.spec.ts index 5f7fb80..05402a4 100644 --- a/tests/integration/location/location.spec.ts +++ b/tests/integration/location/location.spec.ts @@ -2,15 +2,13 @@ import { DependencyContainer } from 'tsyringe'; import type { Feature } from 'geojson'; import { CleanupRegistry } from '@map-colonies/cleanup-registry'; -import jsLogger from '@map-colonies/js-logger'; -import { trace } from '@opentelemetry/api'; import httpStatusCodes from 'http-status-codes'; import nock, { Body } from 'nock'; +import { IConfig } from 'config'; +import { RedisClient } from '@src/common/redis'; import { getApp } from '../../../src/app'; import { ConfigType, getConfig } from '../../../src/common/config'; -import { SERVICES } from '../../../src/common/constants'; -import { S3_REPOSITORY_SYMBOL } from '../../../src/common/s3/s3Repository'; -import { cronLoadTileLatLonDataSymbol } from '../../../src/latLon/DAL/latLonDAL'; +import { redisConfigPath, SERVICES } from '../../../src/common/constants'; import { GetGeotextSearchParams } from '../../../src/location/interfaces'; import { GenericGeocodingResponse, GeoContext, GeoContextMode } from '../../../src/common/interfaces'; import { @@ -30,6 +28,7 @@ import { } from '../../mockObjects/locations'; import { LocationRequestSender } from './helpers/requestSender'; import { expectedResponse, hierarchiesWithAnyWieght } from './utils'; +import { getBaseRegisterOptions } from './helpers'; let config: ConfigType; @@ -42,16 +41,7 @@ describe('/search/location', function () { }); beforeEach(async function () { - const [app, container] = await getApp({ - override: [ - { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, - { token: SERVICES.TRACER, provider: { useValue: trace.getTracer('testTracer') } }, - { token: S3_REPOSITORY_SYMBOL, provider: { useValue: {} } }, - { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, - { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, - ], - useChild: true, - }); + const [app, container] = await getApp(getBaseRegisterOptions()); depContainer = container; requestSender = new LocationRequestSender(app); @@ -536,6 +526,41 @@ describe('/search/location', function () { tokenTypesUrlScope.done(); }); + + describe('Redis uses prefix key', () => { + it('should return 200 status code and add key to Redis with prefix', async function () { + const realConfig = depContainer.resolve(SERVICES.CONFIG); + const prefix = 'test-prefix-location'; + + const configWithPrefix: IConfig = { + ...realConfig, + get(key: string): T { + if (key === redisConfigPath) { + const realRedisConfig = realConfig.get(redisConfigPath); + return { ...realRedisConfig, prefix } as T; + } + return realConfig.get(key); + }, + }; + + const mockRegisterOptions = getBaseRegisterOptions(); + mockRegisterOptions.override.push({ + token: SERVICES.CONFIG, + provider: { useValue: configWithPrefix }, + }); + + const [mockApp, localContainer] = await getApp(mockRegisterOptions); + const localRequestSender = new LocationRequestSender(mockApp); + + const redisConnection = localContainer.resolve(SERVICES.REDIS); + + const response = await localRequestSender.getRegions(); + + const keys = await redisConnection.keys(prefix + '*'); + expect(keys.length).toBeGreaterThanOrEqual(1); + expect(response.status).toBe(httpStatusCodes.OK); + }); + }); }); describe('Bad Path', function () { diff --git a/tests/integration/mgrs/helpers/index.ts b/tests/integration/mgrs/helpers/index.ts new file mode 100644 index 0000000..adcfc64 --- /dev/null +++ b/tests/integration/mgrs/helpers/index.ts @@ -0,0 +1,20 @@ +import jsLogger from '@map-colonies/js-logger'; +import { trace } from '@opentelemetry/api'; +import { SERVICES } from '@src/common/constants'; +import { S3_REPOSITORY_SYMBOL } from '@src/common/s3/s3Repository'; +import { cronLoadTileLatLonDataSymbol } from '@src/latLon/DAL/latLonDAL'; +import { RegisterOptions } from '@src/containerConfig'; + +export const getBaseRegisterOptions = (): Required => { + return { + override: [ + { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, + { token: SERVICES.TRACER, provider: { useValue: trace.getTracer('testTracer') } }, + { token: S3_REPOSITORY_SYMBOL, provider: { useValue: {} } }, + { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, + { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, + { token: SERVICES.ELASTIC_CLIENTS, provider: { useValue: {} } }, + ], + useChild: true, + }; +}; diff --git a/tests/integration/mgrs/mgrs.spec.ts b/tests/integration/mgrs/mgrs.spec.ts index 3d827ad..ae68055 100644 --- a/tests/integration/mgrs/mgrs.spec.ts +++ b/tests/integration/mgrs/mgrs.spec.ts @@ -2,34 +2,21 @@ import 'jest-openapi'; import { DependencyContainer } from 'tsyringe'; import { CleanupRegistry } from '@map-colonies/cleanup-registry'; -import jsLogger from '@map-colonies/js-logger'; -import { trace } from '@opentelemetry/api'; import httpStatusCodes from 'http-status-codes'; import { IConfig } from 'config'; import { RedisClient } from '@src/common/redis'; import { getApp } from '../../../src/app'; -import { SERVICES } from '../../../src/common/constants'; -import { S3_REPOSITORY_SYMBOL } from '../../../src/common/s3/s3Repository'; -import { cronLoadTileLatLonDataSymbol } from '../../../src/latLon/DAL/latLonDAL'; +import { redisConfigPath, SERVICES } from '../../../src/common/constants'; import { GenericGeocodingFeatureResponse } from '../../../src/common/interfaces'; import { MgrsRequestSender } from './helpers/requestSender'; +import { getBaseRegisterOptions } from './helpers'; describe('/search/MGRS', function () { let requestSender: MgrsRequestSender; let depContainer: DependencyContainer; beforeEach(async function () { - const [app, container] = await getApp({ - override: [ - { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, - { token: SERVICES.TRACER, provider: { useValue: trace.getTracer('testTracer') } }, - { token: S3_REPOSITORY_SYMBOL, provider: { useValue: {} } }, - { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, - { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, - { token: SERVICES.ELASTIC_CLIENTS, provider: { useValue: {} } }, - ], - useChild: true, - }); + const [app, container] = await getApp(getBaseRegisterOptions()); depContainer = container; requestSender = new MgrsRequestSender(app); @@ -94,16 +81,35 @@ describe('/search/MGRS', function () { describe('Redis uses prefix key', () => { it('should return 200 status code and add key to Redis with prefix', async function () { - const config = depContainer.resolve(SERVICES.CONFIG); - const prefix = config.get('redis.prefix'); - const redisConnection = depContainer.resolve(SERVICES.REDIS); + const realConfig = depContainer.resolve(SERVICES.CONFIG); + const prefix = 'test-prefix-mgrs'; + + const configWithPrefix: IConfig = { + ...realConfig, + get(key: string): T { + if (key === redisConfigPath) { + const realRedisConfig = realConfig.get(redisConfigPath); + return { ...realRedisConfig, prefix } as T; + } + return realConfig.get(key); + }, + }; - const response = await requestSender.getTile({ tile: '18SUJ2339007393' }); + const mockRegisterOptions = getBaseRegisterOptions(); + mockRegisterOptions.override.push({ + token: SERVICES.CONFIG, + provider: { useValue: configWithPrefix }, + }); - const keys = prefix !== undefined ? await redisConnection.keys(prefix + '*') : await redisConnection.keys('*'); + const [mockApp, localContainer] = await getApp(mockRegisterOptions); + const localRequestSender = new MgrsRequestSender(mockApp); - expect(keys.length).toBeGreaterThanOrEqual(1); + const redisConnection = localContainer.resolve(SERVICES.REDIS); + const response = await localRequestSender.getTile({ tile: '18SUJ2339007393' }); + + const keys = await redisConnection.keys(prefix + '*'); + expect(keys.length).toBeGreaterThanOrEqual(1); expect(response.status).toBe(httpStatusCodes.OK); }); }); From 435a53a075cb56a4b8c3c99a3ab2b43a2122f745 Mon Sep 17 00:00:00 2001 From: NatalieShaked Date: Thu, 25 Dec 2025 11:20:09 +0200 Subject: [PATCH 09/10] test: added options to baseRegisterOptions --- tests/integration/control/item/helpers/index.ts | 4 +++- tests/integration/control/item/item.spec.ts | 11 ++++++----- tests/integration/control/route/helpers/index.ts | 4 +++- tests/integration/control/route/route.spec.ts | 11 ++++++----- tests/integration/control/tile/helpers/index.ts | 4 +++- tests/integration/control/tile/tile.spec.ts | 11 ++++++----- tests/integration/location/helpers/index.ts | 4 +++- tests/integration/location/location.spec.ts | 11 ++++++----- tests/integration/mgrs/helpers/index.ts | 4 +++- tests/integration/mgrs/mgrs.spec.ts | 11 ++++++----- 10 files changed, 45 insertions(+), 30 deletions(-) diff --git a/tests/integration/control/item/helpers/index.ts b/tests/integration/control/item/helpers/index.ts index 52580f6..6a343d9 100644 --- a/tests/integration/control/item/helpers/index.ts +++ b/tests/integration/control/item/helpers/index.ts @@ -4,8 +4,9 @@ import { SERVICES } from '@src/common/constants'; import { S3_REPOSITORY_SYMBOL } from '@src/common/s3/s3Repository'; import { cronLoadTileLatLonDataSymbol } from '@src/latLon/DAL/latLonDAL'; import { RegisterOptions } from '@src/containerConfig'; +import { InjectionObject } from '@src/common/dependencyRegistration'; -export const getBaseRegisterOptions = (): Required => { +export const getBaseRegisterOptions = (options: InjectionObject[] = []): Required => { return { override: [ { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, @@ -13,6 +14,7 @@ export const getBaseRegisterOptions = (): Required => { { token: S3_REPOSITORY_SYMBOL, provider: { useValue: {} } }, { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, + ...options, ], useChild: true, }; diff --git a/tests/integration/control/item/item.spec.ts b/tests/integration/control/item/item.spec.ts index 2d8e374..fbbc719 100644 --- a/tests/integration/control/item/item.spec.ts +++ b/tests/integration/control/item/item.spec.ts @@ -253,11 +253,12 @@ describe('/search/control/items', function () { }, }; - const mockRegisterOptions = getBaseRegisterOptions(); - mockRegisterOptions.override.push({ - token: SERVICES.CONFIG, - provider: { useValue: configWithPrefix }, - }); + const mockRegisterOptions = getBaseRegisterOptions([ + { + token: SERVICES.CONFIG, + provider: { useValue: configWithPrefix }, + }, + ]); const [mockApp, localContainer] = await getApp(mockRegisterOptions); const localRequestSender = new ItemRequestSender(mockApp); diff --git a/tests/integration/control/route/helpers/index.ts b/tests/integration/control/route/helpers/index.ts index 52580f6..6a343d9 100644 --- a/tests/integration/control/route/helpers/index.ts +++ b/tests/integration/control/route/helpers/index.ts @@ -4,8 +4,9 @@ import { SERVICES } from '@src/common/constants'; import { S3_REPOSITORY_SYMBOL } from '@src/common/s3/s3Repository'; import { cronLoadTileLatLonDataSymbol } from '@src/latLon/DAL/latLonDAL'; import { RegisterOptions } from '@src/containerConfig'; +import { InjectionObject } from '@src/common/dependencyRegistration'; -export const getBaseRegisterOptions = (): Required => { +export const getBaseRegisterOptions = (options: InjectionObject[] = []): Required => { return { override: [ { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, @@ -13,6 +14,7 @@ export const getBaseRegisterOptions = (): Required => { { token: S3_REPOSITORY_SYMBOL, provider: { useValue: {} } }, { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, + ...options, ], useChild: true, }; diff --git a/tests/integration/control/route/route.spec.ts b/tests/integration/control/route/route.spec.ts index ecce7da..36a1c09 100644 --- a/tests/integration/control/route/route.spec.ts +++ b/tests/integration/control/route/route.spec.ts @@ -389,11 +389,12 @@ describe('/search/control/route', function () { }, }; - const mockRegisterOptions = getBaseRegisterOptions(); - mockRegisterOptions.override.push({ - token: SERVICES.CONFIG, - provider: { useValue: configWithPrefix }, - }); + const mockRegisterOptions = getBaseRegisterOptions([ + { + token: SERVICES.CONFIG, + provider: { useValue: configWithPrefix }, + }, + ]); const [mockApp, localContainer] = await getApp(mockRegisterOptions); const localRequestSender = new RouteRequestSender(mockApp); diff --git a/tests/integration/control/tile/helpers/index.ts b/tests/integration/control/tile/helpers/index.ts index 52580f6..6a343d9 100644 --- a/tests/integration/control/tile/helpers/index.ts +++ b/tests/integration/control/tile/helpers/index.ts @@ -4,8 +4,9 @@ import { SERVICES } from '@src/common/constants'; import { S3_REPOSITORY_SYMBOL } from '@src/common/s3/s3Repository'; import { cronLoadTileLatLonDataSymbol } from '@src/latLon/DAL/latLonDAL'; import { RegisterOptions } from '@src/containerConfig'; +import { InjectionObject } from '@src/common/dependencyRegistration'; -export const getBaseRegisterOptions = (): Required => { +export const getBaseRegisterOptions = (options: InjectionObject[] = []): Required => { return { override: [ { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, @@ -13,6 +14,7 @@ export const getBaseRegisterOptions = (): Required => { { token: S3_REPOSITORY_SYMBOL, provider: { useValue: {} } }, { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, + ...options, ], useChild: true, }; diff --git a/tests/integration/control/tile/tile.spec.ts b/tests/integration/control/tile/tile.spec.ts index e4e10f4..3aa69d1 100644 --- a/tests/integration/control/tile/tile.spec.ts +++ b/tests/integration/control/tile/tile.spec.ts @@ -363,11 +363,12 @@ describe('/search/control/tiles', function () { }, }; - const mockRegisterOptions = getBaseRegisterOptions(); - mockRegisterOptions.override.push({ - token: SERVICES.CONFIG, - provider: { useValue: configWithPrefix }, - }); + const mockRegisterOptions = getBaseRegisterOptions([ + { + token: SERVICES.CONFIG, + provider: { useValue: configWithPrefix }, + }, + ]); const [mockApp, localContainer] = await getApp(mockRegisterOptions); const localRequestSender = new TileRequestSender(mockApp); diff --git a/tests/integration/location/helpers/index.ts b/tests/integration/location/helpers/index.ts index 52580f6..6a343d9 100644 --- a/tests/integration/location/helpers/index.ts +++ b/tests/integration/location/helpers/index.ts @@ -4,8 +4,9 @@ import { SERVICES } from '@src/common/constants'; import { S3_REPOSITORY_SYMBOL } from '@src/common/s3/s3Repository'; import { cronLoadTileLatLonDataSymbol } from '@src/latLon/DAL/latLonDAL'; import { RegisterOptions } from '@src/containerConfig'; +import { InjectionObject } from '@src/common/dependencyRegistration'; -export const getBaseRegisterOptions = (): Required => { +export const getBaseRegisterOptions = (options: InjectionObject[] = []): Required => { return { override: [ { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, @@ -13,6 +14,7 @@ export const getBaseRegisterOptions = (): Required => { { token: S3_REPOSITORY_SYMBOL, provider: { useValue: {} } }, { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, + ...options, ], useChild: true, }; diff --git a/tests/integration/location/location.spec.ts b/tests/integration/location/location.spec.ts index 05402a4..650b171 100644 --- a/tests/integration/location/location.spec.ts +++ b/tests/integration/location/location.spec.ts @@ -543,11 +543,12 @@ describe('/search/location', function () { }, }; - const mockRegisterOptions = getBaseRegisterOptions(); - mockRegisterOptions.override.push({ - token: SERVICES.CONFIG, - provider: { useValue: configWithPrefix }, - }); + const mockRegisterOptions = getBaseRegisterOptions([ + { + token: SERVICES.CONFIG, + provider: { useValue: configWithPrefix }, + }, + ]); const [mockApp, localContainer] = await getApp(mockRegisterOptions); const localRequestSender = new LocationRequestSender(mockApp); diff --git a/tests/integration/mgrs/helpers/index.ts b/tests/integration/mgrs/helpers/index.ts index adcfc64..73da7e7 100644 --- a/tests/integration/mgrs/helpers/index.ts +++ b/tests/integration/mgrs/helpers/index.ts @@ -4,8 +4,9 @@ import { SERVICES } from '@src/common/constants'; import { S3_REPOSITORY_SYMBOL } from '@src/common/s3/s3Repository'; import { cronLoadTileLatLonDataSymbol } from '@src/latLon/DAL/latLonDAL'; import { RegisterOptions } from '@src/containerConfig'; +import { InjectionObject } from '@src/common/dependencyRegistration'; -export const getBaseRegisterOptions = (): Required => { +export const getBaseRegisterOptions = (options: InjectionObject[] = []): Required => { return { override: [ { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, @@ -14,6 +15,7 @@ export const getBaseRegisterOptions = (): Required => { { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, { token: SERVICES.ELASTIC_CLIENTS, provider: { useValue: {} } }, + ...options, ], useChild: true, }; diff --git a/tests/integration/mgrs/mgrs.spec.ts b/tests/integration/mgrs/mgrs.spec.ts index ae68055..ba9eed5 100644 --- a/tests/integration/mgrs/mgrs.spec.ts +++ b/tests/integration/mgrs/mgrs.spec.ts @@ -95,11 +95,12 @@ describe('/search/MGRS', function () { }, }; - const mockRegisterOptions = getBaseRegisterOptions(); - mockRegisterOptions.override.push({ - token: SERVICES.CONFIG, - provider: { useValue: configWithPrefix }, - }); + const mockRegisterOptions = getBaseRegisterOptions([ + { + token: SERVICES.CONFIG, + provider: { useValue: configWithPrefix }, + }, + ]); const [mockApp, localContainer] = await getApp(mockRegisterOptions); const localRequestSender = new MgrsRequestSender(mockApp); From 17ccdf410562135c561daaec7da7efaf652759d8 Mon Sep 17 00:00:00 2001 From: NatalieShaked Date: Thu, 25 Dec 2025 15:12:04 +0200 Subject: [PATCH 10/10] refactor: added type for GetBaseRegisterOptions function --- tests/integration/control/item/helpers/index.ts | 5 ++--- tests/integration/control/item/item.spec.ts | 2 ++ tests/integration/control/route/helpers/index.ts | 5 ++--- tests/integration/control/route/route.spec.ts | 2 ++ tests/integration/control/tile/helpers/index.ts | 5 ++--- tests/integration/control/tile/tile.spec.ts | 2 ++ tests/integration/helpers/types.ts | 4 ++++ tests/integration/location/helpers/index.ts | 5 ++--- tests/integration/location/location.spec.ts | 2 ++ tests/integration/mgrs/helpers/index.ts | 5 ++--- tests/integration/mgrs/mgrs.spec.ts | 2 ++ 11 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 tests/integration/helpers/types.ts diff --git a/tests/integration/control/item/helpers/index.ts b/tests/integration/control/item/helpers/index.ts index 6a343d9..84115c1 100644 --- a/tests/integration/control/item/helpers/index.ts +++ b/tests/integration/control/item/helpers/index.ts @@ -3,10 +3,9 @@ import { trace } from '@opentelemetry/api'; import { SERVICES } from '@src/common/constants'; import { S3_REPOSITORY_SYMBOL } from '@src/common/s3/s3Repository'; import { cronLoadTileLatLonDataSymbol } from '@src/latLon/DAL/latLonDAL'; -import { RegisterOptions } from '@src/containerConfig'; -import { InjectionObject } from '@src/common/dependencyRegistration'; +import { GetBaseRegisterOptions } from '@tests/integration/helpers/types'; -export const getBaseRegisterOptions = (options: InjectionObject[] = []): Required => { +export const getBaseRegisterOptions: GetBaseRegisterOptions = (options = []) => { return { override: [ { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, diff --git a/tests/integration/control/item/item.spec.ts b/tests/integration/control/item/item.spec.ts index fbbc719..67d2e53 100644 --- a/tests/integration/control/item/item.spec.ts +++ b/tests/integration/control/item/item.spec.ts @@ -271,6 +271,8 @@ describe('/search/control/items', function () { const keys = await redisConnection.keys(prefix + '*'); expect(keys.length).toBeGreaterThanOrEqual(1); expect(response.status).toBe(httpStatusCodes.OK); + + await localContainer.dispose(); }); }); }); diff --git a/tests/integration/control/route/helpers/index.ts b/tests/integration/control/route/helpers/index.ts index 6a343d9..84115c1 100644 --- a/tests/integration/control/route/helpers/index.ts +++ b/tests/integration/control/route/helpers/index.ts @@ -3,10 +3,9 @@ import { trace } from '@opentelemetry/api'; import { SERVICES } from '@src/common/constants'; import { S3_REPOSITORY_SYMBOL } from '@src/common/s3/s3Repository'; import { cronLoadTileLatLonDataSymbol } from '@src/latLon/DAL/latLonDAL'; -import { RegisterOptions } from '@src/containerConfig'; -import { InjectionObject } from '@src/common/dependencyRegistration'; +import { GetBaseRegisterOptions } from '@tests/integration/helpers/types'; -export const getBaseRegisterOptions = (options: InjectionObject[] = []): Required => { +export const getBaseRegisterOptions: GetBaseRegisterOptions = (options = []) => { return { override: [ { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, diff --git a/tests/integration/control/route/route.spec.ts b/tests/integration/control/route/route.spec.ts index 36a1c09..f47bc05 100644 --- a/tests/integration/control/route/route.spec.ts +++ b/tests/integration/control/route/route.spec.ts @@ -407,6 +407,8 @@ describe('/search/control/route', function () { const keys = await redisConnection.keys(prefix + '*'); expect(keys.length).toBeGreaterThanOrEqual(1); expect(response.status).toBe(httpStatusCodes.OK); + + await localContainer.dispose(); }); }); }); diff --git a/tests/integration/control/tile/helpers/index.ts b/tests/integration/control/tile/helpers/index.ts index 6a343d9..84115c1 100644 --- a/tests/integration/control/tile/helpers/index.ts +++ b/tests/integration/control/tile/helpers/index.ts @@ -3,10 +3,9 @@ import { trace } from '@opentelemetry/api'; import { SERVICES } from '@src/common/constants'; import { S3_REPOSITORY_SYMBOL } from '@src/common/s3/s3Repository'; import { cronLoadTileLatLonDataSymbol } from '@src/latLon/DAL/latLonDAL'; -import { RegisterOptions } from '@src/containerConfig'; -import { InjectionObject } from '@src/common/dependencyRegistration'; +import { GetBaseRegisterOptions } from '@tests/integration/helpers/types'; -export const getBaseRegisterOptions = (options: InjectionObject[] = []): Required => { +export const getBaseRegisterOptions: GetBaseRegisterOptions = (options = []) => { return { override: [ { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, diff --git a/tests/integration/control/tile/tile.spec.ts b/tests/integration/control/tile/tile.spec.ts index 3aa69d1..7a67a02 100644 --- a/tests/integration/control/tile/tile.spec.ts +++ b/tests/integration/control/tile/tile.spec.ts @@ -382,6 +382,8 @@ describe('/search/control/tiles', function () { const keys = await redisConnection.keys(prefix + '*'); expect(keys.length).toBeGreaterThanOrEqual(1); expect(response.status).toBe(httpStatusCodes.OK); + + await localContainer.dispose(); }); }); }); diff --git a/tests/integration/helpers/types.ts b/tests/integration/helpers/types.ts new file mode 100644 index 0000000..3e80943 --- /dev/null +++ b/tests/integration/helpers/types.ts @@ -0,0 +1,4 @@ +import { RegisterOptions } from '@src/containerConfig'; +import { InjectionObject } from '@src/common/dependencyRegistration'; + +export type GetBaseRegisterOptions = (injectionObjects?: InjectionObject[]) => Required; diff --git a/tests/integration/location/helpers/index.ts b/tests/integration/location/helpers/index.ts index 6a343d9..84115c1 100644 --- a/tests/integration/location/helpers/index.ts +++ b/tests/integration/location/helpers/index.ts @@ -3,10 +3,9 @@ import { trace } from '@opentelemetry/api'; import { SERVICES } from '@src/common/constants'; import { S3_REPOSITORY_SYMBOL } from '@src/common/s3/s3Repository'; import { cronLoadTileLatLonDataSymbol } from '@src/latLon/DAL/latLonDAL'; -import { RegisterOptions } from '@src/containerConfig'; -import { InjectionObject } from '@src/common/dependencyRegistration'; +import { GetBaseRegisterOptions } from '@tests/integration/helpers/types'; -export const getBaseRegisterOptions = (options: InjectionObject[] = []): Required => { +export const getBaseRegisterOptions: GetBaseRegisterOptions = (options = []) => { return { override: [ { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, diff --git a/tests/integration/location/location.spec.ts b/tests/integration/location/location.spec.ts index 650b171..bde71c0 100644 --- a/tests/integration/location/location.spec.ts +++ b/tests/integration/location/location.spec.ts @@ -560,6 +560,8 @@ describe('/search/location', function () { const keys = await redisConnection.keys(prefix + '*'); expect(keys.length).toBeGreaterThanOrEqual(1); expect(response.status).toBe(httpStatusCodes.OK); + + await localContainer.dispose(); }); }); }); diff --git a/tests/integration/mgrs/helpers/index.ts b/tests/integration/mgrs/helpers/index.ts index 73da7e7..3791fc1 100644 --- a/tests/integration/mgrs/helpers/index.ts +++ b/tests/integration/mgrs/helpers/index.ts @@ -3,10 +3,9 @@ import { trace } from '@opentelemetry/api'; import { SERVICES } from '@src/common/constants'; import { S3_REPOSITORY_SYMBOL } from '@src/common/s3/s3Repository'; import { cronLoadTileLatLonDataSymbol } from '@src/latLon/DAL/latLonDAL'; -import { RegisterOptions } from '@src/containerConfig'; -import { InjectionObject } from '@src/common/dependencyRegistration'; +import { GetBaseRegisterOptions } from '@tests/integration/helpers/types'; -export const getBaseRegisterOptions = (options: InjectionObject[] = []): Required => { +export const getBaseRegisterOptions: GetBaseRegisterOptions = (options = []) => { return { override: [ { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, diff --git a/tests/integration/mgrs/mgrs.spec.ts b/tests/integration/mgrs/mgrs.spec.ts index ba9eed5..52697f7 100644 --- a/tests/integration/mgrs/mgrs.spec.ts +++ b/tests/integration/mgrs/mgrs.spec.ts @@ -112,6 +112,8 @@ describe('/search/MGRS', function () { const keys = await redisConnection.keys(prefix + '*'); expect(keys.length).toBeGreaterThanOrEqual(1); expect(response.status).toBe(httpStatusCodes.OK); + + await localContainer.dispose(); }); }); });