|
| 1 | +import 'dotenv/config'; |
| 2 | + |
| 3 | +import onErrorResumeNext from 'on-error-resume-next'; |
| 4 | + |
| 5 | +import { timeouts } from './constants.json'; |
| 6 | +import * as createDirectLine from './setup/createDirectLine'; |
| 7 | +import waitForBotToRespond from './setup/waitForBotToRespond'; |
| 8 | + |
| 9 | +describe('Happy path', () => { |
| 10 | + let unsubscribes; |
| 11 | + |
| 12 | + beforeEach(() => unsubscribes = []); |
| 13 | + afterEach(() => unsubscribes.forEach(fn => onErrorResumeNext(fn))); |
| 14 | + |
| 15 | + describe('should receive the welcome message from bot in English', () => { |
| 16 | + let directLine; |
| 17 | + |
| 18 | + describe('using REST', () => { |
| 19 | + beforeEach(() => jest.setTimeout(timeouts.rest)); |
| 20 | + |
| 21 | + test('without conversation start properties', async () => { |
| 22 | + directLine = await createDirectLine.forREST({ token: true }); |
| 23 | + }); |
| 24 | + |
| 25 | + test('without locale in conversation start properties', async () => { |
| 26 | + directLine = await createDirectLine.forREST({ token: true }, { conversationStartProperties: {} }); |
| 27 | + }); |
| 28 | + |
| 29 | + test('with locale "en-US" in conversation start properties', async () => { |
| 30 | + directLine = await createDirectLine.forREST({ token: true }, { conversationStartProperties: { locale: 'en-US' } }); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + describe('using Web Socket', () => { |
| 35 | + beforeEach(() => jest.setTimeout(timeouts.webSocket)); |
| 36 | + |
| 37 | + test('without conversation start properties', async () => { |
| 38 | + directLine = await createDirectLine.forWebSocket({ token: true }); |
| 39 | + }); |
| 40 | + |
| 41 | + test('without locale in conversation start properties', async () => { |
| 42 | + directLine = await createDirectLine.forWebSocket({ token: true }, { conversationStartProperties: {} }); |
| 43 | + }); |
| 44 | + |
| 45 | + test('with locale "en-US" in conversation start properties', async () => { |
| 46 | + directLine = await createDirectLine.forWebSocket({ token: true }, { conversationStartProperties: { locale: 'en-US' } }); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + afterEach(async () => { |
| 51 | + // If directLine object is undefined, that means the test is failing. |
| 52 | + if (!directLine) { return; } |
| 53 | + |
| 54 | + unsubscribes.push(directLine.end.bind(directLine)); |
| 55 | + |
| 56 | + await waitForBotToRespond(directLine, ({ text }) => text === 'Welcome'); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + describe('should receive the welcome message from bot in Chinese', () => { |
| 61 | + let directLine; |
| 62 | + |
| 63 | + describe('using REST', () => { |
| 64 | + beforeEach(() => jest.setTimeout(timeouts.rest)); |
| 65 | + |
| 66 | + test('with locale "zh-CN" in conversation start properties', async () => { |
| 67 | + directLine = await createDirectLine.forREST({ token: true }, { conversationStartProperties: { locale: 'zh-CN' } }); |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
| 71 | + describe('using Web Socket', () => { |
| 72 | + beforeEach(() => jest.setTimeout(timeouts.webSocket)); |
| 73 | + |
| 74 | + test('with locale "zh-CN" in conversation start properties', async () => { |
| 75 | + directLine = await createDirectLine.forWebSocket({ token: true }, { conversationStartProperties: { locale: 'zh-CN' } }); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + afterEach(async () => { |
| 80 | + // If directLine object is undefined, that means the test is failing. |
| 81 | + if (!directLine) { return; } |
| 82 | + |
| 83 | + unsubscribes.push(directLine.end.bind(directLine)); |
| 84 | + |
| 85 | + await waitForBotToRespond(directLine, ({ text }) => text === '欢迎'); |
| 86 | + }); |
| 87 | + }); |
| 88 | +}); |
0 commit comments