// {{ display_name }} MCP server — generated by mcpify. Do not hand-edit.

import { describe, expect, it } from 'vitest';

import { createPkcePair, OAuth2Strategy } from '../../../src/auth/strategies/oauth2.js';

describe('OAuth2Strategy', () => {
  it('throws when clientId/tokenUrl are missing', async () => {
    const strategy = new OAuth2Strategy();
    await expect(strategy.authenticate({})).rejects.toThrow();
  });

  it('validateCredentials requires an accessToken and respects expiry', () => {
    const strategy = new OAuth2Strategy();
    expect(strategy.validateCredentials({ accessToken: 'abc' })).toBe(true);
    expect(strategy.validateCredentials({ accessToken: 'abc', expiresAt: String(Date.now() - 1000) })).toBe(false);
    expect(strategy.validateCredentials({})).toBe(false);
  });
});

describe('createPkcePair', () => {
  it('generates a verifier and a derived challenge', () => {
    const { verifier, challenge } = createPkcePair();
    expect(verifier).toMatch(/^[\w-]+$/);
    expect(challenge).toMatch(/^[\w-]+$/);
    expect(challenge).not.toBe(verifier);
  });
});
