Skip to content

Commit

Permalink
Replacing original method of receiveContextStreamFromMockApp
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed Jun 3, 2024
1 parent 4f1b11a commit e815b60
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/test/v2.0/support/intent-support-2.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,30 +163,29 @@ export class RaiseIntentControl2_0 {
});
}

receiveContextStreamFromMockApp(privChannel: PrivateChannel, streamedNumberStart: number, streamedNumberEnd: number): Promise<Listener> {
return new Promise((resolve, reject) => {
let theListener: Listener | null = null
async receiveContextStreamFromMockApp(privChannel: PrivateChannel, streamedNumberStart: number, streamedNumberEnd: number): Promise<Listener> {
let timeout: number;
const wrapper = wrapPromise();

//receive multiple contexts in succession from intent-k
privChannel.addContextListener(ContextType.testContextZ, (context: IntentUtilityContext) => {
expect(context.number, "Unexpected context stream number received.").to.be.equal(streamedNumberStart);
expect(context.type).to.be.equal(ContextType.testContextZ);
//receive multiple contexts in succession from intent-k
const listener = privChannel.addContextListener(ContextType.testContextZ, (context: IntentUtilityContext) => {
expect(context.number, "Unexpected context stream number received.").to.be.equal(streamedNumberStart);
expect(context.type).to.be.equal(ContextType.testContextZ);

if (streamedNumberStart === streamedNumberEnd) {
resolve(theListener);
}
if (streamedNumberStart === streamedNumberEnd) {
wrapper.resolve();
clearTimeout(timeout);
}

streamedNumberStart += 1;
});

timeout = window.setTimeout(() => {
wrapper.reject("Timeout: did not receive all 5 streamed contexts back from the mock app. onAddContextListener may not have been triggered");
}, constants.WaitTime);

streamedNumberStart += 1;
}).then(listener => {
theListener = listener
setTimeout(() => {
listener.unsubscribe()
if (streamedNumberStart < streamedNumberEnd) {
reject("Timeout: did not receive all 5 streamed contexts back from the mock app. onAddContextListener may not have been triggered");
}
}, constants.WaitTime);
})
})
await wrapper.promise;
return listener;
}

unsubscribeListener(listener: Listener): void {
Expand Down

0 comments on commit e815b60

Please sign in to comment.