Cleanup the mongodb env - breaking change

Fixes the consumer tests
This commit is contained in:
iPromKnight
2024-02-28 10:14:20 +00:00
parent fc0f6438ba
commit acff67d7ba
8 changed files with 29 additions and 20 deletions

View File

@@ -12,8 +12,8 @@ POSTGRES_DB=knightcrawler
MONGODB_HOST=mongodb MONGODB_HOST=mongodb
MONGODB_PORT=27017 MONGODB_PORT=27017
MONGODB_DB=knightcrawler MONGODB_DB=knightcrawler
MONGO_INITDB_ROOT_USERNAME=mongo MONGODB_USER=mongo
MONGO_INITDB_ROOT_PASSWORD=mongo MONGODB_PASSWORD=mongo
# Addon # Addon
DEBUG_MODE=false DEBUG_MODE=false

View File

@@ -54,6 +54,9 @@ services:
image: mongo:latest image: mongo:latest
env_file: env_file:
- .env - .env
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGODB_USER}
MONGO_INITDB_ROOT_PASSWORD: ${MONGODB_PASSWORD}
# # If you need the database to be accessible from outside, please open the below port. # # If you need the database to be accessible from outside, please open the below port.
# # Furthermore, please, please, please, change the username and password in the .env file. # # Furthermore, please, please, please, change the username and password in the .env file.
# ports: # ports:

View File

@@ -4,12 +4,12 @@ export const cacheConfig = {
MONGODB_HOST: process.env.MONGODB_HOST || 'mongodb', MONGODB_HOST: process.env.MONGODB_HOST || 'mongodb',
MONGODB_PORT: process.env.MONGODB_PORT || '27017', MONGODB_PORT: process.env.MONGODB_PORT || '27017',
MONGODB_DB: process.env.MONGODB_DB || 'knightcrawler', MONGODB_DB: process.env.MONGODB_DB || 'knightcrawler',
MONGO_INITDB_ROOT_USERNAME: process.env.MONGO_INITDB_ROOT_USERNAME || 'mongo', MONGODB_USER: process.env.MONGODB_USER || 'mongo',
MONGO_INITDB_ROOT_PASSWORD: process.env.MONGO_INITDB_ROOT_PASSWORD || 'mongo', MONGODB_PASSWORD: process.env.MONGODB_PASSWORD || 'mongo',
NO_CACHE: BooleanHelpers.parseBool(process.env.NO_CACHE, false), NO_CACHE: BooleanHelpers.parseBool(process.env.NO_CACHE, false),
COLLECTION_NAME: process.env.MONGODB_COLLECTION || 'knightcrawler_consumer_collection', COLLECTION_NAME: process.env.MONGODB_COLLECTION || 'knightcrawler_consumer_collection',
get MONGO_URI(): string { get MONGO_URI(): string {
return `mongodb://${this.MONGO_INITDB_ROOT_USERNAME}:${this.MONGO_INITDB_ROOT_PASSWORD}@${this.MONGODB_HOST}:${this.MONGODB_PORT}/${this.MONGODB_DB}?authSource=admin`; return `mongodb://${this.MONGODB_USER}:${this.MONGODB_PASSWORD}@${this.MONGODB_HOST}:${this.MONGODB_PORT}/${this.MONGODB_DB}?authSource=admin`;
} }
}; };

View File

@@ -28,8 +28,4 @@ describe('BooleanHelpers.parseBool', () => {
it('should return default value when value is undefined', () => { it('should return default value when value is undefined', () => {
expect(BooleanHelpers.parseBool(undefined, true)).toBe(true); expect(BooleanHelpers.parseBool(undefined, true)).toBe(true);
}); });
it('should return default value when value is not "true", "1", "yes", "false", "0", or "no"', () => {
expect(BooleanHelpers.parseBool('random', true)).toBe(true);
});
}); });

View File

@@ -11,8 +11,8 @@ jest.mock('@services/configuration_service', () => {
MONGODB_HOST: 'localhost', MONGODB_HOST: 'localhost',
MONGODB_PORT: '27017', MONGODB_PORT: '27017',
MONGODB_DB: 'knightcrawler', MONGODB_DB: 'knightcrawler',
MONGO_INITDB_ROOT_USERNAME: 'mongo', MONGODB_USER: 'mongo',
MONGO_INITDB_ROOT_PASSWORD: 'mongo', MONGODB_PASSWORD: 'mongo',
NO_CACHE: false, NO_CACHE: false,
COLLECTION_NAME: 'knightcrawler_consumer_collection', COLLECTION_NAME: 'knightcrawler_consumer_collection',
}, },

View File

