Skip to content

Commit

Permalink
Look reservations up properly for hasTaskControl check
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhand committed Sep 17, 2024
1 parent c8ef305 commit 331a924
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 9 additions & 4 deletions functions/transfer/helpers.private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
7 changes: 3 additions & 4 deletions tests/taskrouterListeners/janitorListener.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ const mockClient: RecursivePartial<Twilio> = {
get: () => ({
tasks: {
get: () => ({
fetch: () =>
Promise.resolve({
sid: 'WRxxx',
}),
reservations: {
list: () => Promise.resolve([{ sid: 'WRxxx' }]),
},
}),
},
}),
Expand Down

0 comments on commit 331a924

Please sign in to comment.