diff --git a/functions/transfer/helpers.private.ts b/functions/transfer/helpers.private.ts index 6c8c5bea..e26e17e4 100644 --- a/functions/transfer/helpers.private.ts +++ b/functions/transfer/helpers.private.ts @@ -39,12 +39,17 @@ export const hasTaskControl = async ( console.debug('hasTaskControl? Yes - Transfer has not started'); return true; } - const task = await client.taskrouter.v1.workspaces.get(workspaceSid).tasks.get(taskSid).fetch(); - const res = taskAttributes.transferMeta?.sidWithTaskControl === task.sid; + const reservations = await client.taskrouter.v1.workspaces + .get(workspaceSid) + .tasks.get(taskSid) + .reservations.list(); + const res = Boolean( + reservations.find((r) => r.sid === taskAttributes.transferMeta?.sidWithTaskControl), + ); console.debug( - `hasTaskControl? ${res ? 'Yes' : 'No'} - ${task.sid} (task.sid) === ${ + `hasTaskControl? ${res ? 'Yes' : 'No'} - ${ taskAttributes.transferMeta?.sidWithTaskControl - } (taskAttributes.transferMeta?.sidWithTaskControl)`, + } (taskAttributes.transferMeta?.sidWithTaskControl) IN (${reservations.map((r) => r.sid)})`, ); return res; }; diff --git a/tests/taskrouterListeners/janitorListener.test.ts b/tests/taskrouterListeners/janitorListener.test.ts index f1bff13a..b18a22e0 100644 --- a/tests/taskrouterListeners/janitorListener.test.ts +++ b/tests/taskrouterListeners/janitorListener.test.ts @@ -79,10 +79,9 @@ const mockClient: RecursivePartial = { get: () => ({ tasks: { get: () => ({ - fetch: () => - Promise.resolve({ - sid: 'WRxxx', - }), + reservations: { + list: () => Promise.resolve([{ sid: 'WRxxx' }]), + }, }), }, }),