@yoctol/kurator
Advanced tools
Comparing version 0.5.6 to 0.5.7
{ | ||
"name": "@yoctol/kurator", | ||
"license": "UNLICENSED", | ||
"version": "0.5.6", | ||
"version": "0.5.7", | ||
"main": "src/index.js", | ||
@@ -6,0 +6,0 @@ "files": [ |
@@ -47,3 +47,3 @@ const nock = require('nock'); | ||
async function setup() { | ||
async function setup(options = {}) { | ||
nock('https://kurator.yoctol.com') | ||
@@ -56,2 +56,3 @@ .get('/api/projects/1/definition') | ||
accessToken: 'ACCESS_TOKEN', | ||
...options, | ||
}); | ||
@@ -97,2 +98,15 @@ | ||
}); | ||
it('should support actionMap', async () => { | ||
const { kurator } = await setup({ actionMap: { 測試: '1' } }); | ||
const context = { | ||
sendText: jest.fn(), | ||
}; | ||
const action = kurator.getAction('測試'); | ||
await action(context); | ||
expect(context.sendText).toBeCalledWith('基本的', {}); | ||
}); | ||
}); | ||
@@ -99,0 +113,0 @@ |
@@ -20,3 +20,3 @@ const B = require('bottender-compose'); | ||
class Kurator { | ||
constructor({ projectId, accessToken, origin }) { | ||
constructor({ projectId, accessToken, origin, actionMap }) { | ||
this._projectId = projectId; | ||
@@ -36,2 +36,3 @@ this._accessToken = accessToken; | ||
this._predicates = []; | ||
this._actionMap = actionMap || {}; | ||
@@ -93,3 +94,5 @@ this._initPromise = this.syncDefinition(); | ||
return (...args) => { | ||
const action = this._remoteActions[actionId]; | ||
const action = | ||
this._remoteActions[actionId] || | ||
this._remoteActions[this._actionMap[actionId]]; | ||
@@ -107,3 +110,6 @@ if (!action) { | ||
} | ||
return this._remoteActions[actionId]; | ||
return ( | ||
this._remoteActions[actionId] || | ||
this._remoteActions[this._actionMap[actionId]] | ||
); | ||
} | ||
@@ -110,0 +116,0 @@ |
46715
1590