Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 3d06d49

Browse files
authored
expose getActiveVersionIds function in lubuild (#671)
* add getVersionIds function and fix a bug * revert changes in comparing app which is fixed in another PR * refactor and add tests
1 parent 7eb2099 commit 3d06d49

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

packages/lu/src/parser/lubuild/builder.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,25 @@ export class Builder {
253253
return writeDone
254254
}
255255

256+
async getActiveVersionIds(appNames: string[], authoringKey: string, region: string) {
257+
const luBuildCore = new LuBuildCore(authoringKey, `https://${region}.api.cognitive.microsoft.com`)
258+
const apps = await luBuildCore.getApplicationList()
259+
let appNameVersionMap = new Map<string, string>()
260+
for (const appName of appNames) {
261+
// find if there is a matched name with current app under current authoring key
262+
appNameVersionMap.set(appName, '')
263+
for (let app of apps) {
264+
if (app.name === appName) {
265+
const appInfo = await luBuildCore.getApplicationInfo(app.id)
266+
appNameVersionMap.set(appName, appInfo.activeVersion)
267+
break
268+
}
269+
}
270+
}
271+
272+
return appNameVersionMap
273+
}
274+
256275
async initApplicationFromLuContent(content: any, botName: string, suffix: string) {
257276
let currentApp = await LuisBuilder.fromLUAsync([content]) // content.parseToLuis(true, content.language)
258277
currentApp.culture = currentApp.culture && currentApp.culture !== '' && currentApp.culture !== 'en-us' ? currentApp.culture : content.language as string
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const assert = require('chai').assert
2+
const nock = require('nock')
3+
const Builder = require('../../../src/parser/lubuild/builder').Builder
4+
5+
describe('builder: getActiveVersionIds function return version id sucessfully', () => {
6+
before(function () {
7+
nock('https://westus.api.cognitive.microsoft.com')
8+
.get(uri => uri.includes('apps'))
9+
.reply(200, [{
10+
name: 'app1',
11+
id: 'f8c64e2a-1111-3a09-8f78-39d7adc76ec5'
12+
}, {
13+
name: 'app2',
14+
id: 'f8c64e2a-2222-3a09-8f78-39d7adc76ec5'
15+
}
16+
])
17+
18+
nock('https://westus.api.cognitive.microsoft.com')
19+
.get(uri => uri.includes('apps'))
20+
.reply(200, {
21+
name: 'app1',
22+
id: 'f8c64e2a-1111-3a09-8f78-39d7adc76ec5',
23+
activeVersion: 0.1
24+
})
25+
26+
nock('https://westus.api.cognitive.microsoft.com')
27+
.get(uri => uri.includes('apps'))
28+
.reply(200, {
29+
name: 'app2',
30+
id: 'f8c64e2a-1111-3a09-8f78-39d7adc76ec5',
31+
activeVersion: 0.2
32+
})
33+
})
34+
35+
it('should get active version ids successfully', async () => {
36+
const builder = new Builder()
37+
const appNameVersioIdMap = await builder.getActiveVersionIds(['app1', 'app2'], 'f8c64e2a-3333-3a09-8f78-39d7adc76ec5', 'westus')
38+
assert.equal(appNameVersioIdMap.get('app1'), '0.1')
39+
assert.equal(appNameVersioIdMap.get('app2'), '0.2')
40+
})
41+
})

0 commit comments

Comments
 (0)