Skip to content

Commit 0855583

Browse files
committed
add plugin sandbox utils.axios
1 parent b565c11 commit 0855583

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/lib/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,5 @@ export async function downloadScripts(url: string): Promise<string[]> {
151151
*/
152152
export {
153153
clean,
154+
axios,
154155
};

test/plugin/plugin.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('Plugin', () => {
7575
req.variables.name = 'Bob';
7676
req.variables.intent = 'ask name';
7777
~~~
78-
`)
78+
`);
7979
// .plugin('human name', async (req, ctx) => {
8080
// req.variables.name = 'Bob';
8181
// req.variables.intent = 'ask name';
@@ -109,7 +109,7 @@ describe('Plugin', () => {
109109
req.variables.fired = true;
110110
req.$flows.name = 'Bob';
111111
~~~
112-
`)
112+
`);
113113
// .plugin('human name', async (req, ctx) => {
114114
// req.variables.fired = true;
115115
// req.$flows.name = 'Bob';

test/plugin/utils.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { BotScript, Request } from '../../src/engine';
2+
import { assert } from 'chai';
3+
4+
describe('Plugin: utils', () => {
5+
6+
describe('axios', () => {
7+
const botPlugin = new BotScript();
8+
botPlugin
9+
.parse(`
10+
> query answer
11+
12+
+ send question
13+
- answer $answer
14+
15+
/plugin: query answer
16+
~~~js
17+
const vResp = await utils.axios.get('http://httpbin.org/get?answer=42');
18+
req.variables.answer = vResp.data.args.answer;
19+
~~~
20+
`);
21+
22+
it('should get answer from httpbin service', async () => {
23+
let req = new Request('send question');
24+
25+
req = await botPlugin.handleAsync(req);
26+
assert.equal(req.speechResponse, 'answer 42', 'send request and get value back');
27+
});
28+
29+
});
30+
});

0 commit comments

Comments
 (0)