-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin-flow-builder: handoff test (#2821)
## Description - Refactor create QueuesApi class and then create a mockQueueAvailability for testing - Add test to check conditional queue and handoff nodes ## Testing Add tests for conditional queue and handoff nodes
- Loading branch information
Showing
4 changed files
with
350 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/botonic-plugin-flow-builder/tests/__mocks__/conditional-queue.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { jest } from '@jest/globals' | ||
|
||
import { | ||
AvailabilityData, | ||
HubtypeQueuesApi, | ||
} from '../../src/functions/conditional-queue-status' | ||
|
||
interface QueueAvailabilityMockOptions { | ||
availableAgents?: number | ||
isOpen?: boolean | ||
name: string | ||
} | ||
|
||
export function mockQueueAvailability({ | ||
availableAgents = 0, | ||
isOpen = false, | ||
name, | ||
}: QueueAvailabilityMockOptions) { | ||
const getQueueAvailabilitySpy = jest.spyOn( | ||
HubtypeQueuesApi.prototype as any, | ||
'getAvailability' | ||
) | ||
|
||
getQueueAvailabilitySpy.mockImplementation( | ||
async (): Promise<AvailabilityData> => { | ||
return { | ||
available: true, | ||
waiting_cases: 0, | ||
availability_threshold_waiting_cases: 0, | ||
open: isOpen, | ||
name, | ||
available_agents: availableAgents, | ||
} | ||
} | ||
) | ||
} |
67 changes: 67 additions & 0 deletions
67
packages/botonic-plugin-flow-builder/tests/handoff.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { INPUT } from '@botonic/core' | ||
import { describe, test } from '@jest/globals' | ||
|
||
import { FlowText } from '../src/index' | ||
import { ProcessEnvNodeEnvs } from '../src/types' | ||
// eslint-disable-next-line jest/no-mocks-import | ||
import { mockQueueAvailability } from './__mocks__/conditional-queue' | ||
import { basicFlow } from './helpers/flows/basic' | ||
import { | ||
createFlowBuilderPlugin, | ||
createRequest, | ||
getContentsAfterPreAndBotonicInit, | ||
} from './helpers/utils' | ||
|
||
describe('Check the content returned by the plugin, when the queue is open', () => { | ||
process.env.NODE_ENV = ProcessEnvNodeEnvs.PRODUCTION | ||
const flowBuilderPlugin = createFlowBuilderPlugin(basicFlow) | ||
|
||
beforeEach(() => mockQueueAvailability({ isOpen: true, name: 'General' })) | ||
|
||
test('The content connected to the status queue open is displayed and a handoff is done', async () => { | ||
const request = createRequest({ | ||
input: { data: 'agent', type: INPUT.TEXT }, | ||
plugins: { | ||
// @ts-ignore | ||
flowBuilderPlugin, | ||
}, | ||
}) | ||
|
||
const { contents } = await getContentsAfterPreAndBotonicInit( | ||
request, | ||
flowBuilderPlugin | ||
) | ||
|
||
expect((contents[0] as FlowText).text).toBe( | ||
'Soon you will be served by a human agent' | ||
) | ||
expect(request.session._botonic_action).toBeDefined() | ||
}) | ||
}) | ||
|
||
describe('The content connected to the closed queue status is displayed and the handoff is not done', () => { | ||
process.env.NODE_ENV = ProcessEnvNodeEnvs.PRODUCTION | ||
const flowBuilderPlugin = createFlowBuilderPlugin(basicFlow) | ||
|
||
beforeEach(() => mockQueueAvailability({ isOpen: false, name: 'General' })) | ||
|
||
test('The content connected to the node before the handoff node is displayed and a handoff is done.', async () => { | ||
const request = createRequest({ | ||
input: { data: 'agent', type: INPUT.TEXT }, | ||
plugins: { | ||
// @ts-ignore | ||
flowBuilderPlugin, | ||
}, | ||
}) | ||
|
||
const { contents } = await getContentsAfterPreAndBotonicInit( | ||
request, | ||
flowBuilderPlugin | ||
) | ||
|
||
expect((contents[0] as FlowText).text).toBe( | ||
'At the moment we are out of office hours' | ||
) | ||
expect(request.session._botonic_action).toBeUndefined() | ||
}) | ||
}) |
Oops, something went wrong.