/**
 * Tests for the AUTH_GUARD selection in aurora.provider.ts.
 *
 * Verifies that the correct guard is resolved from the DI container
 * based on environment.authStrategy:
 *   - 'password'            → authenticationPasswordGuard
 *   - 'authorization-code'  → authorizationCodeGuard
 *
 * We test the REAL exported `authGuardForStrategy` function so that inverting
 * the condition in the production code would immediately break these tests.
 * A re-implemented copy of the selection logic would NOT catch that regression.
 */
import '@angular/compiler';
import { vi } from 'vitest';

vi.mock('environments/environment', () => ({
  environment: {
    api: { rest: 'http://localhost:8080/api', graphql: 'http://localhost:8080/graphql' },
    authStrategy: 'password' as 'password' | 'authorization-code',
    lang: { base: 'es', fallback: 'es', langs: ['es', 'en'] },
    oAuth: { applicationCode: 'aurora', applicationSecret: 'secret' },
    production: false,
    debug: false,
  },
}));

import { authorizationCodeGuard } from '../@aurora/modules/authentication/guards/adapters/authorization-code.guard';
import { authenticationPasswordGuard } from '../@aurora/modules/authentication/guards/adapters/authentication-password.guard';
import { AUTH_STRATEGY } from '../environments/environment.type';

// Import the REAL exported function from the production provider.
// If this import fails, the function has not been extracted yet.
import { authGuardForStrategy } from './aurora.provider';

describe('authGuardForStrategy — real production function', () => {
  it('returns authenticationPasswordGuard for the "password" strategy', () => {
    const guard = authGuardForStrategy(AUTH_STRATEGY.PASSWORD);
    // This test FAILS if the condition is inverted in aurora.provider.ts.
    expect(guard).toBe(authenticationPasswordGuard);
  });

  it('returns authorizationCodeGuard for the "authorization-code" strategy', () => {
    const guard = authGuardForStrategy(AUTH_STRATEGY.AUTHORIZATION_CODE);
    // This test FAILS if the condition is inverted in aurora.provider.ts.
    expect(guard).toBe(authorizationCodeGuard);
  });

  it('does NOT return authorizationCodeGuard for the "password" strategy', () => {
    const guard = authGuardForStrategy(AUTH_STRATEGY.PASSWORD);
    expect(guard).not.toBe(authorizationCodeGuard);
  });

  it('does NOT return authenticationPasswordGuard for the "authorization-code" strategy', () => {
    const guard = authGuardForStrategy(AUTH_STRATEGY.AUTHORIZATION_CODE);
    expect(guard).not.toBe(authenticationPasswordGuard);
  });
});
