Skip to content

Commit

Permalink
Tidying up
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed Jun 3, 2024
1 parent e0437ab commit 9132ad1
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions src/test/v2.0/support/intent-support-2.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,29 +163,27 @@ export class RaiseIntentControl2_0 {
});
}

async receiveContextStreamFromMockApp(privChannel: PrivateChannel, streamedNumberStart: number, streamedNumberEnd: number): Promise<Listener> {
let timeout;
const wrapper = wrapPromise();

//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) {
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);
receiveContextStreamFromMockApp(privChannel: PrivateChannel, streamedNumberStart: number, streamedNumberEnd: number): Promise<void> {
return new Promise((resolve, reject) => {
//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);

if (streamedNumberStart === streamedNumberEnd) {
resolve();
}

await wrapper.promise;
return listener;
streamedNumberStart += 1;
}).then(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);
})
})
}

unsubscribeListener(listener: Listener): void {
Expand Down

0 comments on commit 9132ad1

Please sign in to comment.