import { createMongooseOptions } from './mongoose-options.factory';

describe('createMongooseOptions', () => {
  const config = (values: Record<string, unknown>) => ({
    get: jest.fn((key: string) => values[key]),
  }) as any;

  it('uses a bounded production pool and disables startup index builds', () => {
    const options = createMongooseOptions(config({
      nodeEnv: 'production', 'mongodb.uri': 'mongodb://database/app',
    }));
    expect(options).toEqual(expect.objectContaining({
      autoIndex: false, minPoolSize: 5, maxPoolSize: 100,
      serverSelectionTimeoutMS: 10_000, socketTimeoutMS: 45_000,
    }));
  });

  it('accepts explicit pool and index configuration', () => {
    const options = createMongooseOptions(config({
      nodeEnv: 'production', 'mongodb.uri': 'mongodb://database/app',
      'mongodb.autoIndex': true, 'mongodb.minPoolSize': 10, 'mongodb.maxPoolSize': 200,
    }));
    expect(options.autoIndex).toBe(true);
    expect(options.minPoolSize).toBe(10);
    expect(options.maxPoolSize).toBe(200);
  });
});
