|
1 | 1 | /* eslint-disable @typescript-eslint/naming-convention */ |
2 | | -import jsLogger from '@map-colonies/js-logger'; |
3 | | -import { trace } from '@opentelemetry/api'; |
4 | 2 | import { CleanupRegistry } from '@map-colonies/cleanup-registry'; |
5 | 3 | import { DependencyContainer } from 'tsyringe'; |
6 | 4 | import httpStatusCodes from 'http-status-codes'; |
| 5 | +import { IConfig } from 'config'; |
| 6 | +import { RedisClient } from '@src/common/redis'; |
7 | 7 | import { getApp } from '../../../../src/app'; |
8 | | -import { SERVICES } from '../../../../src/common/constants'; |
| 8 | +import { redisConfigPath, SERVICES } from '../../../../src/common/constants'; |
9 | 9 | import { GetItemsQueryParams } from '../../../../src/control/item/controllers/itemController'; |
10 | 10 | import { Item } from '../../../../src/control/item/models/item'; |
11 | 11 | import { CommonRequestParameters, GenericGeocodingResponse, GeoContext, GeoContextMode } from '../../../../src/common/interfaces'; |
12 | | -import { cronLoadTileLatLonDataSymbol } from '../../../../src/latLon/DAL/latLonDAL'; |
13 | | -import { S3_REPOSITORY_SYMBOL } from '../../../../src/common/s3/s3Repository'; |
14 | 12 | import { expectedResponse } from '../utils'; |
15 | 13 | import { ITEM_1234, ITEM_1235, ITEM_1236 } from '../../../mockObjects/items'; |
16 | 14 | import { ItemRequestSender } from './helpers/requestSender'; |
| 15 | +import { getBaseRegisterOptions } from './helpers'; |
17 | 16 |
|
18 | 17 | describe('/search/control/items', function () { |
19 | 18 | let requestSender: ItemRequestSender; |
20 | 19 | let depContainer: DependencyContainer; |
21 | 20 |
|
22 | 21 | beforeEach(async function () { |
23 | | - const [app, container] = await getApp({ |
24 | | - override: [ |
25 | | - { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } }, |
26 | | - { token: SERVICES.TRACER, provider: { useValue: trace.getTracer('testTracer') } }, |
27 | | - { token: S3_REPOSITORY_SYMBOL, provider: { useValue: {} } }, |
28 | | - { token: SERVICES.S3_CLIENT, provider: { useValue: {} } }, |
29 | | - { token: cronLoadTileLatLonDataSymbol, provider: { useValue: {} } }, |
30 | | - ], |
31 | | - useChild: true, |
32 | | - }); |
| 22 | + const [app, container] = await getApp(getBaseRegisterOptions()); |
| 23 | + |
33 | 24 | depContainer = container; |
34 | 25 | requestSender = new ItemRequestSender(app); |
35 | 26 | }); |
@@ -245,7 +236,47 @@ describe('/search/control/items', function () { |
245 | 236 | expectedResponse(requestParams, [ITEM_1234, ITEM_1235], expect) |
246 | 237 | ); |
247 | 238 | }); |
| 239 | + |
| 240 | + describe('Redis uses prefix key', () => { |
| 241 | + it('should return 200 status code and add key to Redis with prefix', async function () { |
| 242 | + const realConfig = depContainer.resolve<IConfig>(SERVICES.CONFIG); |
| 243 | + const prefix = 'test-prefix-item'; |
| 244 | + |
| 245 | + const configWithPrefix: IConfig = { |
| 246 | + ...realConfig, |
| 247 | + get<T>(key: string): T { |
| 248 | + if (key === redisConfigPath) { |
| 249 | + const realRedisConfig = realConfig.get<RedisClient>(redisConfigPath); |
| 250 | + return { ...realRedisConfig, prefix } as T; |
| 251 | + } |
| 252 | + return realConfig.get<T>(key); |
| 253 | + }, |
| 254 | + }; |
| 255 | + |
| 256 | + const mockRegisterOptions = getBaseRegisterOptions([ |
| 257 | + { |
| 258 | + token: SERVICES.CONFIG, |
| 259 | + provider: { useValue: configWithPrefix }, |
| 260 | + }, |
| 261 | + ]); |
| 262 | + |
| 263 | + const [mockApp, localContainer] = await getApp(mockRegisterOptions); |
| 264 | + const localRequestSender = new ItemRequestSender(mockApp); |
| 265 | + |
| 266 | + const redisConnection = localContainer.resolve<RedisClient>(SERVICES.REDIS); |
| 267 | + |
| 268 | + const requestParams: GetItemsQueryParams = { command_name: '123', limit: 5, disable_fuzziness: false }; |
| 269 | + const response = await localRequestSender.getItems(requestParams); |
| 270 | + |
| 271 | + const keys = await redisConnection.keys(prefix + '*'); |
| 272 | + expect(keys.length).toBeGreaterThanOrEqual(1); |
| 273 | + expect(response.status).toBe(httpStatusCodes.OK); |
| 274 | + |
| 275 | + await localContainer.dispose(); |
| 276 | + }); |
| 277 | + }); |
248 | 278 | }); |
| 279 | + |
249 | 280 | describe('Bad Path', function () { |
250 | 281 | // All requests with status code of 400 |
251 | 282 | it("should return 400 status code and error message when item's command_name", async function () { |
|
0 commit comments