import { describe, it, expect, vi, afterEach } from 'vitest';
import { createSecretStore } from '../../src/secrets/index.js';
import { GnomeKeyringStore } from '../../src/secrets/gnome-keyring.js';
import { FileSecretStore } from '../../src/secrets/file-store.js';

afterEach(() => {
  vi.restoreAllMocks();
});

describe('createSecretStore', () => {
  it('returns GnomeKeyringStore when secret-tool is available', async () => {
    vi.spyOn(GnomeKeyringStore, 'isAvailable').mockResolvedValue(true);
    const store = await createSecretStore();
    expect(store.backend()).toBe('gnome-keyring');
    expect(store).toBeInstanceOf(GnomeKeyringStore);
  });

  it('returns FileSecretStore when secret-tool is not available', async () => {
    vi.spyOn(GnomeKeyringStore, 'isAvailable').mockResolvedValue(false);
    const store = await createSecretStore();
    expect(store.backend()).toBe('file');
    expect(store).toBeInstanceOf(FileSecretStore);
  });
});
