This repository was archived by the owner on Jul 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 376
LU refactor #717
Merged
Merged
LU refactor #717
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6df5594
rename luPath to botDir
boydc2014 a52d18e
Move things from luIndexer to luPublisher
boydc2014 705ec39
remove unused files interfaces
boydc2014 586a36d
clean
boydc2014 92470b1
clean up
boydc2014 82f567f
remove invalid interface
boydc2014 5c886d9
update publish time after publish, instead of before
boydc2014 c83d764
save after publish
boydc2014 4e4cc1a
move the length checking at later stage and rename some variables
boydc2014 409ab3f
simple test case is better than skiped tests
boydc2014 78c59b0
fix bugs and test cases and no longer add luis.status.json into this.…
liweitian b082efe
Merge branch 'master' into donglei/lu-refactor
boydc2014 16a431a
fix some typos & grammar
a-b-r-o-w-n dfc4b2e
don't muate the objects
boydc2014 599b137
Merge branch 'master' into donglei/lu-refactor
boydc2014 1891bb2
handle comments (#735)
liweitian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 37 additions & 95 deletions
132
Composer/packages/server/__tests__/models/bot/luisPublisher.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,123 +1,65 @@ | ||
| import mock from 'mock-fs'; | ||
| import { FileUpdateType } from '../../../src/models/bot/interface'; | ||
| import { Path } from '../../../src/utility/path'; | ||
|
|
||
| import { LuPublisher } from './../../../src/models/bot/luPublisher'; | ||
| import service from './../../../src/services/storage'; | ||
|
|
||
| jest.mock('azure-storage', () => { | ||
| return {}; | ||
| }); | ||
|
|
||
| const bot1Dir = '/path/to/fake/bot1'; | ||
| const bot2Dir = '/path/to/fake/bot2'; | ||
| const luFile1Path = '/path/to/fake/bot1/a.lu'; | ||
| const luFile2Path = '/path/to/fake/bot2/a.lu'; | ||
|
|
||
| const luisConfig = { | ||
| authoringKey: '111111111111', | ||
| authoringRegion: 'westus', | ||
| defaultLanguage: 'en-us', | ||
| environment: 'test', | ||
| name: 'test', | ||
| }; | ||
|
|
||
| const botDir = Path.join(__dirname, '../../mocks/samplebots/bot1'); | ||
| const storage = service.getStorageClient('default'); | ||
|
|
||
| beforeEach(() => { | ||
| mock({ | ||
| '/path/to/fake/bot1': { | ||
| 'a.lu': ` # Greeting | ||
| - hi`, | ||
| }, | ||
| '/path/to/fake/bot2': { | ||
| 'a.lu': ` # Greeting | ||
| - hi`, | ||
| generated: { | ||
| 'a.en-us.lu.dialog': '', | ||
| 'luis.settings.test.westus.json': ` | ||
| { | ||
| "luis": { | ||
| "a_en-us_lu": "e094b572-2127-4403-8052-cd7a49ec5848" | ||
| }, | ||
| "status": { | ||
| "a_en-us_lu": { | ||
| "version": "0000000005", | ||
| "state": "published" | ||
| } | ||
| } | ||
| } | ||
| `, | ||
| }, | ||
| }, | ||
| describe('luis status management', () => { | ||
| it('will get luis status', async () => { | ||
| const luPublisher = new LuPublisher(botDir, storage); | ||
| const status = await luPublisher.loadStatus(['bot1/a.lu', 'bot1/b.lu', 'bot1/Main.lu']); | ||
| expect(status['bot1/a.lu'].lastUpdateTime).toBe(1); | ||
| expect(status['bot1/a.lu'].lastPublishTime).toBe(0); | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(mock.restore); | ||
| it('can update luis status', async () => { | ||
| const luPublisher = new LuPublisher(botDir, storage); | ||
|
|
||
| describe.skip('getLuisStatus', () => { | ||
| it('will get luis status', async () => { | ||
| const luPublisher = new LuPublisher(bot2Dir, storage); | ||
| luPublisher.setLuisConfig(luisConfig); | ||
| const settings = await luPublisher.getLuisStatus(); | ||
| expect(settings[0].name).toEqual('a.lu'); | ||
| expect(settings[0].state).toBe('published'); | ||
| await luPublisher.loadStatus(['bot1/a.lu', 'bot1/b.lu', 'bot1/Main.lu']); | ||
| const oldUpdateTime = luPublisher.status['bot1/a.lu'].lastUpdateTime; | ||
|
|
||
| await luPublisher.onFileChange('bot1/a.lu', FileUpdateType.UPDATE); | ||
| const newUpdateTime = luPublisher.status['bot1/a.lu'].lastUpdateTime; | ||
| // update should increase the update time | ||
| expect(newUpdateTime).toBeGreaterThan(oldUpdateTime); | ||
| }); | ||
| }); | ||
|
|
||
| describe.skip('getUnpublisedFiles', () => { | ||
| it('will get unpublished files when no setting.json exist', async () => { | ||
| describe('get unpublishedFiles', () => { | ||
| it('will get unpublished files', async () => { | ||
| const lufiles = [ | ||
| { | ||
| diagnostics: [], | ||
| id: 'a.lu', | ||
| relativePath: '/path/to/fake/bot1/a.lu', | ||
| id: 'a', | ||
| relativePath: 'bot1/a.lu', | ||
| content: '', | ||
| parsedContent: {}, | ||
| lastUpdateTime: 1, | ||
| lastPublishTime: 1, | ||
| }, | ||
| ]; | ||
| const luPublisher = new LuPublisher(bot1Dir, storage); | ||
| luPublisher.setLuisConfig(luisConfig); | ||
| const files = await luPublisher.getUnpublisedFiles(lufiles); | ||
| expect(files.length).toBe(1); | ||
| }); | ||
|
|
||
| it('will get unpublished files when setting.json exist', async () => { | ||
| const lufiles = [ | ||
| { | ||
| diagnostics: [], | ||
| id: 'a.lu', | ||
| relativePath: '/path/to/fake/bot2/a.lu', | ||
| id: 'b', | ||
| relativePath: 'bot1/b.lu', | ||
| content: '', | ||
| parsedContent: {}, | ||
| lastUpdateTime: 1, | ||
| lastPublishTime: 1, | ||
| }, | ||
| ]; | ||
| const luPublisher = new LuPublisher(bot2Dir, storage); | ||
| luPublisher.setLuisConfig(luisConfig); | ||
| const files = await luPublisher.getUnpublisedFiles(lufiles); | ||
| expect(files.length).toBe(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe.skip('update', () => { | ||
| it('will not update the statuse if no setting.json', async () => { | ||
| const luPublisher = new LuPublisher(bot1Dir, storage); | ||
| luPublisher.setLuisConfig(luisConfig); | ||
| await luPublisher.update(true, luFile1Path); | ||
| const settings = await luPublisher.getLuisStatus(); | ||
| expect(settings).toEqual([]); | ||
| }); | ||
| const luPublisher = new LuPublisher(botDir, storage); | ||
| await luPublisher.loadStatus(['bot1/a.lu', 'bot1/b.lu']); // relative path is key | ||
|
|
||
| it('update the statuse if setting.json exist', async () => { | ||
| const luPublisher = new LuPublisher(bot2Dir, storage); | ||
| luPublisher.setLuisConfig(luisConfig); | ||
| await luPublisher.update(false, luFile2Path); | ||
| let settings = await luPublisher.getLuisStatus(); | ||
| expect(settings[0].state).toBe('published'); | ||
| await luPublisher.update(true, luFile2Path); | ||
| settings = await luPublisher.getLuisStatus(); | ||
| expect(settings[0].state).toBe('unpublished'); | ||
| let files = await luPublisher.getUnpublisedFiles(lufiles); | ||
| expect(files.length).toBe(2); | ||
| const curTime = Date.now(); | ||
| luPublisher.status['bot1/a.lu'].lastPublishTime = curTime; // assumming we publish a.lu | ||
| luPublisher.status['bot1/b.lu'].lastPublishTime = curTime; // and b.lu | ||
| files = await luPublisher.getUnpublisedFiles(lufiles); | ||
| expect(files.length).toBe(0); | ||
|
|
||
| await luPublisher.onFileChange('bot1/a.lu', FileUpdateType.UPDATE); | ||
| files = await luPublisher.getUnpublisedFiles(lufiles); | ||
| expect(files.length).toBe(1); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.