Skip to content

Commit

Permalink
feat: Implement setupIntegrationAMITesting
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyfarrell committed Oct 6, 2020
1 parent 19c4861 commit 326aece
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,29 @@ export class AsteriskInstance extends FixtureRunDirectory {
throw new Error('Failed to start asterisk');
}
}

export function setupIntegrationAMITesting(tap, integrationInstance, defaultInstanceID) {
const {Test} = tap;

Test.addAssert('checkAMIEvents', 2, async function ({instanceID, watch, expect, execute}, message, extra) {
const {ami} = integrationInstance[instanceID ?? defaultInstanceID];

watch = [].concat(watch).map(eventName => eventName.toLowerCase());
const events = [];
const listener = ({asObject}) => {
if (watch.includes(asObject.event.toLowerCase())) {
events.push(asObject);
}
};

ami.on('event', listener);
const result = await execute();
await delay(50);
ami.off('event', listener);

this.equal(events.length, expect.length, 'events.length matches', extra);
this.match(events, expect, message || 'events match', extra);

return result;
});
}

0 comments on commit 326aece

Please sign in to comment.