25 lines
1.0 KiB
TypeScript
25 lines
1.0 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|||
|
|
import { Agent } from '@prisma/client';
|
||
|
|
import { AgentsService } from '@/modules/identity/agents/service/agents.service';
|
||
|
|
import { AgentsRepository } from '@/modules/identity/agents/repository/agents.repository';
|
||
|
|
|
||
|
|
function fakeRepo(agent: Agent | null): AgentsRepository {
|
||
|
|
return { findByUserId: async () => agent } as unknown as AgentsRepository;
|
||
|
|
}
|
||
|
|
|
||
|
|
describe('AgentsService.requireAgentForUser', () => {
|
||
|
|
it('resolves the linked Agent when one exists', async () => {
|
||
|
|
const agent = { id: 'agent-1', userId: 'user-1' } as Agent;
|
||
|
|
const service = new AgentsService(fakeRepo(agent));
|
||
|
|
await expect(service.requireAgentForUser('user-1')).resolves.toBe(agent);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('throws a specific NotFoundError when no Agent is linked to this User', async () => {
|
||
|
|
const service = new AgentsService(fakeRepo(null));
|
||
|
|
await expect(service.requireAgentForUser('user-2')).rejects.toMatchObject({
|
||
|
|
statusCode: 404,
|
||
|
|
message: 'No agent profile is linked to this account.',
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|