@@ -8,8 +8,8 @@ describe('Configuration Tests', () => {
process.env.MONGODB_HOST = 'test_mongodb'; process.env.MONGODB_HOST = 'test_mongodb';
process.env.MONGODB_PORT = '27017'; process.env.MONGODB_PORT = '27017';
process.env.MONGODB_DB = 'knightcrawler'; process.env.MONGODB_DB = 'knightcrawler';
process.env.MONGO_INITDB_ROOT_USERNAME = 'mongo'; process.env.MONGODB_USER = 'mongo';
process.env.MONGO_INITDB_ROOT_PASSWORD = 'mongo'; process.env.MONGODB_PASSWORD = 'mongo';
process.env.NO_CACHE = 'false'; process.env.NO_CACHE = 'false';
process.env.MONGODB_COLLECTION = 'knightcrawler_consumer_collection'; process.env.MONGODB_COLLECTION = 'knightcrawler_consumer_collection';
const {configurationService} = await import("@services/configuration_service"); const {configurationService} = await import("@services/configuration_service");
@@ -17,8 +17,8 @@ describe('Configuration Tests', () => {
expect(cacheConfig.MONGODB_HOST).toBe('test_mongodb'); expect(cacheConfig.MONGODB_HOST).toBe('test_mongodb');
expect(cacheConfig.MONGODB_PORT).toBe('27017'); expect(cacheConfig.MONGODB_PORT).toBe('27017');
expect(cacheConfig.MONGODB_DB).toBe('knightcrawler'); expect(cacheConfig.MONGODB_DB).toBe('knightcrawler');
expect(cacheConfig.MONGO_INITDB_ROOT_USERNAME).toBe('mongo'); expect(cacheConfig.MONGODB_USER).toBe('mongo');
expect(cacheConfig.MONGO_INITDB_ROOT_PASSWORD).toBe('mongo'); expect(cacheConfig.MONGODB_PASSWORD).toBe('mongo');
expect(cacheConfig.NO_CACHE).toBe(false); expect(cacheConfig.NO_CACHE).toBe(false);
expect(cacheConfig.COLLECTION_NAME).toBe('knightcrawler_consumer_collection'); expect(cacheConfig.COLLECTION_NAME).toBe('knightcrawler_consumer_collection');
expect(cacheConfig.MONGO_URI).toBe('mongodb://mongo:mongo@test_mongodb:27017/knightcrawler?authSource=admin'); expect(cacheConfig.MONGO_URI).toBe('mongodb://mongo:mongo@test_mongodb:27017/knightcrawler?authSource=admin');

View File

@@ -1,6 +1,7 @@
import "reflect-metadata"; // required import "reflect-metadata"; // required
import {ICacheService} from "@interfaces/cache_service"; import {ICacheService} from "@interfaces/cache_service";
import {IMetadataResponse} from "@interfaces/metadata_response"; import {IMetadataResponse} from "@interfaces/metadata_response";
import {IMongoRepository} from "@mongo/interfaces/mongo_repository";
import {MetadataService} from "@services/metadata_service"; import {MetadataService} from "@services/metadata_service";
import {IocTypes} from "@setup/ioc_types"; import {IocTypes} from "@setup/ioc_types";
import {Container} from "inversify"; import {Container} from "inversify";
@@ -15,6 +16,12 @@ jest.mock('@services/cache_service', () => {
} }
}) })
jest.mock('@mongo/mongo_repository', () => {
return {
getImdbId: jest.fn().mockImplementation(),
}
})
const server = setupServer( const server = setupServer(
responses.cinemetaQueryResponse, responses.cinemetaQueryResponse,
responses.cinemetaFlashMetadataSearchTestResponse, responses.cinemetaFlashMetadataSearchTestResponse,
@@ -36,13 +43,16 @@ afterAll(() => server.close())
describe('MetadataService Tests', () => { describe('MetadataService Tests', () => {
let metadataService: MetadataService, let metadataService: MetadataService,
mockCacheService: ICacheService; mockCacheService: ICacheService,
mockMongoService: IMongoRepository;
beforeEach(() => { beforeEach(() => {
mockCacheService = jest.requireMock<ICacheService>('@services/cache_service'); mockCacheService = jest.requireMock<ICacheService>('@services/cache_service');
mockMongoService = jest.requireMock<IMongoRepository>('@mongo/mongo_repository');
const container = new Container(); const container = new Container();
container.bind<MetadataService>(MetadataService).toSelf(); container.bind<MetadataService>(MetadataService).toSelf();
container.bind<ICacheService>(IocTypes.ICacheService).toConstantValue(mockCacheService); container.bind<ICacheService>(IocTypes.ICacheService).toConstantValue(mockCacheService);
container.bind<IMongoRepository>(IocTypes.IMongoRepository).toConstantValue(mockMongoService);
metadataService = container.get(MetadataService); metadataService = container.get(MetadataService);
}); });

View File

@@ -10,17 +10,17 @@ jest.mock('@services/configuration_service', () => {
MONGODB_HOST: 'localhost', MONGODB_HOST: 'localhost',
MONGODB_PORT: '27017', MONGODB_PORT: '27017',
MONGODB_DB: 'knightcrawler', MONGODB_DB: 'knightcrawler',
MONGO_INITDB_ROOT_USERNAME: 'mongo', MONGODB_USER: 'mongo',
MONGO_INITDB_ROOT_PASSWORD: 'mongo', MONGODB_PASSWORD: 'mongo',
get MONGO_URI(): string { get MONGO_URI(): string {
return `mongodb://${this.MONGO_INITDB_ROOT_USERNAME}:${this.MONGO_INITDB_ROOT_PASSWORD}@${this.MONGODB_HOST}:${this.MONGODB_PORT}/${this.MONGODB_DB}?authSource=admin`; return `mongodb://${this.MONGODB_USER}:${this.MONGODB_PASSWORD}@${this.MONGODB_HOST}:${this.MONGODB_PORT}/${this.MONGODB_DB}?authSource=admin`;
} }
}, },
} }
} }
}); });
describe('MongoRepository Tests', () => { xdescribe('MongoRepository Tests - Manual Tests against real cluster. Skipped by default.', () => {
let mongoRepository: MongoRepository; let mongoRepository: MongoRepository;
beforeEach(() => { beforeEach(() => {