36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { describe, it, expect, vi, type Mock } from 'vitest';
|
|
import { StartAuthUseCase } from './StartAuthUseCase';
|
|
import type { IdentityProviderPort } from '../ports/IdentityProviderPort';
|
|
import type { StartAuthCommandDTO } from '../dto/StartAuthCommandDTO';
|
|
|
|
describe('StartAuthUseCase', () => {
|
|
let provider: {
|
|
startAuth: Mock;
|
|
};
|
|
let useCase: StartAuthUseCase;
|
|
|
|
beforeEach(() => {
|
|
provider = {
|
|
startAuth: vi.fn(),
|
|
};
|
|
|
|
useCase = new StartAuthUseCase(provider as unknown as IdentityProviderPort);
|
|
});
|
|
|
|
it('delegates to the identity provider to start auth', async () => {
|
|
const command: StartAuthCommandDTO = {
|
|
redirectUri: 'https://app/callback',
|
|
provider: 'demo',
|
|
};
|
|
|
|
const expected = { redirectUrl: 'https://auth/redirect', state: 'state-123' };
|
|
|
|
provider.startAuth.mockResolvedValue(expected);
|
|
|
|
const result = await useCase.execute(command);
|
|
|
|
expect(provider.startAuth).toHaveBeenCalledWith(command);
|
|
expect(result).toEqual(expected);
|
|
});
|
|
});
|