import { TestBed } from '@angular/core/testing';
import { Router } from '@angular/router';
import { describe, expect, it, vi } from 'vitest';
import { Callback } from './callback';
import { AuthService } from '../auth.service';

describe('Callback', () => {
  it('completes the OIDC login and navigates to /trips', async () => {
    const authService = { completeLogin: vi.fn().mockResolvedValue(undefined) };
    const router = { navigateByUrl: vi.fn().mockResolvedValue(true) };

    await TestBed.configureTestingModule({
      imports: [Callback],
      providers: [
        { provide: AuthService, useValue: authService },
        { provide: Router, useValue: router },
      ],
    }).compileComponents();

    const fixture = TestBed.createComponent(Callback);
    fixture.detectChanges();
    await fixture.whenStable();

    expect(authService.completeLogin).toHaveBeenCalledTimes(1);
    expect(router.navigateByUrl).toHaveBeenCalledWith('/trips');
  });
});
