From aa3dd47b70367d2c0e6f696ff8d0546d714d6c17 Mon Sep 17 00:00:00 2001 From: Lucas <31957045+SketchingDev@users.noreply.github.com> Date: Fri, 28 Jul 2023 12:12:45 +0100 Subject: [PATCH] Update tests to remove delay --- .../__tests__/Conversation.spec.ts | 2 ++ .../__tests__/Transcriber.spec.ts | 2 ++ .../__tests__/WebMessengerGuestSession.spec.ts | 5 +++++ .../__tests__/fixtures/NoDelay.ts | 13 +++++++++++++ 4 files changed, 22 insertions(+) create mode 100644 packages/genesys-web-messaging-tester/__tests__/fixtures/NoDelay.ts diff --git a/packages/genesys-web-messaging-tester/__tests__/Conversation.spec.ts b/packages/genesys-web-messaging-tester/__tests__/Conversation.spec.ts index a220a96..90672fa 100644 --- a/packages/genesys-web-messaging-tester/__tests__/Conversation.spec.ts +++ b/packages/genesys-web-messaging-tester/__tests__/Conversation.spec.ts @@ -3,6 +3,7 @@ import WebSocket from 'ws'; import getPort from 'get-port'; import { WebMessageServerFixture } from './fixtures/WebMessageServerFixture'; import { WebMessageServerConnectionFixture } from './fixtures/WebMessageServerConnectionFixture'; +import { NoDelay } from './fixtures/NoDelay'; // eslint-disable-next-line @typescript-eslint/no-var-requires const FakeTimers = require('@sinonjs/fake-timers'); @@ -22,6 +23,7 @@ describe('Conversation', () => { }, {}, () => new WebSocket(`ws://localhost:${genesysServerFixture.port}`), + new NoDelay(), ); serverConnection = await genesysServerFixture.waitForConnection(); diff --git a/packages/genesys-web-messaging-tester/__tests__/Transcriber.spec.ts b/packages/genesys-web-messaging-tester/__tests__/Transcriber.spec.ts index ae75f50..1d2c439 100644 --- a/packages/genesys-web-messaging-tester/__tests__/Transcriber.spec.ts +++ b/packages/genesys-web-messaging-tester/__tests__/Transcriber.spec.ts @@ -12,6 +12,7 @@ import { // eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore } from './fixtures/WebMessageServerConnectionFixture'; +import { NoDelay } from './fixtures/NoDelay'; describe('Transcriber', () => { let genesysServerFixture: WebMessageServerFixture; @@ -29,6 +30,7 @@ describe('Transcriber', () => { }, {}, () => new WebSocket(`ws://localhost:${genesysServerFixture.port}`), + new NoDelay(), ); serverConnection = await genesysServerFixture.waitForConnection(); diff --git a/packages/genesys-web-messaging-tester/__tests__/WebMessengerGuestSession.spec.ts b/packages/genesys-web-messaging-tester/__tests__/WebMessengerGuestSession.spec.ts index 2c337d2..739938b 100644 --- a/packages/genesys-web-messaging-tester/__tests__/WebMessengerGuestSession.spec.ts +++ b/packages/genesys-web-messaging-tester/__tests__/WebMessengerGuestSession.spec.ts @@ -7,6 +7,7 @@ import { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore } from './fixtures/WebMessageServerFixture'; +import { NoDelay } from './fixtures/NoDelay'; describe('WebMessengerGuestSession', () => { let genesysServerFixture: WebMessageServerFixture; @@ -50,6 +51,7 @@ describe('WebMessengerGuestSession', () => { }, {}, () => new WebSocket(`ws://localhost:${genesysServerFixture.port}`), + new NoDelay(), ); const connectionToServer = await genesysServerFixture.waitForConnection(); @@ -69,6 +71,7 @@ describe('WebMessengerGuestSession', () => { }, {}, () => new WebSocket(`ws://localhost:${genesysServerFixture.port}`), + new NoDelay(), ); const serverConnection = await genesysServerFixture.waitForConnection(); @@ -94,6 +97,7 @@ describe('WebMessengerGuestSession', () => { }, {}, () => new WebSocket(`ws://localhost:${genesysServerFixture.port}`), + new NoDelay(), ); (await genesysServerFixture.waitForConnection()).simulateOutboundTextStructuredMessage( @@ -131,6 +135,7 @@ describe('WebMessengerGuestSession', () => { }, { test: 'test-value' }, () => new WebSocket(`ws://localhost:${genesysServerFixture.port}`), + new NoDelay(), ); const serverConnection = await genesysServerFixture.waitForConnection(); diff --git a/packages/genesys-web-messaging-tester/__tests__/fixtures/NoDelay.ts b/packages/genesys-web-messaging-tester/__tests__/fixtures/NoDelay.ts new file mode 100644 index 0000000..4e2b2c8 --- /dev/null +++ b/packages/genesys-web-messaging-tester/__tests__/fixtures/NoDelay.ts @@ -0,0 +1,13 @@ +import { EventEmitter } from 'events'; +import { Response } from '../../src/genesys/Response'; +import { MessageDelayer } from '../../src/genesys/message-delayer/MessageDelayer'; + +export class NoDelay extends EventEmitter implements MessageDelayer { + constructor() { + super(); + } + + public add(message: Response): void { + this.emit('message', message); + } +}