feat: Trigger automations on call answered, rejected and hung up (#2591)
This commit is contained in:
@@ -10,27 +10,53 @@ describe('call condition', () => {
|
||||
expect(() => callConditionSchema.parse({ condition: 'call' })).toThrow();
|
||||
});
|
||||
|
||||
it('should match when call is true', () => {
|
||||
const evaluator = createConditionEvaluator(
|
||||
{ condition: 'call' as const, call: true },
|
||||
createEvaluatorContext(),
|
||||
);
|
||||
|
||||
expect(evaluator.evaluate({}).result).toBeFalsy();
|
||||
expect(evaluator.evaluate({ call: true }).result).toBeTruthy();
|
||||
expect(evaluator.evaluate({ call: false }).result).toBeFalsy();
|
||||
it('should reject a phase that does not exist', () => {
|
||||
expect(() =>
|
||||
callConditionSchema.parse({ condition: 'call', call: 'hungup' }),
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it('should match when call is false', () => {
|
||||
it('should match the ringing phase', () => {
|
||||
const evaluator = createConditionEvaluator(
|
||||
{ condition: 'call' as const, call: false },
|
||||
{ condition: 'call' as const, call: 'ringing' as const },
|
||||
createEvaluatorContext(),
|
||||
);
|
||||
|
||||
expect(evaluator.evaluate({ call: 'ringing' }).result).toBeTruthy();
|
||||
expect(evaluator.evaluate({ call: 'answered' }).result).toBeFalsy();
|
||||
expect(evaluator.evaluate({ call: 'idle' }).result).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should match the answered phase', () => {
|
||||
const evaluator = createConditionEvaluator(
|
||||
{ condition: 'call' as const, call: 'answered' as const },
|
||||
createEvaluatorContext(),
|
||||
);
|
||||
|
||||
expect(evaluator.evaluate({ call: 'answered' }).result).toBeTruthy();
|
||||
expect(evaluator.evaluate({ call: 'ringing' }).result).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should treat an absent call state as idle', () => {
|
||||
const evaluator = createConditionEvaluator(
|
||||
{ condition: 'call' as const, call: 'idle' as const },
|
||||
createEvaluatorContext(),
|
||||
);
|
||||
|
||||
// With no state.call published, the bare condition matches `false`,
|
||||
// so `call: false` is satisfied.
|
||||
expect(evaluator.evaluate({}).result).toBeTruthy();
|
||||
expect(evaluator.evaluate({ call: true }).result).toBeFalsy();
|
||||
expect(evaluator.evaluate({ call: false }).result).toBeTruthy();
|
||||
expect(evaluator.evaluate({ call: 'idle' }).result).toBeTruthy();
|
||||
expect(evaluator.evaluate({ call: 'ringing' }).result).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should match any phase in a list', () => {
|
||||
const evaluator = createConditionEvaluator(
|
||||
{ condition: 'call' as const, call: ['ringing', 'answered'] as const },
|
||||
createEvaluatorContext(),
|
||||
);
|
||||
|
||||
expect(evaluator.evaluate({ call: 'ringing' }).result).toBeTruthy();
|
||||
expect(evaluator.evaluate({ call: 'answered' }).result).toBeTruthy();
|
||||
expect(evaluator.evaluate({ call: 'idle' }).result).toBeFalsy();
|
||||
expect(evaluator.evaluate({}).result).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user