-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLexClient.test.ts
36 lines (32 loc) · 1.1 KB
/
LexClient.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Need to bypass type safety of typescript to allow this approach for mocking to work.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const LexRuntime = require('aws-sdk/clients/lexruntime');
import LexClient from './LexClient';
jest.mock('aws-sdk/clients/lexruntime');
const lexRuntimePostTextPromise = jest.fn().mockReturnValue({
promise: jest.fn().mockResolvedValue({
sessionAttributes: { foo: 'bar' },
message: 'This is a mocked message.',
}),
});
LexRuntime.mockImplementation(() => ({
postText: lexRuntimePostTextPromise,
}));
test('LexClient.speak()', async (): Promise<void> => {
const botContext = {
botName: 'OrderFlowers',
botAlias: 'prod',
region: 'us-east-1',
};
const userContext = {
userId: 'homer',
userAttributes: {
firstName: 'Homer',
lastName: 'Simpson',
address: 'Springfield',
},
};
const botClient = new LexClient(botContext, userContext);
const reply = await botClient.speak('Hello World');
expect(reply).toBe('This is a mocked message.');
});