From fa6d82d0fc33ff131182ba1da259f65b7bf8d85d Mon Sep 17 00:00:00 2001 From: Oriol Raventos Date: Tue, 14 May 2024 18:45:57 +0200 Subject: [PATCH] test(plugin-flow-builder): add test for conditional country --- .../tests/conditional-country.test.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 packages/botonic-plugin-flow-builder/tests/conditional-country.test.ts diff --git a/packages/botonic-plugin-flow-builder/tests/conditional-country.test.ts b/packages/botonic-plugin-flow-builder/tests/conditional-country.test.ts new file mode 100644 index 000000000..4a9fb603a --- /dev/null +++ b/packages/botonic-plugin-flow-builder/tests/conditional-country.test.ts @@ -0,0 +1,45 @@ +import { INPUT } from '@botonic/core' +import { describe, test } from '@jest/globals' + +import { FlowText } from '../src/index' +import { ProcessEnvNodeEnvs } from '../src/types' +import { basicFlow } from './helpers/flows/basic' +import { + createFlowBuilderPlugin, + createRequest, + getContentsAfterPreAndBotonicInit, +} from './helpers/utils' + +describe('Check the contents returned by the plugin after conditional country node', () => { + process.env.NODE_ENV = ProcessEnvNodeEnvs.PRODUCTION + const flowBuilderPlugin = createFlowBuilderPlugin(basicFlow) + + test.each([ + ['ES', 'Message only for Spain'], + ['FR', 'Message only for France'], + ['GB', 'Message only for United Kingdom'], + ['DE', 'Message for other countries'], + ])( + 'The content of the country %s is displayed', + async (countryISO: string, messageExpected: string) => { + const request = createRequest({ + input: { data: 'countryConditional', type: INPUT.TEXT }, + plugins: { + // @ts-ignore + flowBuilderPlugin, + }, + extraData: { + language: 'en', + country: countryISO, + }, + }) + + const { contents } = await getContentsAfterPreAndBotonicInit( + request, + flowBuilderPlugin + ) + + expect((contents[0] as FlowText).text).toBe(messageExpected) + } + ) +})