-
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.
test(plugin-flow-builder): create a test for handoff
- Loading branch information
Showing
2 changed files
with
326 additions
and
2 deletions.
There are no files selected for viewing
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() | ||
}) | ||
}) |
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