63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import {
|
|
resolveMongoAppName,
|
|
resolveMongoConnectionOptions,
|
|
resolveMongoDbName,
|
|
} from './connection.service';
|
|
|
|
describe('resolveMongoDbName', () => {
|
|
it('uses production database only for prod', () => {
|
|
expect(resolveMongoDbName('prod')).toBe('lolympus');
|
|
});
|
|
|
|
it('uses isolated databases for non-production environments', () => {
|
|
expect(resolveMongoDbName('dev')).toBe('lolympus-dev');
|
|
expect(resolveMongoDbName('staging')).toBe('lolympus-staging');
|
|
expect(resolveMongoDbName('')).toBe('lolympus-dev');
|
|
expect(resolveMongoDbName('local')).toBe('lolympus-dev');
|
|
});
|
|
});
|
|
|
|
describe('resolveMongoAppName', () => {
|
|
it('identifies api environment and process for MongoDB connection tracking', () => {
|
|
expect(resolveMongoAppName('staging', 1234)).toBe(
|
|
'lolympus-api:staging:1234',
|
|
);
|
|
});
|
|
|
|
it('uses dev as the fallback environment label', () => {
|
|
expect(resolveMongoAppName('', 1234)).toBe('lolympus-api:dev:1234');
|
|
});
|
|
});
|
|
|
|
describe('resolveMongoConnectionOptions', () => {
|
|
it('disables automatic collection and index creation by default', () => {
|
|
expect(
|
|
resolveMongoConnectionOptions('lolympus-dev', 'lolympus-api:dev:1'),
|
|
).toEqual({
|
|
dbName: 'lolympus-dev',
|
|
appName: 'lolympus-api:dev:1',
|
|
minPoolSize: 10,
|
|
maxPoolSize: 20,
|
|
autoIndex: false,
|
|
autoCreate: false,
|
|
});
|
|
});
|
|
|
|
it('enables automatic index creation when explicitly requested', () => {
|
|
expect(
|
|
resolveMongoConnectionOptions(
|
|
'lolympus-staging',
|
|
'lolympus-api:staging:1',
|
|
'true',
|
|
),
|
|
).toEqual({
|
|
dbName: 'lolympus-staging',
|
|
appName: 'lolympus-api:staging:1',
|
|
minPoolSize: 10,
|
|
maxPoolSize: 20,
|
|
autoIndex: true,
|
|
autoCreate: false,
|
|
});
|
|
});
|
|
});
|