test(tasks): cover client-mode targeting and missing-advocate guard
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
06842f9031
commit
a1206f9515
1 changed files with 61 additions and 0 deletions
|
|
@ -255,6 +255,67 @@ describe('runGenerateAndAssign — advocate-designation mode', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('runGenerateAndAssign — client mode', () => {
|
||||||
|
const target = { mode: 'client' as const, clientId: 'client-1' }
|
||||||
|
|
||||||
|
it('targets only the specified client and assigns to its own claims advocate', async () => {
|
||||||
|
mockClientFindUnique.mockResolvedValueOnce({
|
||||||
|
id: 'client-1',
|
||||||
|
claimsAdvocateId: 'adv-2',
|
||||||
|
designationId: 'des-1',
|
||||||
|
designation2Id: null,
|
||||||
|
})
|
||||||
|
mockUserFindUnique.mockResolvedValue({ id: 'adv-2', displayName: 'Bob Advocate', isActive: true })
|
||||||
|
mockTaskTemplateFindMany.mockResolvedValue([
|
||||||
|
{
|
||||||
|
id: 'template-1',
|
||||||
|
name: 'Prepare loss summary',
|
||||||
|
description: null,
|
||||||
|
department: 'Commercial Lines',
|
||||||
|
timing: 'PRE_RENEWAL',
|
||||||
|
daysOffset: -1,
|
||||||
|
defaultPriority: 'NORMAL',
|
||||||
|
level: 'RENEWAL_GROUP',
|
||||||
|
},
|
||||||
|
])
|
||||||
|
mockPolicyGroupFindMany.mockResolvedValue([
|
||||||
|
{ id: 'group-1', clientId: 'client-1', renewalDate: new Date('2026-08-01') },
|
||||||
|
])
|
||||||
|
mockClientFindMany.mockResolvedValue([{ id: 'client-1', name: 'Client One' }])
|
||||||
|
|
||||||
|
const result = await runGenerateAndAssign(target, { dryRun: true, actorUserId: 'user-1' })
|
||||||
|
|
||||||
|
expect(mockPolicyGroupFindMany).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({ where: expect.objectContaining({ clientId: { in: ['client-1'] } }) })
|
||||||
|
)
|
||||||
|
expect(result.advocateName).toBe('Bob Advocate')
|
||||||
|
expect(result.clientsFound).toBe(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('throws a 400 error when the client has no claims advocate assigned', async () => {
|
||||||
|
mockClientFindUnique.mockResolvedValueOnce({
|
||||||
|
id: 'client-1',
|
||||||
|
claimsAdvocateId: null,
|
||||||
|
designationId: null,
|
||||||
|
designation2Id: null,
|
||||||
|
})
|
||||||
|
|
||||||
|
await expect(runGenerateAndAssign(target, { dryRun: true, actorUserId: 'user-1' })).rejects.toMatchObject({
|
||||||
|
status: 400,
|
||||||
|
message: 'Client has no claims advocate assigned',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('throws a 404 error when the client does not exist', async () => {
|
||||||
|
mockClientFindUnique.mockResolvedValueOnce(null)
|
||||||
|
|
||||||
|
await expect(runGenerateAndAssign(target, { dryRun: true, actorUserId: 'user-1' })).rejects.toMatchObject({
|
||||||
|
status: 404,
|
||||||
|
message: 'Client not found',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('parseGenerateAndAssignTarget', () => {
|
describe('parseGenerateAndAssignTarget', () => {
|
||||||
it('parses advocate+designation mode', () => {
|
it('parses advocate+designation mode', () => {
|
||||||
const { target, dryRun } = parseGenerateAndAssignTarget({
|
const { target, dryRun } = parseGenerateAndAssignTarget({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue