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 374
fix: Added better error handling in pva publish extension's publish method #4837
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6be9b14
Added better error handling for unexpected responses from PVA
tonyanziano bf3b2e4
Merge branch 'main' of https://github.com/microsoft/BotFramework-Comp…
tonyanziano 0c8acf8
Merge branch 'main' into toanzian/fix/pva-err-handling
tonyanziano 9ec2cd7
Merge branch 'main' into toanzian/fix/pva-err-handling
tonyanziano 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import { publish } from './publish'; | ||
|
|
||
| const mockFetch = jest.fn(); | ||
| jest.mock('node-fetch', () => { | ||
| return async (...args) => await mockFetch(args); | ||
| }); | ||
|
|
||
| const mockPublishConfig: any = { | ||
| profileName: 'Publish to Power Virtual Agents', | ||
| baseUrl: 'https://bots.int.customercareintelligence.net/', | ||
| botId: 'myBotId', | ||
| envId: 'myEnvId', | ||
| tenantId: 'myTenantId', | ||
| deleteMissingDependencies: false, | ||
| }; | ||
| const mockBotProject: any = { | ||
| exportToZip: jest.fn((options, cb) => { | ||
| const archive = { | ||
| on: jest.fn((eventName, handler) => { | ||
| if (eventName === 'end') { | ||
| handler(); | ||
| } | ||
| }), | ||
| pipe: jest.fn(), | ||
| unpipe: jest.fn(), | ||
| }; | ||
| cb(archive); | ||
| }), | ||
| }; | ||
| const mockGetAccessToken = jest.fn().mockResolvedValue('accessToken'); | ||
|
|
||
| beforeEach(() => { | ||
| mockFetch.mockClear(); | ||
| }); | ||
|
|
||
| describe('publish()', () => { | ||
| it('should successfully start a publish job', async () => { | ||
| const mockDiagnostics = [ | ||
| { | ||
| message: 'This is a log message from PVA', | ||
| }, | ||
| { | ||
| message: 'This is a second log message from PVA', | ||
| }, | ||
| ]; | ||
| mockFetch.mockResolvedValueOnce({ | ||
| status: 202, | ||
| json: jest.fn().mockResolvedValue({ | ||
| comment: 'testing', | ||
| importedContentEtag: 'W/"version"', | ||
| operationId: 'operationId', | ||
| diagnostics: mockDiagnostics, | ||
| lastUpdateTimeUtc: Date.now(), | ||
| state: 'Validating', | ||
| }), | ||
| }); | ||
| const result = await publish( | ||
| mockPublishConfig, | ||
| mockBotProject, | ||
| { comment: 'testing' }, | ||
| undefined, | ||
| mockGetAccessToken | ||
| ); | ||
|
|
||
| expect(result.status).toBe(202); | ||
| const innerResult = result.result; | ||
| expect(innerResult.message).toBe('Validating bot assets...'); | ||
| expect(innerResult.comment).toBe('testing'); | ||
| expect(innerResult.eTag).toBe('W/"version"'); | ||
| expect(innerResult.log).toEqual( | ||
| mockDiagnostics.map((diag) => `---\n${JSON.stringify(diag, null, 2)}\n---\n`).join('\n') | ||
| ); | ||
| expect(innerResult.id).toBe('operationId'); | ||
| expect(innerResult.action).toEqual(null); | ||
| }); | ||
|
|
||
| it('should surface the status message from PVA if a 202 is not returned', async () => { | ||
| mockFetch.mockResolvedValueOnce({ | ||
| status: 502, | ||
| text: jest.fn().mockResolvedValue('Bad Gateway: The service might be down temporarily.'), | ||
| }); | ||
| const result = await publish( | ||
| mockPublishConfig, | ||
| mockBotProject, | ||
| { comment: 'testing' }, | ||
| undefined, | ||
| mockGetAccessToken | ||
| ); | ||
|
|
||
| expect(result.status).toBe(502); | ||
| expect(result.result.message).toBe('Bad Gateway: The service might be down temporarily.'); | ||
| }); | ||
|
|
||
| it('should surface a 500 and th error message if the publish code throws', async () => { | ||
| mockFetch.mockResolvedValueOnce({ | ||
| status: 202, | ||
| json: jest.fn().mockRejectedValueOnce(new Error('Invalid JSON at position 0: "<"')), | ||
| }); | ||
| const result = await publish( | ||
| mockPublishConfig, | ||
| mockBotProject, | ||
| { comment: 'testing' }, | ||
| undefined, | ||
| mockGetAccessToken | ||
| ); | ||
|
|
||
| expect(result.status).toBe(500); | ||
| expect(result.result.message).toBe('Invalid JSON at position 0: "<"'); | ||
| }); | ||
| }); |
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
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.