import { describe, expect, it } from 'vitest';
import type { MosaicConfig } from '@mosaicstack/config';
import { SystemOverrideService } from './system-override.service.js';

const localConfig = { queue: { type: 'local' } } as MosaicConfig;

describe('SystemOverrideService local tier', () => {
  it('keeps ephemeral overrides isolated by tenant and user scope', async () => {
    const service = new SystemOverrideService(localConfig);
    const firstScope = { tenantId: 'tenant-a', userId: 'user-a' };
    const secondScope = { tenantId: 'tenant-b', userId: 'user-b' };

    await service.set('shared-session', 'first override', firstScope);
    await service.set('shared-session', 'second override', secondScope);

    await expect(service.get('shared-session', firstScope)).resolves.toBe('first override');
    await expect(service.get('shared-session', secondScope)).resolves.toBe('second override');

    await service.clear('shared-session', firstScope);
    await expect(service.get('shared-session', firstScope)).resolves.toBeNull();
    await expect(service.get('shared-session', secondScope)).resolves.toBe('second override');
  });
});
