-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deprecation upgrade code for speech credentials (#2824)
* Fix credentials function and allow empty reference grammar ID * Add entry * Add more tests * Update entry * Fix ESLint * Use .eslintignore
- Loading branch information
Showing
16 changed files
with
295 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,9 @@ | ||
/src/__tests__/**/* | ||
/src/**/*.spec.js | ||
/src/**/*.spec.jsx | ||
/src/**/*.spec.ts | ||
/src/**/*.spec.tsx | ||
/src/**/*.test.js | ||
/src/**/*.test.jsx | ||
/src/**/*.test.ts | ||
/src/**/*.test.tsx |
This file contains 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
This file contains 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
220 changes: 220 additions & 0 deletions
220
packages/bundle/src/createCognitiveServicesSpeechServicesPonyfillFactory.spec.js
This file contains 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,220 @@ | ||
let consoleWarns; | ||
let createCognitiveServicesSpeechServicesPonyfillFactory; | ||
let createPonyfill; | ||
let originalConsole; | ||
|
||
async function resolveFunctionOrValue(fnOrValue) { | ||
return await (typeof fnOrValue === 'function' ? fnOrValue() : fnOrValue); | ||
} | ||
|
||
beforeEach(() => { | ||
jest.mock('web-speech-cognitive-services/lib/SpeechServices', () => jest.fn(() => ({}))); | ||
|
||
originalConsole = console; | ||
consoleWarns = []; | ||
|
||
console = { | ||
...console, | ||
warn: text => consoleWarns.push(text) | ||
}; | ||
|
||
createPonyfill = require('web-speech-cognitive-services/lib/SpeechServices'); | ||
createCognitiveServicesSpeechServicesPonyfillFactory = require('./createCognitiveServicesSpeechServicesPonyfillFactory') | ||
.default; | ||
}); | ||
|
||
afterEach(() => { | ||
console = originalConsole; | ||
|
||
jest.resetModules(); | ||
}); | ||
|
||
test('upgrading string-based authorizationToken to credentials', async () => { | ||
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({ | ||
authorizationToken: 'a1b2c3d', | ||
region: 'westus2' | ||
}); | ||
|
||
ponyfillFactory(); | ||
|
||
const { credentials } = createPonyfill.mock.calls[0][0]; | ||
|
||
await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({ | ||
authorizationToken: 'a1b2c3d', | ||
region: 'westus2' | ||
}); | ||
|
||
expect(consoleWarns[0]).toMatchInlineSnapshot( | ||
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."` | ||
); | ||
}); | ||
|
||
test('upgrading Promise-based authorizationToken to credentials', async () => { | ||
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({ | ||
authorizationToken: (async () => 'a1b2c3d')(), | ||
region: 'westus2' | ||
}); | ||
|
||
ponyfillFactory(); | ||
|
||
const { credentials } = createPonyfill.mock.calls[0][0]; | ||
|
||
await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({ | ||
authorizationToken: 'a1b2c3d', | ||
region: 'westus2' | ||
}); | ||
|
||
expect(consoleWarns[0]).toMatchInlineSnapshot( | ||
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."` | ||
); | ||
}); | ||
|
||
test('upgrading function-based authorizationToken to credentials', async () => { | ||
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({ | ||
authorizationToken: () => 'a1b2c3d', | ||
region: 'westus2' | ||
}); | ||
|
||
ponyfillFactory(); | ||
|
||
const { credentials } = createPonyfill.mock.calls[0][0]; | ||
|
||
await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({ | ||
authorizationToken: 'a1b2c3d', | ||
region: 'westus2' | ||
}); | ||
|
||
expect(consoleWarns[0]).toMatchInlineSnapshot( | ||
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."` | ||
); | ||
}); | ||
|
||
test('upgrading Promise function-based authorizationToken to credentials', async () => { | ||
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({ | ||
authorizationToken: async () => 'a1b2c3d', | ||
region: 'westus2' | ||
}); | ||
|
||
ponyfillFactory(); | ||
|
||
const { credentials } = createPonyfill.mock.calls[0][0]; | ||
|
||
await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({ | ||
authorizationToken: 'a1b2c3d', | ||
region: 'westus2' | ||
}); | ||
|
||
expect(consoleWarns[0]).toMatchInlineSnapshot( | ||
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."` | ||
); | ||
}); | ||
|
||
test('upgrading string-based subscriptionKey to credentials', async () => { | ||
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({ | ||
region: 'westus2', | ||
subscriptionKey: 'a1b2c3d' | ||
}); | ||
|
||
ponyfillFactory(); | ||
|
||
const { credentials } = createPonyfill.mock.calls[0][0]; | ||
|
||
await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({ | ||
region: 'westus2', | ||
subscriptionKey: 'a1b2c3d' | ||
}); | ||
|
||
expect(consoleWarns[0]).toMatchInlineSnapshot( | ||
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."` | ||
); | ||
}); | ||
|
||
test('upgrading string-based subscriptionKey to credentials', async () => { | ||
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({ | ||
region: 'westus2', | ||
subscriptionKey: (async () => 'a1b2c3d')() | ||
}); | ||
|
||
ponyfillFactory(); | ||
|
||
const { credentials } = createPonyfill.mock.calls[0][0]; | ||
|
||
await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({ | ||
region: 'westus2', | ||
subscriptionKey: 'a1b2c3d' | ||
}); | ||
|
||
expect(consoleWarns[0]).toMatchInlineSnapshot( | ||
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."` | ||
); | ||
}); | ||
|
||
test('upgrading function-based subscriptionKey to credentials', async () => { | ||
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({ | ||
region: 'westus2', | ||
subscriptionKey: () => 'a1b2c3d' | ||
}); | ||
|
||
ponyfillFactory(); | ||
|
||
const { credentials } = createPonyfill.mock.calls[0][0]; | ||
|
||
await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({ | ||
region: 'westus2', | ||
subscriptionKey: 'a1b2c3d' | ||
}); | ||
|
||
expect(consoleWarns[0]).toMatchInlineSnapshot( | ||
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."` | ||
); | ||
}); | ||
|
||
test('upgrading Promise function-based subscriptionKey to credentials', async () => { | ||
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({ | ||
region: 'westus2', | ||
subscriptionKey: async () => 'a1b2c3d' | ||
}); | ||
|
||
ponyfillFactory(); | ||
|
||
const { credentials } = createPonyfill.mock.calls[0][0]; | ||
|
||
await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({ | ||
region: 'westus2', | ||
subscriptionKey: 'a1b2c3d' | ||
}); | ||
|
||
expect(consoleWarns[0]).toMatchInlineSnapshot( | ||
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."` | ||
); | ||
}); | ||
|
||
test('providing reference grammar ID', () => { | ||
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({ | ||
credentials: { | ||
authorizationToken: 'a1b2c3d', | ||
region: 'westus2' | ||
} | ||
}); | ||
|
||
ponyfillFactory({ referenceGrammarID: 'a1b2c3d' }); | ||
|
||
const { referenceGrammars } = createPonyfill.mock.calls[0][0]; | ||
|
||
expect(referenceGrammars).toEqual(['luis/a1b2c3d-PRODUCTION']); | ||
}); | ||
|
||
test('not providing reference grammar ID', () => { | ||
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({ | ||
credentials: { | ||
authorizationToken: 'a1b2c3d', | ||
region: 'westus2' | ||
} | ||
}); | ||
|
||
ponyfillFactory({}); | ||
|
||
const { referenceGrammars } = createPonyfill.mock.calls[0][0]; | ||
|
||
expect(referenceGrammars).toEqual([]); | ||
}); |
This file contains 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,9 @@ | ||
/src/__tests__/**/* | ||
/src/**/*.spec.js | ||
/src/**/*.spec.jsx | ||
/src/**/*.spec.ts | ||
/src/**/*.spec.tsx | ||
/src/**/*.test.js | ||
/src/**/*.test.jsx | ||
/src/**/*.test.ts | ||
/src/**/*.test.tsx |
This file contains 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
This file contains 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,9 @@ | ||
/src/__tests__/**/* | ||
/src/**/*.spec.js | ||
/src/**/*.spec.jsx | ||
/src/**/*.spec.ts | ||
/src/**/*.spec.tsx | ||
/src/**/*.test.js | ||
/src/**/*.test.jsx | ||
/src/**/*.test.ts | ||
/src/**/*.test.tsx |
This file contains 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
This file contains 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,9 @@ | ||
/src/__tests__/**/* | ||
/src/**/*.spec.js | ||
/src/**/*.spec.jsx | ||
/src/**/*.spec.ts | ||
/src/**/*.spec.tsx | ||
/src/**/*.test.js | ||
/src/**/*.test.jsx | ||
/src/**/*.test.ts | ||
/src/**/*.test.tsx |
This file contains 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
This file contains 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,9 @@ | ||
/src/__tests__/**/* | ||
/src/**/*.spec.js | ||
/src/**/*.spec.jsx | ||
/src/**/*.spec.ts | ||
/src/**/*.spec.tsx | ||
/src/**/*.test.js | ||
/src/**/*.test.jsx | ||
/src/**/*.test.ts | ||
/src/**/*.test.tsx |
This file contains 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,9 @@ | ||
/src/__tests__/**/* | ||
/src/**/*.spec.js | ||
/src/**/*.spec.jsx | ||
/src/**/*.spec.ts | ||
/src/**/*.spec.tsx | ||
/src/**/*.test.js | ||
/src/**/*.test.jsx | ||
/src/**/*.test.ts | ||
/src/**/*.test.tsx |
This file contains 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.