[communication] Move @azure/communication-call-automation to ESM/vitest (#31680)
### Packages impacted by this PR - @azure/communication-call-automation ### Issues associated with this PR - https://github.com/Azure/azure-sdk-for-js/issues/31338 ### Describe the problem that is addressed by this PR Migrates package to ESM/vitest. Note that ServiceBus has issues with Browser loads that we can fix in a later revision as Buffer is not defined when you try to import any files. But then including Buffer then also causes issues with the unit tests. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary)
This commit is contained in:
Родитель
5edf27a030
Коммит
0188ca180f
|
@ -12348,7 +12348,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/ai-language-text.tgz:
|
||||
resolution: {integrity: sha512-PqM9ui81lmdhXEtP8GIAjLVcVvlupuMDmN23SvaEKLDAwj7x83KNuxMXUC03nuAu7GGw7f6duJQPj59nEyUXig==, tarball: file:projects/ai-language-text.tgz}
|
||||
resolution: {integrity: sha512-6C3jjNxEgVBUU20JjosTiobhkOlbsaBeUq+OJ0mXgqnm/Y3L5EhJz6zvG8MgM9Mj2yQPfX9VWCy4+Pn9Nkhslw==, tarball: file:projects/ai-language-text.tgz}
|
||||
name: '@rush-temp/ai-language-text'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
|
@ -12506,7 +12506,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/ai-translation-document.tgz:
|
||||
resolution: {integrity: sha512-tczwZFFKsT8A5tYnAH8FLQ1cpw9B0tFIiAVb5wPaI40o9Rx3gBKBxZ7mGU9lPdXwAy03uyqtXOAwr1JzaNTj4A==, tarball: file:projects/ai-translation-document.tgz}
|
||||
resolution: {integrity: sha512-Ab59rauKcO/H7u7fQJ0DmNlyMycKybpGa1Wsaw9GNLpNJxh+ibmPDS44TaOAcFwxOLIadyxaj7vsrmXXkM5Ocg==, tarball: file:projects/ai-translation-document.tgz}
|
||||
name: '@rush-temp/ai-translation-document'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
|
@ -12710,7 +12710,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/api-management-custom-widgets-tools.tgz:
|
||||
resolution: {integrity: sha512-+ezPIFcLbT94W1qUmvCf/8ZmRXgcIp4ZPWPvZChsGG05CeBCDrZecSEeO58F3vnVQDhYQAwOUwmqhgYJanVg0g==, tarball: file:projects/api-management-custom-widgets-tools.tgz}
|
||||
resolution: {integrity: sha512-dMAIacqzLU3uGgVdn+A8r+/Vv7vC4Emr0Z0T3lCVhq7JoQmL3I7yyUueYdP6tPVYSGzko9MdRYXA11RvB9GHPA==, tarball: file:projects/api-management-custom-widgets-tools.tgz}
|
||||
name: '@rush-temp/api-management-custom-widgets-tools'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
|
@ -18933,7 +18933,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/communication-call-automation.tgz:
|
||||
resolution: {integrity: sha512-Fd/HeZS/REzGRLDLjxyqGG1NM1QgMCK7pzWoE0849CzJUyCUGayK6xbpCkvHxhexi1MBvlmwSwIp+Vaixtk0Qg==, tarball: file:projects/communication-call-automation.tgz}
|
||||
resolution: {integrity: sha512-j9rSk+SzAA5RTLrNqnlSWmfabKPVUE/iu7X3ckI3iQyYIgHYjn1Ek+zXQaN0DYMThl2chTjnq389qCuy1OeT4Q==, tarball: file:projects/communication-call-automation.tgz}
|
||||
name: '@rush-temp/communication-call-automation'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
|
@ -18944,6 +18944,8 @@ packages:
|
|||
'@types/mocha': 10.0.9
|
||||
'@types/node': 18.19.64
|
||||
'@types/sinon': 17.0.3
|
||||
'@vitest/browser': 2.1.5(@types/node@18.19.64)(playwright@1.48.2)(typescript@5.6.3)(vitest@2.1.5)
|
||||
'@vitest/coverage-istanbul': 2.1.5(vitest@2.1.5)
|
||||
chai: 4.3.10
|
||||
dotenv: 16.4.5
|
||||
eslint: 9.14.0
|
||||
|
@ -18961,19 +18963,33 @@ packages:
|
|||
karma-sourcemap-loader: 0.3.8
|
||||
mocha: 10.8.2
|
||||
nyc: 17.1.0
|
||||
playwright: 1.48.2
|
||||
sinon: 17.0.1
|
||||
ts-node: 10.9.2(@types/node@18.19.64)(typescript@5.6.3)
|
||||
tslib: 2.8.1
|
||||
typescript: 5.6.3
|
||||
util: 0.12.5
|
||||
vitest: 2.1.5(@types/node@18.19.64)(@vitest/browser@2.1.5)
|
||||
transitivePeerDependencies:
|
||||
- '@swc/core'
|
||||
- '@swc/wasm'
|
||||
- '@edge-runtime/vm'
|
||||
- '@vitest/ui'
|
||||
- bufferutil
|
||||
- debug
|
||||
- happy-dom
|
||||
- jiti
|
||||
- jsdom
|
||||
- less
|
||||
- lightningcss
|
||||
- msw
|
||||
- safaridriver
|
||||
- sass
|
||||
- sass-embedded
|
||||
- stylus
|
||||
- sugarss
|
||||
- supports-color
|
||||
- terser
|
||||
- utf-8-validate
|
||||
- vite
|
||||
- webdriverio
|
||||
dev: false
|
||||
|
||||
file:projects/communication-chat.tgz:
|
||||
|
@ -20800,7 +20816,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/eventhubs-checkpointstore-blob.tgz(chai@4.3.10):
|
||||
resolution: {integrity: sha512-d0r9Tcp+PR88ElbvXVtloMca/5o3x7baoqzfzU6erNYp3+qDb28vnauB7wgtSr/JCNFXUUEwCRdCDkqnj2SjIg==, tarball: file:projects/eventhubs-checkpointstore-blob.tgz}
|
||||
resolution: {integrity: sha512-QIMCv2kTVX8O/o5j/9cm9cj3M1Yu68nIK2z4ubzIx+w0ZJ4Sby3hc2F+UFe5oj59UyA29uZLX6sfITm7+SuKgQ==, tarball: file:projects/eventhubs-checkpointstore-blob.tgz}
|
||||
id: file:projects/eventhubs-checkpointstore-blob.tgz
|
||||
name: '@rush-temp/eventhubs-checkpointstore-blob'
|
||||
version: 0.0.0
|
||||
|
@ -21833,7 +21849,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/microsoft-playwright-testing.tgz:
|
||||
resolution: {integrity: sha512-5ZtQtASg+gjAwV0BZ3pqTl2taVn2mW46wnhVjYnUhjn08xDzhaRqPvupmTT6S4Nfc1TcP+J/dQWhqEqwD22HGw==, tarball: file:projects/microsoft-playwright-testing.tgz}
|
||||
resolution: {integrity: sha512-LOfcpsGhkCQlf/ONHLHqjTVgWCasb0ImH6OcRwRpzkO4ybQbiAi4eQvnD2CVwpoa3crRHI9hebbLeSvBsBKAVA==, tarball: file:projects/microsoft-playwright-testing.tgz}
|
||||
name: '@rush-temp/microsoft-playwright-testing'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
|
@ -22661,7 +22677,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/perf-storage-blob.tgz:
|
||||
resolution: {integrity: sha512-bP40paE6XWSxK1NI6IqTFa3TnZ/KV+oOwXvHOlWlnpDa6vHxzuVaSLO22jn2HKpusBkvMhL2znxbrnglHkXp7Q==, tarball: file:projects/perf-storage-blob.tgz}
|
||||
resolution: {integrity: sha512-gC/6yI3RAsLz8yW4HuwmY/hZJdfQ4WpTasQrnaGM2o0ADvshX7BbTMziACBVC1IJ+SZS0f25nzWdMrf1cKEPUA==, tarball: file:projects/perf-storage-blob.tgz}
|
||||
name: '@rush-temp/perf-storage-blob'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
|
@ -22680,7 +22696,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/perf-storage-file-datalake.tgz:
|
||||
resolution: {integrity: sha512-lOYRq0haEkX/2PuDMltoOo+lVVv6qQ6vg9V9bTtsf49Dw0Cl+6GBEzEdY5zzfK/QJj8GqH0BDKJe9SH0dFtnuw==, tarball: file:projects/perf-storage-file-datalake.tgz}
|
||||
resolution: {integrity: sha512-/Ci5NG7Th6jCRFjxNQnQIN066A0l8K8hkuTPVCvaChixw0hduEm6MN1HeVT+Qmwkko8uVFlLNu1s7HgLwy8rLw==, tarball: file:projects/perf-storage-file-datalake.tgz}
|
||||
name: '@rush-temp/perf-storage-file-datalake'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
|
@ -22699,7 +22715,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/perf-storage-file-share.tgz:
|
||||
resolution: {integrity: sha512-2xwPxzCMbVfYgHjYiUFtyHhpNoU3rDDiz8voS+JIJni80uABgbEZbbTqb/sGDiMkix0lky1xHLBgplcoq50p8g==, tarball: file:projects/perf-storage-file-share.tgz}
|
||||
resolution: {integrity: sha512-PA4GNlP5egvK17bRRWDzOrPQgQ87ZxFP+UzUQxy/Wa1NwuHJdBlcsa8P3do4HTkD0UpSzTyeNQ5P7X2etFM+8A==, tarball: file:projects/perf-storage-file-share.tgz}
|
||||
name: '@rush-temp/perf-storage-file-share'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
|
@ -22983,7 +22999,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/quantum-jobs.tgz:
|
||||
resolution: {integrity: sha512-LcPcq+CQlLRl1qN04ARwMlUE2OQi7Bef8aO8uqXIxhejiYFVDLUvtES/oJPoqRTAcYiNs0+6dW7DV/tlyyncdQ==, tarball: file:projects/quantum-jobs.tgz}
|
||||
resolution: {integrity: sha512-7t0BJaiAPuiDKNgRvOYijVm/Nd8OdjCrk2UhxSYDCVAaJkxRcbNExsrj1RLHv7LrmDbg3AcKymMM+dP9KPBAeA==, tarball: file:projects/quantum-jobs.tgz}
|
||||
name: '@rush-temp/quantum-jobs'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
|
@ -23251,7 +23267,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/storage-blob-changefeed.tgz:
|
||||
resolution: {integrity: sha512-g3z0U7sH8A+7aPtYY/h7NmhPoYx4N12mE1GyVw0EENN4iO6jFRVFh4r8y1qcfPXCUewloCiPfF2DxwZR8KmyXg==, tarball: file:projects/storage-blob-changefeed.tgz}
|
||||
resolution: {integrity: sha512-ulb7cStYuBYLz5klWzekE1UG2EGSPjv5VqYpaBmA73FZHcjYXumEFAsnGOdUxJFL2/mJAUHJ2nutM3jWLwoH/g==, tarball: file:projects/storage-blob-changefeed.tgz}
|
||||
name: '@rush-temp/storage-blob-changefeed'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
|
@ -23343,7 +23359,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/storage-file-datalake.tgz:
|
||||
resolution: {integrity: sha512-0S+88/SFOzE4eUYtKCMMikxfTh8NzfL5hEGTleZyl+URlPSpUBt/SJE35R9OlVOI+ihfc9RE66XdsYktjy5SBQ==, tarball: file:projects/storage-file-datalake.tgz}
|
||||
resolution: {integrity: sha512-FVV+PJzMPt7z/pAYIE+3/XbfTv9nR1icrxKEnPtNjNiu1SIFzxoqsSfyzWEhM3OaDxw7cGkn5CVEb1dGo0yoRA==, tarball: file:projects/storage-file-datalake.tgz}
|
||||
name: '@rush-temp/storage-file-datalake'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
|
@ -23390,7 +23406,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/storage-file-share.tgz:
|
||||
resolution: {integrity: sha512-YwK1nFzjoDaHcHuGiKSexyTzZmiRARdZ6VeWkvXMmmOckWkIzYfcUkwEnIhU60ban96FVT/6BrczNFgvHMOCUg==, tarball: file:projects/storage-file-share.tgz}
|
||||
resolution: {integrity: sha512-UIGe6OIq8WYfDcVyTGSBN+NoU0a62Gp8CPRLfLLdhyewy7MtMfQeQeqsJA0UheHGE7KiVMdEJ1Y7CqVnVBT4+A==, tarball: file:projects/storage-file-share.tgz}
|
||||
name: '@rush-temp/storage-file-share'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
|
@ -23476,7 +23492,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/storage-queue.tgz:
|
||||
resolution: {integrity: sha512-7PfyEm0o178jiAjKrXJJ/BGBF09A1GzA3dTgPIPNQ6Y4XJitrpDIm4jliYFQYvoiJgBDG2zvzjNP2Z4HCa2sCw==, tarball: file:projects/storage-queue.tgz}
|
||||
resolution: {integrity: sha512-5eSIt9TpDfdl5IHCDEjtBqAe+1Ipe/bEju6w4pdLRo7/j/dcOrewCOj+c96FLKsU334aj4qhvZ0/5TQqyxizpw==, tarball: file:projects/storage-queue.tgz}
|
||||
name: '@rush-temp/storage-queue'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"include": ["dist-esm/src/**/*.js"],
|
||||
"exclude": ["**/*.d.ts", "dist-esm/src/generated/*"],
|
||||
"reporter": ["text-summary", "html", "cobertura"],
|
||||
"exclude-after-remap": false,
|
||||
"sourceMap": true,
|
||||
"produce-source-map": true,
|
||||
"instrument": true,
|
||||
"all": true
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
||||
"mainEntryPointFilePath": "types/src/index.d.ts",
|
||||
"mainEntryPointFilePath": "dist/esm/index.d.ts",
|
||||
"docModel": {
|
||||
"enabled": true
|
||||
},
|
||||
|
@ -11,7 +11,7 @@
|
|||
"dtsRollup": {
|
||||
"enabled": true,
|
||||
"untrimmedFilePath": "",
|
||||
"publicTrimmedFilePath": "./types/communication-call-automation.d.ts"
|
||||
"publicTrimmedFilePath": "dist/communication-call-automation.d.ts"
|
||||
},
|
||||
"messages": {
|
||||
"tsdocMessageReporting": {
|
||||
|
|
|
@ -1,127 +0,0 @@
|
|||
// https://github.com/karma-runner/karma-chrome-launcher
|
||||
process.env.CHROME_BIN = require("puppeteer").executablePath();
|
||||
const { relativeRecordingsPath } = require("@azure-tools/test-recorder");
|
||||
|
||||
require("dotenv").config();
|
||||
|
||||
process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath();
|
||||
|
||||
module.exports = function (config) {
|
||||
config.set({
|
||||
// base path that will be used to resolve all patterns (eg. files, exclude)
|
||||
basePath: "./",
|
||||
|
||||
// frameworks to use
|
||||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
||||
frameworks: ["mocha"],
|
||||
|
||||
plugins: [
|
||||
"karma-mocha",
|
||||
"karma-mocha-reporter",
|
||||
"karma-chrome-launcher",
|
||||
"karma-edge-launcher",
|
||||
"karma-firefox-launcher",
|
||||
"karma-ie-launcher",
|
||||
"karma-env-preprocessor",
|
||||
"karma-coverage",
|
||||
"karma-sourcemap-loader",
|
||||
"karma-junit-reporter",
|
||||
],
|
||||
|
||||
// list of files / patterns to load in the browser
|
||||
files: ["dist-test/index.browser.js"],
|
||||
|
||||
// list of files / patterns to exclude
|
||||
exclude: [],
|
||||
|
||||
// preprocess matching files before serving them to the browser
|
||||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
||||
preprocessors: {
|
||||
"**/*.js": ["sourcemap", "env"],
|
||||
// IMPORTANT: COMMENT following line if you want to debug in your browsers!!
|
||||
// Preprocess source file to calculate code coverage, however this will make source file unreadable
|
||||
//"dist-test/index.browser.js": ["coverage"]
|
||||
},
|
||||
|
||||
// inject following environment values into browser testing with window.__env__
|
||||
// environment values MUST be exported or set with same console running "karma start"
|
||||
// https://www.npmjs.com/package/karma-env-preprocessor
|
||||
envPreprocessor: [
|
||||
"TEST_MODE",
|
||||
"COMMUNICATION_LIVETEST_DYNAMIC_CONNECTION_STRING",
|
||||
"BASE_URL",
|
||||
"RECORDINGS_RELATIVE_PATH",
|
||||
],
|
||||
|
||||
// test results reporter to use
|
||||
// possible values: 'dots', 'progress'
|
||||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
||||
reporters: ["mocha", "coverage", "junit"],
|
||||
|
||||
coverageReporter: {
|
||||
// specify a common output directory
|
||||
dir: "coverage-browser/",
|
||||
reporters: [
|
||||
{ type: "json", subdir: ".", file: "coverage.json" },
|
||||
{ type: "lcovonly", subdir: ".", file: "lcov.info" },
|
||||
{ type: "html", subdir: "html" },
|
||||
{ type: "cobertura", subdir: ".", file: "cobertura-coverage.xml" },
|
||||
],
|
||||
},
|
||||
|
||||
junitReporter: {
|
||||
outputDir: "", // results will be saved as $outputDir/$browserName.xml
|
||||
outputFile: "test-results.browser.xml", // if included, results will be saved as $outputDir/$browserName/$outputFile
|
||||
suite: "", // suite will become the package name attribute in xml testsuite element
|
||||
useBrowserName: false, // add browser name to report and classes names
|
||||
nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
|
||||
classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
|
||||
properties: {}, // key value pair of properties to add to the <properties> section of the report
|
||||
},
|
||||
|
||||
// web server port
|
||||
port: 9876,
|
||||
|
||||
// enable / disable colors in the output (reporters and logs)
|
||||
colors: true,
|
||||
|
||||
// level of logging
|
||||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
||||
logLevel: config.LOG_INFO,
|
||||
|
||||
// enable / disable watching file and executing tests whenever any file changes
|
||||
autoWatch: false,
|
||||
|
||||
// start these browsers
|
||||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
||||
// 'ChromeHeadless', 'Chrome', 'Firefox', 'Edge', 'IE'
|
||||
browsers: ["HeadlessChrome"],
|
||||
|
||||
customLaunchers: {
|
||||
HeadlessChrome: {
|
||||
base: "ChromeHeadless",
|
||||
flags: ["--no-sandbox"],
|
||||
},
|
||||
},
|
||||
|
||||
// Continuous Integration mode
|
||||
// if true, Karma captures browsers, runs the tests and exits
|
||||
singleRun: true,
|
||||
|
||||
// Concurrency level
|
||||
// how many browser should be started simultaneous
|
||||
concurrency: 1,
|
||||
|
||||
browserNoActivityTimeout: 600000,
|
||||
browserDisconnectTimeout: 10000,
|
||||
browserDisconnectTolerance: 3,
|
||||
|
||||
client: {
|
||||
mocha: {
|
||||
// change Karma's debug.html to the mocha web reporter
|
||||
reporter: "html",
|
||||
timeout: "600000",
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
|
@ -3,23 +3,21 @@
|
|||
"version": "1.3.0-beta.1",
|
||||
"description": "Azure client library for Azure Communication Call Automation services",
|
||||
"sdk-type": "client",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist-esm/src/index.js",
|
||||
"types": "types/communication-call-automation.d.ts",
|
||||
"browser": {
|
||||
"./dist-esm/src/credential/cryptoUtils.js": "./dist-esm/src/credential/cryptoUtils.browser.js"
|
||||
},
|
||||
"main": "./dist/commonjs/index.js",
|
||||
"module": "./dist/esm/index.js",
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"browser": "./dist/browser/index.js",
|
||||
"scripts": {
|
||||
"build": "npm run clean && tsc -p . && dev-tool run bundle && dev-tool run extract-api",
|
||||
"build": "npm run clean && dev-tool run build-package && dev-tool run extract-api",
|
||||
"build:autorest": "autorest ./swagger/README.md && rushx format",
|
||||
"build:browser": "tsc -p . && dev-tool run bundle",
|
||||
"build:node": "tsc -p . && dev-tool run bundle",
|
||||
"build:browser": "dev-tool run build-package && dev-tool run bundle",
|
||||
"build:node": "dev-tool run build-package && dev-tool run bundle",
|
||||
"build:samples": "dev-tool samples publish --force",
|
||||
"build:test": "tsc -p . && dev-tool run bundle",
|
||||
"build:test": "dev-tool run build-package && dev-tool run bundle",
|
||||
"check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
|
||||
"clean": "dev-tool run vendored rimraf --glob dist dist-* temp types *.tgz *.log",
|
||||
"execute:samples": "dev-tool samples run samples-dev",
|
||||
"extract-api": "tsc -p . && dev-tool run extract-api",
|
||||
"extract-api": "dev-tool run build-package && dev-tool run extract-api",
|
||||
"format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
|
||||
"generate:client": "autorest --typescript ./swagger/README.md && rushx format",
|
||||
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
|
||||
|
@ -32,14 +30,12 @@
|
|||
"test:browser": "npm run build:test && npm run unit-test:browser",
|
||||
"test:node": "npm run build:test && npm run unit-test:node",
|
||||
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
|
||||
"unit-test:browser": "echo skipped",
|
||||
"unit-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/*.spec.ts'",
|
||||
"unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
|
||||
"unit-test:node": "dev-tool run test:vitest",
|
||||
"update-snippets": "echo skipped"
|
||||
},
|
||||
"files": [
|
||||
"dist/",
|
||||
"dist-esm/src",
|
||||
"types/communication-call-automation.d.ts",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
],
|
||||
|
@ -74,49 +70,73 @@
|
|||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@azure/abort-controller": "^2.0.0",
|
||||
"@azure/abort-controller": "^2.1.2",
|
||||
"@azure/communication-common": "^2.3.1",
|
||||
"@azure/core-auth": "^1.3.0",
|
||||
"@azure/core-client": "^1.3.0",
|
||||
"@azure/core-paging": "^1.1.1",
|
||||
"@azure/core-rest-pipeline": "^1.3.0",
|
||||
"@azure/core-tracing": "^1.0.0",
|
||||
"@azure/core-util": "^1.6.1",
|
||||
"@azure/logger": "^1.0.0",
|
||||
"@azure/core-auth": "^1.9.0",
|
||||
"@azure/core-client": "^1.9.2",
|
||||
"@azure/core-paging": "^1.6.2",
|
||||
"@azure/core-rest-pipeline": "^1.17.0",
|
||||
"@azure/core-tracing": "^1.2.0",
|
||||
"@azure/core-util": "^1.11.0",
|
||||
"@azure/logger": "^1.1.4",
|
||||
"events": "^3.0.0",
|
||||
"tslib": "^2.2.0"
|
||||
"tslib": "^2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@azure-tools/test-credential": "^1.0.1",
|
||||
"@azure-tools/test-recorder": "^3.0.0",
|
||||
"@azure-tools/test-credential": "^2.0.0",
|
||||
"@azure-tools/test-recorder": "^4.1.0",
|
||||
"@azure-tools/test-utils-vitest": "^1.0.0",
|
||||
"@azure-tools/vite-plugin-browser-test-map": "^1.0.0",
|
||||
"@azure/communication-identity": "^1.2.0",
|
||||
"@azure/communication-phone-numbers": "^1.2.0",
|
||||
"@azure/dev-tool": "^1.0.0",
|
||||
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
|
||||
"@azure/service-bus": "^7.8.1",
|
||||
"@types/chai": "^4.1.6",
|
||||
"@types/mocha": "^10.0.0",
|
||||
"@azure/service-bus": "^7.9.5",
|
||||
"@types/node": "^18.0.0",
|
||||
"@types/sinon": "^17.0.0",
|
||||
"chai": "^4.2.0",
|
||||
"@vitest/browser": "^2.1.5",
|
||||
"@vitest/coverage-istanbul": "^2.1.5",
|
||||
"dotenv": "^16.0.0",
|
||||
"eslint": "^9.9.0",
|
||||
"inherits": "^2.0.3",
|
||||
"karma": "^6.2.0",
|
||||
"karma-chrome-launcher": "^3.0.0",
|
||||
"karma-coverage": "^2.0.0",
|
||||
"karma-env-preprocessor": "^0.1.1",
|
||||
"karma-json-preprocessor": "^0.3.3",
|
||||
"karma-json-to-file-reporter": "^1.0.1",
|
||||
"karma-junit-reporter": "^2.0.1",
|
||||
"karma-mocha": "^2.0.1",
|
||||
"karma-mocha-reporter": "^2.2.5",
|
||||
"karma-sourcemap-loader": "^0.3.8",
|
||||
"mocha": "^10.0.0",
|
||||
"nyc": "^17.0.0",
|
||||
"sinon": "^17.0.0",
|
||||
"ts-node": "^10.0.0",
|
||||
"playwright": "^1.48.2",
|
||||
"typescript": "~5.6.2",
|
||||
"util": "^0.12.1"
|
||||
"vitest": "^2.1.5"
|
||||
},
|
||||
"type": "module",
|
||||
"tshy": {
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"dialects": [
|
||||
"esm",
|
||||
"commonjs"
|
||||
],
|
||||
"esmDialects": [
|
||||
"browser",
|
||||
"react-native"
|
||||
],
|
||||
"selfLink": false
|
||||
},
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
".": {
|
||||
"browser": {
|
||||
"types": "./dist/browser/index.d.ts",
|
||||
"default": "./dist/browser/index.js"
|
||||
},
|
||||
"react-native": {
|
||||
"types": "./dist/react-native/index.d.ts",
|
||||
"default": "./dist/react-native/index.js"
|
||||
},
|
||||
"import": {
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import type {
|
|||
MicrosoftTeamsAppIdentifier,
|
||||
} from "@azure/communication-common";
|
||||
import { parseClientArguments, isKeyCredential } from "@azure/communication-common";
|
||||
import { logger } from "./models/logger";
|
||||
import { logger } from "./models/logger.js";
|
||||
import type {
|
||||
AnswerCallRequest,
|
||||
CallAutomationApiClient,
|
||||
|
@ -20,17 +20,21 @@ import type {
|
|||
RedirectCallRequest,
|
||||
RejectCallRequest,
|
||||
CustomCallingContextInternal,
|
||||
} from "./generated/src";
|
||||
import { CallConnection } from "./callConnection";
|
||||
import { CallRecording } from "./callRecording";
|
||||
} from "./generated/src/index.js";
|
||||
import { CallConnection } from "./callConnection.js";
|
||||
import { CallRecording } from "./callRecording.js";
|
||||
import type {
|
||||
AnswerCallOptions,
|
||||
CreateCallOptions,
|
||||
RedirectCallOptions,
|
||||
RejectCallOptions,
|
||||
} from "./models/options";
|
||||
import type { AnswerCallResult, CreateCallResult } from "./models/responses";
|
||||
import type { CallConnectionProperties, CallInvite, CustomCallingContext } from "./models/models";
|
||||
} from "./models/options.js";
|
||||
import type { AnswerCallResult, CreateCallResult } from "./models/responses.js";
|
||||
import type {
|
||||
CallConnectionProperties,
|
||||
CallInvite,
|
||||
CustomCallingContext,
|
||||
} from "./models/models.js";
|
||||
import {
|
||||
communicationIdentifierConverter,
|
||||
communicationIdentifierModelConverter,
|
||||
|
@ -39,11 +43,14 @@ import {
|
|||
microsoftTeamsAppIdentifierModelConverter,
|
||||
phoneNumberIdentifierConverter,
|
||||
PhoneNumberIdentifierModelConverter,
|
||||
} from "./utli/converters";
|
||||
} from "./utli/converters.js";
|
||||
import { randomUUID } from "@azure/core-util";
|
||||
import { createCustomCallAutomationApiClient } from "./credential/callAutomationAuthPolicy";
|
||||
import { CallAutomationEventProcessor } from "./eventprocessor/callAutomationEventProcessor";
|
||||
import type { AnswerCallEventResult, CreateCallEventResult } from "./eventprocessor/eventResponses";
|
||||
import { createCustomCallAutomationApiClient } from "./credential/callAutomationAuthPolicy.js";
|
||||
import { CallAutomationEventProcessor } from "./eventprocessor/callAutomationEventProcessor.js";
|
||||
import type {
|
||||
AnswerCallEventResult,
|
||||
CreateCallEventResult,
|
||||
} from "./eventprocessor/eventResponses.js";
|
||||
/**
|
||||
* Client options used to configure CallAutomation Client API requests.
|
||||
*/
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
import { createSerializer } from "@azure/core-client";
|
||||
|
||||
import { communicationIdentifierConverter, callParticipantConverter } from "./utli/converters";
|
||||
|
||||
import { communicationIdentifierConverter, callParticipantConverter } from "./utli/converters.js";
|
||||
import type {
|
||||
CallAutomationEvent,
|
||||
AddParticipantSucceeded,
|
||||
|
@ -37,10 +35,9 @@ import type {
|
|||
CreateCallFailed,
|
||||
AnswerFailed,
|
||||
HoldFailed,
|
||||
} from "./models/events";
|
||||
|
||||
import { CloudEventMapper } from "./models/mapper";
|
||||
import type { CallParticipantInternal } from "./generated/src";
|
||||
} from "./models/events.js";
|
||||
import { CloudEventMapper } from "./models/mapper.js";
|
||||
import type { CallParticipantInternal } from "./generated/src/index.js";
|
||||
|
||||
const serializer = createSerializer();
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
import type { CommunicationIdentifier } from "@azure/communication-common";
|
||||
import { CallMedia } from "./callMedia";
|
||||
import { CallMedia } from "./callMedia.js";
|
||||
import type {
|
||||
AddParticipantRequest,
|
||||
CallAutomationApiClient,
|
||||
|
@ -11,14 +11,14 @@ import type {
|
|||
MuteParticipantsRequest,
|
||||
RemoveParticipantRequest,
|
||||
TransferToParticipantRequest,
|
||||
} from "./generated/src";
|
||||
import { CallConnectionImpl } from "./generated/src/operations";
|
||||
} from "./generated/src/index.js";
|
||||
import { CallConnectionImpl } from "./generated/src/operations/index.js";
|
||||
import type {
|
||||
CallConnectionProperties,
|
||||
CallInvite,
|
||||
CallParticipant,
|
||||
CustomCallingContext,
|
||||
} from "./models/models";
|
||||
} from "./models/models.js";
|
||||
import type {
|
||||
AddParticipantOptions,
|
||||
CancelAddParticipantOperationOptions,
|
||||
|
@ -28,7 +28,7 @@ import type {
|
|||
MuteParticipantOption,
|
||||
RemoveParticipantsOption,
|
||||
TransferCallToParticipantOptions,
|
||||
} from "./models/options";
|
||||
} from "./models/options.js";
|
||||
import type {
|
||||
ListParticipantsResult,
|
||||
TransferCallResult,
|
||||
|
@ -36,7 +36,7 @@ import type {
|
|||
RemoveParticipantResult,
|
||||
MuteParticipantResult,
|
||||
CancelAddParticipantOperationResult,
|
||||
} from "./models/responses";
|
||||
} from "./models/responses.js";
|
||||
import {
|
||||
callParticipantConverter,
|
||||
communicationIdentifierConverter,
|
||||
|
@ -44,17 +44,17 @@ import {
|
|||
communicationUserIdentifierConverter,
|
||||
phoneNumberIdentifierConverter,
|
||||
PhoneNumberIdentifierModelConverter,
|
||||
} from "./utli/converters";
|
||||
} from "./utli/converters.js";
|
||||
import { randomUUID } from "@azure/core-util";
|
||||
import type { KeyCredential, TokenCredential } from "@azure/core-auth";
|
||||
import type { CallAutomationEventProcessor } from "./eventprocessor/callAutomationEventProcessor";
|
||||
import type { CallAutomationEventProcessor } from "./eventprocessor/callAutomationEventProcessor.js";
|
||||
import type {
|
||||
AddParticipantEventResult,
|
||||
CancelAddParticipantEventResult,
|
||||
RemoveParticipantEventResult,
|
||||
TransferCallToParticipantEventResult,
|
||||
} from "./eventprocessor/eventResponses";
|
||||
import { createCustomCallAutomationApiClient } from "./credential/callAutomationAuthPolicy";
|
||||
} from "./eventprocessor/eventResponses.js";
|
||||
import { createCustomCallAutomationApiClient } from "./credential/callAutomationAuthPolicy.js";
|
||||
|
||||
/**
|
||||
* CallConnection class represents call connection based APIs.
|
||||
|
|
|
@ -23,15 +23,15 @@ import type {
|
|||
UpdateTranscriptionRequest,
|
||||
HoldRequest,
|
||||
UnholdRequest,
|
||||
} from "./generated/src";
|
||||
import { KnownPlaySourceType, KnownRecognizeInputType } from "./generated/src";
|
||||
} from "./generated/src/index.js";
|
||||
import { KnownPlaySourceType, KnownRecognizeInputType } from "./generated/src/index.js";
|
||||
|
||||
import { CallMediaImpl } from "./generated/src/operations";
|
||||
import { CallMediaImpl } from "./generated/src/operations/index.js";
|
||||
|
||||
import type { CommunicationIdentifier } from "@azure/communication-common";
|
||||
import { serializeCommunicationIdentifier } from "@azure/communication-common";
|
||||
|
||||
import type { FileSource, TextSource, SsmlSource, DtmfTone } from "./models/models";
|
||||
import type { FileSource, TextSource, SsmlSource, DtmfTone } from "./models/models.js";
|
||||
import type {
|
||||
PlayOptions,
|
||||
CallMediaRecognizeDtmfOptions,
|
||||
|
@ -44,23 +44,23 @@ import type {
|
|||
StopTranscriptionOptions,
|
||||
HoldOptions,
|
||||
UnholdOptions,
|
||||
} from "./models/options";
|
||||
} from "./models/options.js";
|
||||
import type { KeyCredential, TokenCredential } from "@azure/core-auth";
|
||||
import type {
|
||||
CancelAllMediaOperationsResult,
|
||||
PlayResult,
|
||||
SendDtmfTonesResult,
|
||||
StartRecognizingResult,
|
||||
} from "./models/responses";
|
||||
} from "./models/responses.js";
|
||||
import type {
|
||||
CancelAllMediaOperationsEventResult,
|
||||
PlayEventResult,
|
||||
SendDtmfEventResult,
|
||||
StartRecognizingEventResult,
|
||||
} from "./eventprocessor/eventResponses";
|
||||
import type { CallAutomationEventProcessor } from "./eventprocessor/callAutomationEventProcessor";
|
||||
} from "./eventprocessor/eventResponses.js";
|
||||
import type { CallAutomationEventProcessor } from "./eventprocessor/callAutomationEventProcessor.js";
|
||||
import { randomUUID } from "@azure/core-util";
|
||||
import { createCustomCallAutomationApiClient } from "./credential/callAutomationAuthPolicy";
|
||||
import { createCustomCallAutomationApiClient } from "./credential/callAutomationAuthPolicy.js";
|
||||
|
||||
/**
|
||||
* CallMedia class represents call media related APIs.
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
import { CallRecordingImpl } from "./generated/src/operations";
|
||||
import { CallRecordingImpl } from "./generated/src/operations/index.js";
|
||||
import type {
|
||||
CallAutomationApiClientOptionalParams,
|
||||
StartCallRecordingRequest,
|
||||
} from "./generated/src/models/index";
|
||||
import type { RecordingStateResult } from "./models/responses";
|
||||
} from "./generated/src/models/index.js";
|
||||
import type { RecordingStateResult } from "./models/responses.js";
|
||||
import type {
|
||||
StartRecordingOptions,
|
||||
StopRecordingOptions,
|
||||
|
@ -14,14 +14,14 @@ import type {
|
|||
ResumeRecordingOptions,
|
||||
DeleteRecordingOptions,
|
||||
DownloadRecordingOptions,
|
||||
} from "./models/options";
|
||||
import { communicationIdentifierModelConverter } from "./utli/converters";
|
||||
import { ContentDownloaderImpl } from "./contentDownloader";
|
||||
import * as fs from "fs";
|
||||
} from "./models/options.js";
|
||||
import { communicationIdentifierModelConverter } from "./utli/converters.js";
|
||||
import { ContentDownloaderImpl } from "./contentDownloader.js";
|
||||
import * as fs from "node:fs";
|
||||
import { randomUUID } from "@azure/core-util";
|
||||
import type { KeyCredential, TokenCredential } from "@azure/core-auth";
|
||||
import type { CallAutomationApiClient } from "./generated/src";
|
||||
import { createCustomCallAutomationApiClient } from "./credential/callAutomationAuthPolicy";
|
||||
import type { CallAutomationApiClient } from "./generated/src/index.js";
|
||||
import { createCustomCallAutomationApiClient } from "./credential/callAutomationAuthPolicy.js";
|
||||
|
||||
/**
|
||||
* CallRecording class represents call recording related APIs.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import type { CallAutomationApiClient } from "./generated/src/callAutomationApiClient";
|
||||
import type { CallAutomationApiClient } from "./generated/src/callAutomationApiClient.js";
|
||||
import type {
|
||||
AddPipelineOptions,
|
||||
PipelineRequest,
|
||||
|
@ -10,7 +10,7 @@ import type {
|
|||
SendRequest,
|
||||
} from "@azure/core-rest-pipeline";
|
||||
import { createHttpHeaders, createPipelineRequest } from "@azure/core-rest-pipeline";
|
||||
import type { DeleteRecordingOptions, DownloadRecordingOptions } from "./models/options";
|
||||
import type { DeleteRecordingOptions, DownloadRecordingOptions } from "./models/options.js";
|
||||
|
||||
/** Class containing ContentDownloading operations. */
|
||||
export class ContentDownloaderImpl {
|
||||
|
|
|
@ -8,7 +8,7 @@ import type {
|
|||
SendRequest,
|
||||
} from "@azure/core-rest-pipeline";
|
||||
import type { KeyCredential } from "@azure/core-auth";
|
||||
import { shaHMAC, shaHash } from "./cryptoUtils";
|
||||
import { shaHMAC, shaHash } from "./cryptoUtils.js";
|
||||
import { isNode } from "@azure/core-util";
|
||||
|
||||
const callAutomationAccessKeyCredentialPolicy = "CallAutomationAccessKeyCredentialPolicy";
|
||||
|
|
|
@ -8,9 +8,9 @@ import type {
|
|||
import { bearerTokenAuthenticationPolicy } from "@azure/core-rest-pipeline";
|
||||
import type { KeyCredential, TokenCredential } from "@azure/core-auth";
|
||||
import { isTokenCredential } from "@azure/core-auth";
|
||||
import { createCallAutomationAccessKeyCredentialPolicy } from "./callAutomationAccessKeyCredentialPolicy";
|
||||
import type { CallAutomationApiClientOptionalParams } from "./../generated/src";
|
||||
import { CallAutomationApiClient } from "./../generated/src";
|
||||
import { createCallAutomationAccessKeyCredentialPolicy } from "./callAutomationAccessKeyCredentialPolicy.js";
|
||||
import type { CallAutomationApiClientOptionalParams } from "./../generated/src/index.js";
|
||||
import { CallAutomationApiClient } from "./../generated/src/index.js";
|
||||
import { createCommunicationAuthPolicy } from "@azure/communication-common";
|
||||
/**
|
||||
* Creates a pipeline policy to authenticate request based
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
/// <reference lib="dom" />
|
||||
|
||||
import { encodeBase64, encodeUTF8, encodeUTF8fromBase64 } from "./encodeUtils.browser";
|
||||
import { encodeBase64, encodeUTF8, encodeUTF8fromBase64 } from "./encodeUtils.browser.js";
|
||||
|
||||
const subtle = (globalThis as any)?.crypto?.subtle as SubtleCrypto;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import { createHash, createHmac } from "crypto";
|
||||
import { createHash, createHmac } from "node:crypto";
|
||||
|
||||
export const shaHash = async (content: string): Promise<string> =>
|
||||
createHash("sha256").update(content).digest("base64");
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
import { EventEmitter } from "events";
|
||||
import type { CallAutomationEvent } from "../models/events";
|
||||
import { parseCallAutomationEvent } from "../callAutomationEventParser";
|
||||
import type { CallAutomationEvent } from "../models/events.js";
|
||||
import { parseCallAutomationEvent } from "../callAutomationEventParser.js";
|
||||
import type { AbortSignalLike } from "@azure/abort-controller";
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,7 +21,7 @@ import type {
|
|||
CancelAddParticipantFailed,
|
||||
CreateCallFailed,
|
||||
AnswerFailed,
|
||||
} from "../models/events";
|
||||
} from "../models/events.js";
|
||||
|
||||
/**
|
||||
* AddParticipant event result
|
||||
|
|
|
@ -17,15 +17,15 @@ import {
|
|||
CallMediaImpl,
|
||||
CallDialogImpl,
|
||||
CallRecordingImpl,
|
||||
} from "./operations";
|
||||
} from "./operations/index.js";
|
||||
import {
|
||||
CallConnection,
|
||||
CallMedia,
|
||||
CallDialog,
|
||||
CallRecording,
|
||||
} from "./operationsInterfaces";
|
||||
import * as Parameters from "./models/parameters";
|
||||
import * as Mappers from "./models/mappers";
|
||||
} from "./operationsInterfaces/index.js";
|
||||
import * as Parameters from "./models/parameters.js";
|
||||
import * as Mappers from "./models/mappers.js";
|
||||
import {
|
||||
CallAutomationApiClientOptionalParams,
|
||||
CreateCallRequest,
|
||||
|
@ -38,7 +38,7 @@ import {
|
|||
RedirectCallOptionalParams,
|
||||
RejectCallRequest,
|
||||
RejectCallOptionalParams,
|
||||
} from "./models";
|
||||
} from "./models/index.js";
|
||||
|
||||
export class CallAutomationApiClient extends coreClient.ServiceClient {
|
||||
endpoint: string;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
/// <reference lib="esnext.asynciterable" />
|
||||
export { getContinuationToken } from "./pagingHelper";
|
||||
export * from "./models";
|
||||
export { CallAutomationApiClient } from "./callAutomationApiClient";
|
||||
export * from "./operationsInterfaces";
|
||||
export { getContinuationToken } from "./pagingHelper.js";
|
||||
export * from "./models/index.js";
|
||||
export { CallAutomationApiClient } from "./callAutomationApiClient.js";
|
||||
export * from "./operationsInterfaces/index.js";
|
||||
|
|
|
@ -38,7 +38,7 @@ import {
|
|||
StartDialogRequest as StartDialogRequestMapper,
|
||||
UpdateDialogRequest as UpdateDialogRequestMapper,
|
||||
StartCallRecordingRequest as StartCallRecordingRequestMapper,
|
||||
} from "../models/mappers";
|
||||
} from "../models/mappers.js";
|
||||
|
||||
export const contentType: OperationParameter = {
|
||||
parameterPath: ["options", "contentType"],
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
*/
|
||||
|
||||
import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging";
|
||||
import { setContinuationToken } from "../pagingHelper";
|
||||
import { CallConnection } from "../operationsInterfaces";
|
||||
import { setContinuationToken } from "../pagingHelper.js";
|
||||
import { CallConnection } from "../operationsInterfaces/index.js";
|
||||
import * as coreClient from "@azure/core-client";
|
||||
import * as Mappers from "../models/mappers";
|
||||
import * as Parameters from "../models/parameters";
|
||||
import { CallAutomationApiClient } from "../callAutomationApiClient";
|
||||
import * as Mappers from "../models/mappers.js";
|
||||
import * as Parameters from "../models/parameters.js";
|
||||
import { CallAutomationApiClient } from "../callAutomationApiClient.js";
|
||||
import {
|
||||
CallParticipantInternal,
|
||||
CallConnectionGetParticipantsNextOptionalParams,
|
||||
|
@ -43,7 +43,7 @@ import {
|
|||
CallConnectionGetParticipantOptionalParams,
|
||||
CallConnectionGetParticipantResponse,
|
||||
CallConnectionGetParticipantsNextResponse,
|
||||
} from "../models";
|
||||
} from "../models/index.js";
|
||||
|
||||
/// <reference lib="esnext.asynciterable" />
|
||||
/** Class containing CallConnection operations. */
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
||||
*/
|
||||
|
||||
import { CallDialog } from "../operationsInterfaces";
|
||||
import { CallDialog } from "../operationsInterfaces/index.js";
|
||||
import * as coreClient from "@azure/core-client";
|
||||
import * as Mappers from "../models/mappers";
|
||||
import * as Parameters from "../models/parameters";
|
||||
import { CallAutomationApiClient } from "../callAutomationApiClient";
|
||||
import * as Mappers from "../models/mappers.js";
|
||||
import * as Parameters from "../models/parameters.js";
|
||||
import { CallAutomationApiClient } from "../callAutomationApiClient.js";
|
||||
import {
|
||||
StartDialogRequest,
|
||||
CallDialogStartDialogOptionalParams,
|
||||
|
@ -18,7 +18,7 @@ import {
|
|||
CallDialogStopDialogOptionalParams,
|
||||
UpdateDialogRequest,
|
||||
CallDialogUpdateDialogOptionalParams,
|
||||
} from "../models";
|
||||
} from "../models/index.js";
|
||||
|
||||
/** Class containing CallDialog operations. */
|
||||
export class CallDialogImpl implements CallDialog {
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
||||
*/
|
||||
|
||||
import { CallMedia } from "../operationsInterfaces";
|
||||
import { CallMedia } from "../operationsInterfaces/index.js";
|
||||
import * as coreClient from "@azure/core-client";
|
||||
import * as Mappers from "../models/mappers";
|
||||
import * as Parameters from "../models/parameters";
|
||||
import { CallAutomationApiClient } from "../callAutomationApiClient";
|
||||
import * as Mappers from "../models/mappers.js";
|
||||
import * as Parameters from "../models/parameters.js";
|
||||
import { CallAutomationApiClient } from "../callAutomationApiClient.js";
|
||||
import {
|
||||
PlayRequest,
|
||||
CallMediaPlayOptionalParams,
|
||||
|
@ -41,7 +41,7 @@ import {
|
|||
CallMediaStartMediaStreamingOptionalParams,
|
||||
StopMediaStreamingRequest,
|
||||
CallMediaStopMediaStreamingOptionalParams,
|
||||
} from "../models";
|
||||
} from "../models/index.js";
|
||||
|
||||
/** Class containing CallMedia operations. */
|
||||
export class CallMediaImpl implements CallMedia {
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
||||
*/
|
||||
|
||||
import { CallRecording } from "../operationsInterfaces";
|
||||
import { CallRecording } from "../operationsInterfaces/index.js";
|
||||
import * as coreClient from "@azure/core-client";
|
||||
import * as Mappers from "../models/mappers";
|
||||
import * as Parameters from "../models/parameters";
|
||||
import { CallAutomationApiClient } from "../callAutomationApiClient";
|
||||
import * as Mappers from "../models/mappers.js";
|
||||
import * as Parameters from "../models/parameters.js";
|
||||
import { CallAutomationApiClient } from "../callAutomationApiClient.js";
|
||||
import {
|
||||
StartCallRecordingRequest,
|
||||
CallRecordingStartRecordingOptionalParams,
|
||||
|
@ -20,7 +20,7 @@ import {
|
|||
CallRecordingStopRecordingOptionalParams,
|
||||
CallRecordingPauseRecordingOptionalParams,
|
||||
CallRecordingResumeRecordingOptionalParams,
|
||||
} from "../models";
|
||||
} from "../models/index.js";
|
||||
|
||||
/** Class containing CallRecording operations. */
|
||||
export class CallRecordingImpl implements CallRecording {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
||||
*/
|
||||
|
||||
export * from "./callConnection";
|
||||
export * from "./callMedia";
|
||||
export * from "./callDialog";
|
||||
export * from "./callRecording";
|
||||
export * from "./callConnection.js";
|
||||
export * from "./callMedia.js";
|
||||
export * from "./callDialog.js";
|
||||
export * from "./callRecording.js";
|
||||
|
|
|
@ -34,7 +34,7 @@ import {
|
|||
CallConnectionCancelAddParticipantResponse,
|
||||
CallConnectionGetParticipantOptionalParams,
|
||||
CallConnectionGetParticipantResponse,
|
||||
} from "../models";
|
||||
} from "../models/index.js";
|
||||
|
||||
/// <reference lib="esnext.asynciterable" />
|
||||
/** Interface representing a CallConnection. */
|
||||
|
|
|
@ -13,7 +13,7 @@ import {
|
|||
CallDialogStopDialogOptionalParams,
|
||||
UpdateDialogRequest,
|
||||
CallDialogUpdateDialogOptionalParams,
|
||||
} from "../models";
|
||||
} from "../models/index.js";
|
||||
|
||||
/** Interface representing a CallDialog. */
|
||||
export interface CallDialog {
|
||||
|
|
|
@ -36,7 +36,7 @@ import {
|
|||
CallMediaStartMediaStreamingOptionalParams,
|
||||
StopMediaStreamingRequest,
|
||||
CallMediaStopMediaStreamingOptionalParams,
|
||||
} from "../models";
|
||||
} from "../models/index.js";
|
||||
|
||||
/** Interface representing a CallMedia. */
|
||||
export interface CallMedia {
|
||||
|
|
|
@ -15,7 +15,7 @@ import {
|
|||
CallRecordingStopRecordingOptionalParams,
|
||||
CallRecordingPauseRecordingOptionalParams,
|
||||
CallRecordingResumeRecordingOptionalParams,
|
||||
} from "../models";
|
||||
} from "../models/index.js";
|
||||
|
||||
/** Interface representing a CallRecording. */
|
||||
export interface CallRecording {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
||||
*/
|
||||
|
||||
export * from "./callConnection";
|
||||
export * from "./callMedia";
|
||||
export * from "./callDialog";
|
||||
export * from "./callRecording";
|
||||
export * from "./callConnection.js";
|
||||
export * from "./callMedia.js";
|
||||
export * from "./callDialog.js";
|
||||
export * from "./callRecording.js";
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
export * from "./callAutomationClient";
|
||||
export * from "./callConnection";
|
||||
export * from "./callMedia";
|
||||
export * from "./callRecording";
|
||||
export * from "./callAutomationEventParser";
|
||||
export * from "./models/models";
|
||||
export * from "./models/options";
|
||||
export * from "./models/responses";
|
||||
export * from "./models/events";
|
||||
export * from "./eventprocessor/callAutomationEventProcessor";
|
||||
export * from "./eventprocessor/eventResponses";
|
||||
export * from "./callAutomationClient.js";
|
||||
export * from "./callConnection.js";
|
||||
export * from "./callMedia.js";
|
||||
export * from "./callRecording.js";
|
||||
export * from "./callAutomationEventParser.js";
|
||||
export * from "./models/models.js";
|
||||
export * from "./models/options.js";
|
||||
export * from "./models/responses.js";
|
||||
export * from "./models/events.js";
|
||||
export * from "./eventprocessor/callAutomationEventProcessor.js";
|
||||
export * from "./eventprocessor/eventResponses.js";
|
||||
|
|
|
@ -36,9 +36,9 @@ import type {
|
|||
RestCreateCallFailed,
|
||||
RestAnswerFailed,
|
||||
RestHoldFailed,
|
||||
} from "../generated/src/models";
|
||||
} from "../generated/src/models/index.js";
|
||||
|
||||
import type { CallParticipant } from "./models";
|
||||
import type { CallParticipant } from "./models.js";
|
||||
|
||||
/** Callback events for Call Automation */
|
||||
export type CallAutomationEvent =
|
||||
|
|
|
@ -8,7 +8,7 @@ import type {
|
|||
MicrosoftTeamsAppIdentifier,
|
||||
PhoneNumberIdentifier,
|
||||
} from "@azure/communication-common";
|
||||
import type { CallConnectionStateModel } from "../generated/src";
|
||||
import type { CallConnectionStateModel } from "../generated/src/index.js";
|
||||
|
||||
export {
|
||||
CallConnectionStateModel,
|
||||
|
@ -29,7 +29,7 @@ export {
|
|||
SpeechResult,
|
||||
RecordingState,
|
||||
Tone,
|
||||
} from "../generated/src/models/index";
|
||||
} from "../generated/src/models/index.js";
|
||||
|
||||
/** Properties of a call connection */
|
||||
export interface CallConnectionProperties {
|
||||
|
|
|
@ -20,7 +20,7 @@ import type {
|
|||
ChannelAffinity,
|
||||
CallIntelligenceOptions,
|
||||
CustomCallingContext,
|
||||
} from "./models";
|
||||
} from "./models.js";
|
||||
|
||||
/** Options to configure the recognize operation. */
|
||||
export interface CallMediaRecognizeOptions extends OperationOptions {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import type { CallConnection } from "../callConnection";
|
||||
import type { CallConnectionProperties, CallParticipant } from "./models";
|
||||
import type { RecordingState } from "../generated/src";
|
||||
import type { CallConnection } from "../callConnection.js";
|
||||
import type { CallConnectionProperties, CallParticipant } from "./models.js";
|
||||
import type { RecordingState } from "../generated/src/index.js";
|
||||
import type {
|
||||
AddParticipantEventResult,
|
||||
AnswerCallEventResult,
|
||||
|
@ -15,7 +15,7 @@ import type {
|
|||
StartRecognizingEventResult,
|
||||
TransferCallToParticipantEventResult,
|
||||
CancelAddParticipantEventResult,
|
||||
} from "../eventprocessor/eventResponses";
|
||||
} from "../eventprocessor/eventResponses.js";
|
||||
import type { AbortSignalLike } from "@azure/abort-controller";
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,9 +27,9 @@ import type {
|
|||
PhoneNumberIdentifierModel,
|
||||
CommunicationUserIdentifierModel,
|
||||
MicrosoftTeamsAppIdentifierModel,
|
||||
} from "../generated/src";
|
||||
import { KnownCommunicationIdentifierModelKind } from "../generated/src";
|
||||
import type { CallParticipant } from "../models/models";
|
||||
} from "../generated/src/index.js";
|
||||
import { KnownCommunicationIdentifierModelKind } from "../generated/src/index.js";
|
||||
import type { CallParticipant } from "../models/models.js";
|
||||
|
||||
function extractKind(
|
||||
identifierModel: CommunicationIdentifierModel,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
import { createIdentifierFromRawId } from "@azure/communication-common";
|
||||
import type { TranscriptionMetadata, TranscriptionData } from "../models/transcription";
|
||||
import type { TranscriptionMetadata, TranscriptionData } from "../models/transcription.js";
|
||||
|
||||
/** Parse the incoming package. */
|
||||
export function streamingData(
|
||||
|
|
|
@ -1,373 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import type { Recorder } from "@azure-tools/test-recorder";
|
||||
import type { SinonStubbedInstance } from "sinon";
|
||||
import Sinon from "sinon";
|
||||
import type { CallConnectionProperties } from "../src/models/models";
|
||||
import type { AnswerCallResult, CreateCallResult } from "../src/models/responses";
|
||||
import {
|
||||
CALL_CALLBACK_URL,
|
||||
CALL_INCOMING_CALL_CONTEXT,
|
||||
CALL_TARGET_ID,
|
||||
CALL_TARGET_ID_2,
|
||||
} from "./utils/connectionUtils";
|
||||
import type {
|
||||
CommunicationIdentifier,
|
||||
CommunicationUserIdentifier,
|
||||
MicrosoftTeamsAppIdentifier,
|
||||
} from "@azure/communication-common";
|
||||
import { assert } from "chai";
|
||||
import type { Context } from "mocha";
|
||||
import type { CallInvite, CallConnection, CreateCallOptions, AnswerCallOptions } from "../src";
|
||||
import { CallAutomationClient } from "../src";
|
||||
import {
|
||||
createRecorder,
|
||||
createTestUser,
|
||||
dispatcherCallback,
|
||||
serviceBusWithNewCall,
|
||||
createCallAutomationClient,
|
||||
waitForIncomingCallContext,
|
||||
waitForEvent,
|
||||
events,
|
||||
serviceBusReceivers,
|
||||
incomingCallContexts,
|
||||
loadPersistedEvents,
|
||||
persistEvents,
|
||||
} from "./utils/recordedClient";
|
||||
import type {
|
||||
AnswerCallEventResult,
|
||||
CreateCallEventResult,
|
||||
} from "../src/eventprocessor/eventResponses";
|
||||
import { randomUUID } from "@azure/core-util";
|
||||
import { KnownCommunicationCloudEnvironmentModel } from "../src/generated/src";
|
||||
|
||||
function createOPSCallAutomationClient(
|
||||
oPSSourceIdentity: MicrosoftTeamsAppIdentifier,
|
||||
): CallAutomationClient {
|
||||
const connectionString = "endpoint=https://redacted.communication.azure.com/;accesskey=redacted";
|
||||
|
||||
return new CallAutomationClient(connectionString, {
|
||||
opsSourceIdentity: oPSSourceIdentity,
|
||||
});
|
||||
}
|
||||
|
||||
describe("Call Automation Client Unit Tests", () => {
|
||||
let targets: CommunicationIdentifier[];
|
||||
let target: CallInvite;
|
||||
let client: SinonStubbedInstance<CallAutomationClient> & CallAutomationClient;
|
||||
|
||||
beforeEach(() => {
|
||||
// set up
|
||||
targets = [
|
||||
{
|
||||
communicationUserId: CALL_TARGET_ID,
|
||||
},
|
||||
{
|
||||
communicationUserId: CALL_TARGET_ID_2,
|
||||
},
|
||||
];
|
||||
target = {
|
||||
targetParticipant: { communicationUserId: CALL_TARGET_ID },
|
||||
};
|
||||
// stub CallAutomationClient
|
||||
client = Sinon.createStubInstance(
|
||||
CallAutomationClient,
|
||||
) as SinonStubbedInstance<CallAutomationClient> & CallAutomationClient;
|
||||
});
|
||||
|
||||
it("RepeatabilityHeadersGeneration", async () => {
|
||||
// mocks
|
||||
const repeatabilityFirstSent: string = new Date().toUTCString();
|
||||
const repeatabilityRequestID: string = randomUUID();
|
||||
|
||||
// asserts
|
||||
assert.isNotNull(repeatabilityFirstSent);
|
||||
assert.isNotNull(repeatabilityRequestID);
|
||||
assert.typeOf(repeatabilityFirstSent, "string");
|
||||
assert.typeOf(repeatabilityRequestID, "string");
|
||||
});
|
||||
|
||||
it("CreateCall", async () => {
|
||||
// mocks
|
||||
const createCallResultMock: CreateCallResult = {
|
||||
callConnectionProperties: {} as CallConnectionProperties,
|
||||
callConnection: {} as CallConnection,
|
||||
waitForEventProcessor: async () => {
|
||||
return {} as CreateCallEventResult;
|
||||
},
|
||||
};
|
||||
client.createCall.returns(
|
||||
new Promise((resolve) => {
|
||||
resolve(createCallResultMock);
|
||||
}),
|
||||
);
|
||||
|
||||
const promiseResult = client.createCall(target, CALL_CALLBACK_URL);
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then((result: CreateCallResult) => {
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(client.createCall.calledWith(target, CALL_CALLBACK_URL));
|
||||
assert.equal(result, createCallResultMock);
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
|
||||
it("CreateGroupCall", async () => {
|
||||
// mocks
|
||||
const createGroupCallResultMock: CreateCallResult = {
|
||||
callConnectionProperties: {} as CallConnectionProperties,
|
||||
callConnection: {} as CallConnection,
|
||||
waitForEventProcessor: async () => {
|
||||
return {} as CreateCallEventResult;
|
||||
},
|
||||
};
|
||||
client.createGroupCall.returns(
|
||||
new Promise((resolve) => {
|
||||
resolve(createGroupCallResultMock);
|
||||
}),
|
||||
);
|
||||
|
||||
const promiseResult = client.createGroupCall(targets, CALL_CALLBACK_URL);
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then((result: CreateCallResult) => {
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(client.createGroupCall.calledWith(targets, CALL_CALLBACK_URL));
|
||||
assert.equal(result, createGroupCallResultMock);
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
|
||||
it("CreateOPSCall", async () => {
|
||||
// defined dummy variables
|
||||
const appId = "28:acs:redacted";
|
||||
const appCloud = KnownCommunicationCloudEnvironmentModel.Public;
|
||||
const oPSSouceStub = {
|
||||
teamsAppId: appId,
|
||||
cloud: appCloud,
|
||||
};
|
||||
|
||||
// stub an OPS CallAutomationClient
|
||||
const createOPSClientStub = Sinon.stub().callsFake(() =>
|
||||
createOPSCallAutomationClient(oPSSouceStub),
|
||||
);
|
||||
|
||||
// Use the stubbed factory function to create the client
|
||||
const oPSClient: SinonStubbedInstance<CallAutomationClient> & CallAutomationClient =
|
||||
createOPSClientStub();
|
||||
|
||||
// Explicitly stub the createCall method
|
||||
oPSClient.createCall = Sinon.stub();
|
||||
|
||||
// mocks
|
||||
const createCallResultMock: CreateCallResult = {
|
||||
callConnectionProperties: {
|
||||
source: {
|
||||
rawId: appId,
|
||||
teamsAppId: appId,
|
||||
cloud: appCloud,
|
||||
} as MicrosoftTeamsAppIdentifier,
|
||||
} as CallConnectionProperties,
|
||||
callConnection: {} as CallConnection,
|
||||
waitForEventProcessor: async () => {
|
||||
return {} as CreateCallEventResult;
|
||||
},
|
||||
};
|
||||
|
||||
(oPSClient.createCall as Sinon.SinonStub).returns(Promise.resolve(createCallResultMock));
|
||||
|
||||
const promiseResult = oPSClient.createCall(target, CALL_CALLBACK_URL);
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then((result: CreateCallResult) => {
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(oPSClient.createCall.calledWith(target, CALL_CALLBACK_URL));
|
||||
assert.equal(result, createCallResultMock);
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
|
||||
it("AnswerCall", async () => {
|
||||
// mocks
|
||||
const answerCallResultMock: AnswerCallResult = {
|
||||
callConnectionProperties: {} as CallConnectionProperties,
|
||||
callConnection: {} as CallConnection,
|
||||
waitForEventProcessor: async () => {
|
||||
return {} as AnswerCallEventResult;
|
||||
},
|
||||
};
|
||||
client.answerCall.returns(
|
||||
new Promise((resolve) => {
|
||||
resolve(answerCallResultMock);
|
||||
}),
|
||||
);
|
||||
|
||||
const promiseResult = client.answerCall(CALL_INCOMING_CALL_CONTEXT, CALL_CALLBACK_URL);
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then((result: AnswerCallResult) => {
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(client.answerCall.calledWith(CALL_INCOMING_CALL_CONTEXT, CALL_CALLBACK_URL));
|
||||
assert.equal(result, answerCallResultMock);
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
|
||||
it("RedirectCall", async () => {
|
||||
// mocks
|
||||
client.redirectCall.returns(
|
||||
new Promise((resolve) => {
|
||||
resolve(undefined);
|
||||
}),
|
||||
);
|
||||
|
||||
const promiseResult = client.redirectCall(CALL_INCOMING_CALL_CONTEXT, target);
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then(() => {
|
||||
assert.isTrue(client.redirectCall.calledWith(CALL_INCOMING_CALL_CONTEXT, target));
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
|
||||
it("RejectCall", async () => {
|
||||
// mocks
|
||||
client.rejectCall.returns(
|
||||
new Promise((resolve) => {
|
||||
resolve(undefined);
|
||||
}),
|
||||
);
|
||||
|
||||
const promiseResult = client.rejectCall(CALL_INCOMING_CALL_CONTEXT);
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then(() => {
|
||||
assert.isTrue(client.rejectCall.calledWith(CALL_INCOMING_CALL_CONTEXT));
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
});
|
||||
|
||||
describe("Call Automation Main Client Live Tests", function () {
|
||||
let recorder: Recorder;
|
||||
let callerCallAutomationClient: CallAutomationClient;
|
||||
let receiverCallAutomationClient: CallAutomationClient;
|
||||
let callConnection: CallConnection;
|
||||
let testUser: CommunicationUserIdentifier;
|
||||
let testUser2: CommunicationUserIdentifier;
|
||||
let testName: string;
|
||||
|
||||
beforeEach(async function (this: Context) {
|
||||
recorder = await createRecorder(this.currentTest);
|
||||
testUser = await createTestUser(recorder);
|
||||
testUser2 = await createTestUser(recorder);
|
||||
callerCallAutomationClient = createCallAutomationClient(recorder, testUser);
|
||||
receiverCallAutomationClient = createCallAutomationClient(recorder, testUser2);
|
||||
});
|
||||
|
||||
afterEach(async function (this: Context) {
|
||||
persistEvents(testName);
|
||||
serviceBusReceivers.forEach((receiver) => {
|
||||
receiver.close();
|
||||
});
|
||||
events.forEach((callConnectionEvents) => {
|
||||
callConnectionEvents.clear();
|
||||
});
|
||||
events.clear();
|
||||
serviceBusReceivers.clear();
|
||||
incomingCallContexts.clear();
|
||||
await recorder.stop();
|
||||
if (callConnection) {
|
||||
try {
|
||||
await callConnection.hangUp(true);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("Create a call and hangup", async function () {
|
||||
testName = this.test?.fullTitle()
|
||||
? this.test?.fullTitle().replace(/ /g, "_")
|
||||
: "create_call_and_hang_up";
|
||||
await loadPersistedEvents(testName);
|
||||
|
||||
const callInvite: CallInvite = { targetParticipant: testUser2 };
|
||||
const uniqueId = await serviceBusWithNewCall(testUser, testUser2);
|
||||
const callBackUrl: string = dispatcherCallback + `?q=${uniqueId}`;
|
||||
const createCallOption: CreateCallOptions = { operationContext: "operationContextCreateCall" };
|
||||
|
||||
const result = await callerCallAutomationClient.createCall(
|
||||
callInvite,
|
||||
callBackUrl,
|
||||
createCallOption,
|
||||
);
|
||||
const incomingCallContext = await waitForIncomingCallContext(uniqueId, 8000);
|
||||
const callConnectionId: string = result.callConnectionProperties.callConnectionId
|
||||
? result.callConnectionProperties.callConnectionId
|
||||
: "";
|
||||
assert.isDefined(incomingCallContext);
|
||||
|
||||
if (incomingCallContext) {
|
||||
const answerCallOptions: AnswerCallOptions = {
|
||||
operationContext: "operationContextAnswerCall",
|
||||
};
|
||||
await receiverCallAutomationClient.answerCall(
|
||||
incomingCallContext,
|
||||
callBackUrl,
|
||||
answerCallOptions,
|
||||
);
|
||||
}
|
||||
|
||||
const callConnectedEvent = await waitForEvent("CallConnected", callConnectionId, 8000);
|
||||
assert.isDefined(callConnectedEvent);
|
||||
callConnection = result.callConnection;
|
||||
|
||||
await callConnection.hangUp(true);
|
||||
|
||||
const callDisconnectedEvent = await waitForEvent("CallDisconnected", callConnectionId, 8000);
|
||||
assert.isDefined(callDisconnectedEvent);
|
||||
}).timeout(60000);
|
||||
|
||||
it("Reject call", async function () {
|
||||
testName = this.test?.fullTitle() ? this.test?.fullTitle().replace(/ /g, "_") : "reject_call";
|
||||
await loadPersistedEvents(testName);
|
||||
|
||||
const callInvite: CallInvite = { targetParticipant: testUser2 };
|
||||
const uniqueId = await serviceBusWithNewCall(testUser, testUser2);
|
||||
const callBackUrl: string = dispatcherCallback + `?q=${uniqueId}`;
|
||||
const createCallOption: CreateCallOptions = { operationContext: "operationContextRejectCall" };
|
||||
|
||||
const result = await callerCallAutomationClient.createCall(
|
||||
callInvite,
|
||||
callBackUrl,
|
||||
createCallOption,
|
||||
);
|
||||
const incomingCallContext = await waitForIncomingCallContext(uniqueId, 8000);
|
||||
const callConnectionId: string = result.callConnectionProperties.callConnectionId
|
||||
? result.callConnectionProperties.callConnectionId
|
||||
: "";
|
||||
assert.isDefined(incomingCallContext);
|
||||
|
||||
if (incomingCallContext) {
|
||||
await receiverCallAutomationClient.rejectCall(incomingCallContext);
|
||||
}
|
||||
|
||||
const createCallFailedEvent = await waitForEvent("CreateCallFailed", callConnectionId, 8000);
|
||||
assert.isDefined(createCallFailedEvent);
|
||||
}).timeout(60000);
|
||||
});
|
|
@ -1,17 +1,17 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
import { assert, expect } from "chai";
|
||||
import type { CallAutomationEventProcessor } from "../src/eventprocessor/callAutomationEventProcessor";
|
||||
import type { CallConnected, CallDisconnected } from "../src/models/events";
|
||||
import type { CallAutomationEventProcessor } from "../src/eventprocessor/callAutomationEventProcessor.js";
|
||||
import type { CallConnected, CallDisconnected } from "../src/models/events.js";
|
||||
import {
|
||||
CALL_CALLBACK_URL,
|
||||
MOCK_CONNECTION_STRING,
|
||||
CALL_CALLER_ID,
|
||||
CALL_TARGET_ID,
|
||||
} from "./utils/connectionUtils";
|
||||
import type { CallInvite } from "../src";
|
||||
import { CallAutomationClient } from "../src";
|
||||
import { generateHttpClient } from "./utils/mockClient";
|
||||
} from "./utils/connectionUtils.js";
|
||||
import type { CallInvite } from "../src/index.js";
|
||||
import { CallAutomationClient } from "../src/index.js";
|
||||
import { generateHttpClient } from "./utils/mockClient.js";
|
||||
import { describe, it, assert, expect, beforeEach } from "vitest";
|
||||
|
||||
describe("Call Automation Event Processor Unit Tests", () => {
|
||||
const CALL_CONNECTION_CALL_ID = "callConnectionId";
|
||||
|
|
|
@ -0,0 +1,146 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import type { Recorder } from "@azure-tools/test-recorder";
|
||||
import type { CallAutomationClient } from "../../src/index.js";
|
||||
import { describe, it, assert, beforeEach, afterEach } from "vitest";
|
||||
import {
|
||||
createRecorder,
|
||||
createTestUser,
|
||||
dispatcherCallback,
|
||||
serviceBusWithNewCall,
|
||||
createCallAutomationClient,
|
||||
waitForIncomingCallContext,
|
||||
waitForEvent,
|
||||
events,
|
||||
serviceBusReceivers,
|
||||
incomingCallContexts,
|
||||
loadPersistedEvents,
|
||||
persistEvents,
|
||||
} from "../utils/recordedClient.js";
|
||||
import type { CommunicationUserIdentifier } from "@azure/communication-common";
|
||||
import type {
|
||||
CallInvite,
|
||||
CallConnection,
|
||||
CreateCallOptions,
|
||||
AnswerCallOptions,
|
||||
} from "../../src/index.js";
|
||||
import { isNodeLike } from "@azure/core-util";
|
||||
|
||||
describe("Call Automation Main Client Live Tests", { skip: !isNodeLike }, () => {
|
||||
let recorder: Recorder;
|
||||
let callerCallAutomationClient: CallAutomationClient;
|
||||
let receiverCallAutomationClient: CallAutomationClient;
|
||||
let callConnection: CallConnection;
|
||||
let testUser: CommunicationUserIdentifier;
|
||||
let testUser2: CommunicationUserIdentifier;
|
||||
let testName: string;
|
||||
|
||||
beforeEach(async (ctx) => {
|
||||
recorder = await createRecorder(ctx);
|
||||
testUser = await createTestUser(recorder);
|
||||
testUser2 = await createTestUser(recorder);
|
||||
callerCallAutomationClient = createCallAutomationClient(recorder, testUser);
|
||||
receiverCallAutomationClient = createCallAutomationClient(recorder, testUser2);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
persistEvents(testName);
|
||||
serviceBusReceivers.forEach((receiver) => {
|
||||
receiver.close();
|
||||
});
|
||||
events.forEach((callConnectionEvents) => {
|
||||
callConnectionEvents.clear();
|
||||
});
|
||||
events.clear();
|
||||
serviceBusReceivers.clear();
|
||||
incomingCallContexts.clear();
|
||||
await recorder.stop();
|
||||
if (callConnection) {
|
||||
try {
|
||||
await callConnection.hangUp(true);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("Create a call and hangup", { timeout: 60000 }, async (ctx) => {
|
||||
const fullTitle: string | undefined =
|
||||
ctx.task.suite && ctx.task.suite.name && ctx.task.name
|
||||
? `${ctx.task.suite.name} ${ctx.task.name}`
|
||||
: undefined;
|
||||
|
||||
testName = fullTitle ? fullTitle.replace(/ /g, "_") : "create_call_and_hang_up";
|
||||
await loadPersistedEvents(testName);
|
||||
|
||||
const callInvite: CallInvite = { targetParticipant: testUser2 };
|
||||
const uniqueId = await serviceBusWithNewCall(testUser, testUser2);
|
||||
const callBackUrl: string = dispatcherCallback + `?q=${uniqueId}`;
|
||||
const createCallOption: CreateCallOptions = { operationContext: "operationContextCreateCall" };
|
||||
|
||||
const result = await callerCallAutomationClient.createCall(
|
||||
callInvite,
|
||||
callBackUrl,
|
||||
createCallOption,
|
||||
);
|
||||
const incomingCallContext = await waitForIncomingCallContext(uniqueId, 8000);
|
||||
const callConnectionId: string = result.callConnectionProperties.callConnectionId
|
||||
? result.callConnectionProperties.callConnectionId
|
||||
: "";
|
||||
assert.isDefined(incomingCallContext);
|
||||
|
||||
if (incomingCallContext) {
|
||||
const answerCallOptions: AnswerCallOptions = {
|
||||
operationContext: "operationContextAnswerCall",
|
||||
};
|
||||
await receiverCallAutomationClient.answerCall(
|
||||
incomingCallContext,
|
||||
callBackUrl,
|
||||
answerCallOptions,
|
||||
);
|
||||
}
|
||||
|
||||
const callConnectedEvent = await waitForEvent("CallConnected", callConnectionId, 8000);
|
||||
|
||||
assert.isDefined(callConnectedEvent);
|
||||
callConnection = result.callConnection;
|
||||
|
||||
await callConnection.hangUp(true);
|
||||
|
||||
const callDisconnectedEvent = await waitForEvent("CallDisconnected", callConnectionId, 8000);
|
||||
assert.isDefined(callDisconnectedEvent);
|
||||
});
|
||||
|
||||
it("Reject call", { timeout: 60000 }, async (ctx) => {
|
||||
const fullTitle: string | undefined =
|
||||
ctx.task.suite && ctx.task.suite.name && ctx.task.name
|
||||
? `${ctx.task.suite.name} ${ctx.task.name}`
|
||||
: undefined;
|
||||
testName = fullTitle ? fullTitle.replace(/ /g, "_") : "reject_call";
|
||||
await loadPersistedEvents(testName);
|
||||
|
||||
const callInvite: CallInvite = { targetParticipant: testUser2 };
|
||||
const uniqueId = await serviceBusWithNewCall(testUser, testUser2);
|
||||
const callBackUrl: string = dispatcherCallback + `?q=${uniqueId}`;
|
||||
const createCallOption: CreateCallOptions = { operationContext: "operationContextRejectCall" };
|
||||
|
||||
const result = await callerCallAutomationClient.createCall(
|
||||
callInvite,
|
||||
callBackUrl,
|
||||
createCallOption,
|
||||
);
|
||||
const incomingCallContext = await waitForIncomingCallContext(uniqueId, 8000);
|
||||
const callConnectionId: string = result.callConnectionProperties.callConnectionId
|
||||
? result.callConnectionProperties.callConnectionId
|
||||
: "";
|
||||
assert.isDefined(incomingCallContext);
|
||||
|
||||
if (incomingCallContext) {
|
||||
await receiverCallAutomationClient.rejectCall(incomingCallContext);
|
||||
}
|
||||
|
||||
const createCallFailedEvent = await waitForEvent("CreateCallFailed", callConnectionId, 8000);
|
||||
assert.isDefined(createCallFailedEvent);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,230 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import type { CallConnectionProperties } from "../../src/models/models.js";
|
||||
import type { AnswerCallResult, CreateCallResult } from "../../src/models/responses.js";
|
||||
import {
|
||||
CALL_CALLBACK_URL,
|
||||
CALL_INCOMING_CALL_CONTEXT,
|
||||
CALL_TARGET_ID,
|
||||
CALL_TARGET_ID_2,
|
||||
} from "../utils/connectionUtils.js";
|
||||
import type {
|
||||
CommunicationIdentifier,
|
||||
MicrosoftTeamsAppIdentifier,
|
||||
} from "@azure/communication-common";
|
||||
import type { CallInvite, CallConnection } from "../../src/index.js";
|
||||
import type {
|
||||
AnswerCallEventResult,
|
||||
CreateCallEventResult,
|
||||
} from "../../src/eventprocessor/eventResponses.js";
|
||||
import { randomUUID } from "@azure/core-util";
|
||||
import { KnownCommunicationCloudEnvironmentModel } from "../../src/generated/src/index.js";
|
||||
import type { MockedObject } from "vitest";
|
||||
import { describe, it, assert, expect, vi, beforeEach } from "vitest";
|
||||
|
||||
vi.mock("../src/index.js", async (importActual) => {
|
||||
const CallAutomationClient = vi.fn();
|
||||
CallAutomationClient.prototype.createCall = vi.fn();
|
||||
CallAutomationClient.prototype.createGroupCall = vi.fn();
|
||||
CallAutomationClient.prototype.answerCall = vi.fn();
|
||||
CallAutomationClient.prototype.redirectCall = vi.fn();
|
||||
CallAutomationClient.prototype.rejectCall = vi.fn();
|
||||
|
||||
return {
|
||||
...(await importActual()),
|
||||
CallAutomationClient,
|
||||
};
|
||||
});
|
||||
|
||||
import { CallAutomationClient } from "../../src/index.js";
|
||||
|
||||
function createOPSCallAutomationClient(
|
||||
oPSSourceIdentity: MicrosoftTeamsAppIdentifier,
|
||||
): CallAutomationClient {
|
||||
const connectionString = "endpoint=https://redacted.communication.azure.com/;accesskey=redacted";
|
||||
|
||||
return new CallAutomationClient(connectionString, {
|
||||
opsSourceIdentity: oPSSourceIdentity,
|
||||
});
|
||||
}
|
||||
|
||||
describe("Call Automation Client Unit Tests", () => {
|
||||
let targets: CommunicationIdentifier[];
|
||||
let target: CallInvite;
|
||||
let client: MockedObject<CallAutomationClient>;
|
||||
|
||||
beforeEach(() => {
|
||||
// set up
|
||||
targets = [
|
||||
{
|
||||
communicationUserId: CALL_TARGET_ID,
|
||||
},
|
||||
{
|
||||
communicationUserId: CALL_TARGET_ID_2,
|
||||
},
|
||||
];
|
||||
target = {
|
||||
targetParticipant: { communicationUserId: CALL_TARGET_ID },
|
||||
};
|
||||
// stub CallAutomationClient
|
||||
client = vi.mocked(
|
||||
new CallAutomationClient(
|
||||
"endpoint=https://redacted.communication.azure.com/;accesskey=redacted",
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it("RepeatabilityHeadersGeneration", async () => {
|
||||
// mocks
|
||||
const repeatabilityFirstSent: string = new Date().toUTCString();
|
||||
const repeatabilityRequestID: string = randomUUID();
|
||||
|
||||
// asserts
|
||||
assert.isNotNull(repeatabilityFirstSent);
|
||||
assert.isNotNull(repeatabilityRequestID);
|
||||
assert.typeOf(repeatabilityFirstSent, "string");
|
||||
assert.typeOf(repeatabilityRequestID, "string");
|
||||
});
|
||||
|
||||
it("CreateCall", async () => {
|
||||
// mocks
|
||||
const createCallResultMock: CreateCallResult = {
|
||||
callConnectionProperties: {} as CallConnectionProperties,
|
||||
callConnection: {} as CallConnection,
|
||||
waitForEventProcessor: async () => {
|
||||
return {} as CreateCallEventResult;
|
||||
},
|
||||
};
|
||||
vi.spyOn(client, "createCall").mockResolvedValue(createCallResultMock);
|
||||
|
||||
const promiseResult = client.createCall(target, CALL_CALLBACK_URL);
|
||||
|
||||
// asserts
|
||||
const result = await promiseResult;
|
||||
assert.isNotNull(result);
|
||||
expect(client.createCall).toHaveBeenCalledWith(target, CALL_CALLBACK_URL);
|
||||
assert.equal(result, createCallResultMock);
|
||||
});
|
||||
|
||||
it("CreateGroupCall", async () => {
|
||||
// mocks
|
||||
const createGroupCallResultMock: CreateCallResult = {
|
||||
callConnectionProperties: {} as CallConnectionProperties,
|
||||
callConnection: {} as CallConnection,
|
||||
waitForEventProcessor: async () => {
|
||||
return {} as CreateCallEventResult;
|
||||
},
|
||||
};
|
||||
|
||||
vi.spyOn(client, "createGroupCall").mockResolvedValue(createGroupCallResultMock);
|
||||
|
||||
const promiseResult = client.createGroupCall(targets, CALL_CALLBACK_URL);
|
||||
|
||||
// asserts
|
||||
const result = await promiseResult;
|
||||
assert.isNotNull(result);
|
||||
expect(client.createGroupCall).toHaveBeenCalledWith(targets, CALL_CALLBACK_URL);
|
||||
assert.equal(result, createGroupCallResultMock);
|
||||
});
|
||||
|
||||
it("CreateOPSCall", async () => {
|
||||
// defined dummy variables
|
||||
const appId = "28:acs:redacted";
|
||||
const appCloud = KnownCommunicationCloudEnvironmentModel.Public;
|
||||
const oPSSouceStub = {
|
||||
teamsAppId: appId,
|
||||
cloud: appCloud,
|
||||
};
|
||||
|
||||
// stub an OPS CallAutomationClient
|
||||
const createOPSClientStub = vi
|
||||
.fn()
|
||||
.mockImplementation(() => createOPSCallAutomationClient(oPSSouceStub));
|
||||
|
||||
// Use the stubbed factory function to create the client
|
||||
const oPSClient: MockedObject<CallAutomationClient> = createOPSClientStub();
|
||||
|
||||
// Explicitly stub the createCall method
|
||||
oPSClient.createCall = vi.fn();
|
||||
|
||||
// mocks
|
||||
const createCallResultMock: CreateCallResult = {
|
||||
callConnectionProperties: {
|
||||
source: {
|
||||
rawId: appId,
|
||||
teamsAppId: appId,
|
||||
cloud: appCloud,
|
||||
} as MicrosoftTeamsAppIdentifier,
|
||||
} as CallConnectionProperties,
|
||||
callConnection: {} as CallConnection,
|
||||
waitForEventProcessor: async () => {
|
||||
return {} as CreateCallEventResult;
|
||||
},
|
||||
};
|
||||
|
||||
vi.spyOn(oPSClient, "createCall").mockResolvedValue(createCallResultMock);
|
||||
const promiseResult = oPSClient.createCall(target, CALL_CALLBACK_URL);
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then((result: CreateCallResult) => {
|
||||
assert.isNotNull(result);
|
||||
expect(oPSClient.createCall).toHaveBeenCalledWith(target, CALL_CALLBACK_URL);
|
||||
assert.equal(result, createCallResultMock);
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
|
||||
it("AnswerCall", async () => {
|
||||
// mocks
|
||||
const answerCallResultMock: AnswerCallResult = {
|
||||
callConnectionProperties: {} as CallConnectionProperties,
|
||||
callConnection: {} as CallConnection,
|
||||
waitForEventProcessor: async () => {
|
||||
return {} as AnswerCallEventResult;
|
||||
},
|
||||
};
|
||||
vi.spyOn(client, "answerCall").mockResolvedValue(answerCallResultMock);
|
||||
|
||||
const promiseResult = client.answerCall(CALL_INCOMING_CALL_CONTEXT, CALL_CALLBACK_URL);
|
||||
|
||||
// asserts
|
||||
const result = await promiseResult;
|
||||
|
||||
assert.isNotNull(result);
|
||||
expect(client.answerCall).toHaveBeenCalledWith(CALL_INCOMING_CALL_CONTEXT, CALL_CALLBACK_URL);
|
||||
assert.equal(result, answerCallResultMock);
|
||||
});
|
||||
|
||||
it("RedirectCall", async () => {
|
||||
// mocks
|
||||
vi.spyOn(client, "redirectCall").mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
resolve(undefined);
|
||||
}),
|
||||
);
|
||||
|
||||
const promiseResult = client.redirectCall(CALL_INCOMING_CALL_CONTEXT, target);
|
||||
|
||||
// asserts
|
||||
await promiseResult;
|
||||
expect(client.redirectCall).toHaveBeenCalledWith(CALL_INCOMING_CALL_CONTEXT, target);
|
||||
});
|
||||
|
||||
it("RejectCall", async () => {
|
||||
// mocks
|
||||
vi.spyOn(client, "rejectCall").mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
resolve(undefined);
|
||||
}),
|
||||
);
|
||||
|
||||
const promiseResult = client.rejectCall(CALL_INCOMING_CALL_CONTEXT);
|
||||
|
||||
// asserts
|
||||
await promiseResult;
|
||||
expect(client.rejectCall).toHaveBeenCalledWith(CALL_INCOMING_CALL_CONTEXT);
|
||||
});
|
||||
});
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
import type { Recorder } from "@azure-tools/test-recorder";
|
||||
import type { CommunicationUserIdentifier } from "@azure/communication-common";
|
||||
import { assert } from "chai";
|
||||
import type { Context } from "mocha";
|
||||
import type {
|
||||
CallAutomationClient,
|
||||
CallInvite,
|
||||
|
@ -26,11 +24,8 @@ import type {
|
|||
AddParticipantOptions,
|
||||
RemoveParticipantsOption,
|
||||
CancelAddParticipantOperationOptions,
|
||||
} from "../src";
|
||||
import { CallConnection } from "../src";
|
||||
import type { SinonStubbedInstance } from "sinon";
|
||||
import Sinon from "sinon";
|
||||
import { CALL_TARGET_ID, CALL_TARGET_ID_2 } from "./utils/connectionUtils";
|
||||
} from "../../src/index.js";
|
||||
import { CALL_TARGET_ID, CALL_TARGET_ID_2 } from "../utils/connectionUtils.js";
|
||||
import {
|
||||
createRecorder,
|
||||
createTestUser,
|
||||
|
@ -44,11 +39,35 @@ import {
|
|||
incomingCallContexts,
|
||||
persistEvents,
|
||||
loadPersistedEvents,
|
||||
} from "./utils/recordedClient";
|
||||
} from "../utils/recordedClient.js";
|
||||
import type { MockedObject } from "vitest";
|
||||
import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
|
||||
vi.mock(import("../../src/index.js"), async (importOriginal) => {
|
||||
const mod = await importOriginal();
|
||||
|
||||
const CallConnection = vi.fn();
|
||||
CallConnection.prototype.getCallConnectionProperties = vi.fn();
|
||||
CallConnection.prototype.hangUp = vi.fn();
|
||||
CallConnection.prototype.getParticipant = vi.fn();
|
||||
CallConnection.prototype.listParticipants = vi.fn();
|
||||
CallConnection.prototype.addParticipant = vi.fn();
|
||||
CallConnection.prototype.transferCallToParticipant = vi.fn();
|
||||
CallConnection.prototype.removeParticipant = vi.fn();
|
||||
CallConnection.prototype.muteParticipant = vi.fn();
|
||||
CallConnection.prototype.cancelAddParticipantOperation = vi.fn();
|
||||
|
||||
return {
|
||||
...mod,
|
||||
CallConnection,
|
||||
};
|
||||
});
|
||||
|
||||
import { CallConnection } from "../../src/index.js";
|
||||
|
||||
describe("CallConnection Unit Tests", () => {
|
||||
let target: CallInvite;
|
||||
let callConnection: SinonStubbedInstance<CallConnection> & CallConnection;
|
||||
let callConnection: MockedObject<CallConnection>;
|
||||
|
||||
beforeEach(() => {
|
||||
// set up
|
||||
|
@ -57,15 +76,21 @@ describe("CallConnection Unit Tests", () => {
|
|||
};
|
||||
|
||||
// stub CallConnection
|
||||
callConnection = Sinon.createStubInstance(
|
||||
CallConnection,
|
||||
) as SinonStubbedInstance<CallConnection> & CallConnection;
|
||||
callConnection = vi.mocked(
|
||||
new CallConnection(
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it("GetCallConnectionProperties", async () => {
|
||||
// mocks
|
||||
const callConnectionPropertiesMock: CallConnectionProperties = {};
|
||||
callConnection.getCallConnectionProperties.returns(
|
||||
callConnection.getCallConnectionProperties.mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
resolve(callConnectionPropertiesMock);
|
||||
}),
|
||||
|
@ -74,19 +99,15 @@ describe("CallConnection Unit Tests", () => {
|
|||
const promiseResult = callConnection.getCallConnectionProperties();
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then((result: CallConnectionProperties) => {
|
||||
const result = await promiseResult;
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(callConnection.getCallConnectionProperties.calledWith());
|
||||
expect(callConnection.getCallConnectionProperties).toHaveBeenCalled();
|
||||
assert.equal(result, callConnectionPropertiesMock);
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
|
||||
it("HangUp", async () => {
|
||||
// mocks
|
||||
callConnection.hangUp.returns(
|
||||
callConnection.hangUp.mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
resolve(undefined);
|
||||
}),
|
||||
|
@ -95,17 +116,13 @@ describe("CallConnection Unit Tests", () => {
|
|||
const promiseResult = callConnection.hangUp(false);
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then(() => {
|
||||
assert.isTrue(callConnection.hangUp.calledWith(false));
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
await promiseResult;
|
||||
expect(callConnection.hangUp).toHaveBeenCalledWith(false);
|
||||
});
|
||||
|
||||
it("Terminate", async () => {
|
||||
// mocks
|
||||
callConnection.hangUp.returns(
|
||||
callConnection.hangUp.mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
resolve(undefined);
|
||||
}),
|
||||
|
@ -114,18 +131,14 @@ describe("CallConnection Unit Tests", () => {
|
|||
const promiseResult = callConnection.hangUp(true);
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then(() => {
|
||||
assert.isTrue(callConnection.hangUp.calledWith(true));
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
await promiseResult;
|
||||
expect(callConnection.hangUp).toHaveBeenCalledWith(true);
|
||||
});
|
||||
|
||||
it("GetParticipant", async () => {
|
||||
// mocks
|
||||
const callParticipantMock: CallParticipant = {};
|
||||
callConnection.getParticipant.returns(
|
||||
callConnection.getParticipant.mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
resolve(callParticipantMock);
|
||||
}),
|
||||
|
@ -134,20 +147,16 @@ describe("CallConnection Unit Tests", () => {
|
|||
const promiseResult = callConnection.getParticipant(target.targetParticipant);
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then((result: CallParticipant) => {
|
||||
const result = await promiseResult;
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(callConnection.getParticipant.calledWith(target.targetParticipant));
|
||||
expect(callConnection.getParticipant).toHaveBeenCalledWith(target.targetParticipant);
|
||||
assert.equal(result, callParticipantMock);
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
|
||||
it("ListParticipants", async () => {
|
||||
// mocks
|
||||
const listParticipantsResultMock: ListParticipantsResult = {};
|
||||
callConnection.listParticipants.returns(
|
||||
callConnection.listParticipants.mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
resolve(listParticipantsResultMock);
|
||||
}),
|
||||
|
@ -156,14 +165,10 @@ describe("CallConnection Unit Tests", () => {
|
|||
const promiseResult = callConnection.listParticipants();
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then((result: ListParticipantsResult) => {
|
||||
const result = await promiseResult;
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(callConnection.listParticipants.calledWith());
|
||||
expect(callConnection.listParticipants).toHaveBeenCalled();
|
||||
assert.equal(result, listParticipantsResultMock);
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
|
||||
it("AddParticipant", async () => {
|
||||
|
@ -173,7 +178,7 @@ describe("CallConnection Unit Tests", () => {
|
|||
return {} as AddParticipantEventResult;
|
||||
},
|
||||
};
|
||||
callConnection.addParticipant.returns(
|
||||
callConnection.addParticipant.mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
resolve(addParticipantResultMock);
|
||||
}),
|
||||
|
@ -182,14 +187,10 @@ describe("CallConnection Unit Tests", () => {
|
|||
const promiseResult = callConnection.addParticipant(target);
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then((result: AddParticipantResult) => {
|
||||
const result = await promiseResult;
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(callConnection.addParticipant.calledWith(target));
|
||||
expect(callConnection.addParticipant).toHaveBeenCalledWith(target);
|
||||
assert.equal(result, addParticipantResultMock);
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
|
||||
it("TransferCallToParticipant", async () => {
|
||||
|
@ -199,7 +200,7 @@ describe("CallConnection Unit Tests", () => {
|
|||
return {} as TransferCallToParticipantEventResult;
|
||||
},
|
||||
};
|
||||
callConnection.transferCallToParticipant.returns(
|
||||
callConnection.transferCallToParticipant.mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
resolve(transferCallResultMock);
|
||||
}),
|
||||
|
@ -208,16 +209,10 @@ describe("CallConnection Unit Tests", () => {
|
|||
const promiseResult = callConnection.transferCallToParticipant(target.targetParticipant);
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then((result: TransferCallResult) => {
|
||||
const result = await promiseResult;
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(
|
||||
callConnection.transferCallToParticipant.calledWith(target.targetParticipant),
|
||||
);
|
||||
expect(callConnection.transferCallToParticipant).toHaveBeenCalledWith(target.targetParticipant);
|
||||
assert.equal(result, transferCallResultMock);
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
|
||||
it("TransferCallToParticipantWithTransferee", async () => {
|
||||
|
@ -227,7 +222,7 @@ describe("CallConnection Unit Tests", () => {
|
|||
return {} as TransferCallToParticipantEventResult;
|
||||
},
|
||||
};
|
||||
callConnection.transferCallToParticipant.returns(
|
||||
callConnection.transferCallToParticipant.mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
resolve(transferCallResultMock);
|
||||
}),
|
||||
|
@ -240,16 +235,13 @@ describe("CallConnection Unit Tests", () => {
|
|||
});
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then((result: TransferCallResult) => {
|
||||
const result = await promiseResult;
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(
|
||||
callConnection.transferCallToParticipant.calledWith(target.targetParticipant),
|
||||
expect(callConnection.transferCallToParticipant).toHaveBeenCalledWith(
|
||||
target.targetParticipant,
|
||||
{ transferee: transferee },
|
||||
);
|
||||
assert.equal(result, transferCallResultMock);
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
|
||||
it("RemoveParticipant", async () => {
|
||||
|
@ -259,7 +251,7 @@ describe("CallConnection Unit Tests", () => {
|
|||
return {} as RemoveParticipantEventResult;
|
||||
},
|
||||
};
|
||||
callConnection.removeParticipant.returns(
|
||||
callConnection.removeParticipant.mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
resolve(removeParticipantResultMock);
|
||||
}),
|
||||
|
@ -268,20 +260,16 @@ describe("CallConnection Unit Tests", () => {
|
|||
const promiseResult = callConnection.removeParticipant(target.targetParticipant);
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then((result: RemoveParticipantResult) => {
|
||||
const result = await promiseResult;
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(callConnection.removeParticipant.calledWith(target.targetParticipant));
|
||||
expect(callConnection.removeParticipant).toHaveBeenCalledWith(target.targetParticipant);
|
||||
assert.equal(result, removeParticipantResultMock);
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
|
||||
it("MuteParticipant", async () => {
|
||||
// mocks
|
||||
const muteParticipantResultMock: MuteParticipantResult = {};
|
||||
callConnection.muteParticipant.returns(
|
||||
callConnection.muteParticipant.mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
resolve(muteParticipantResultMock);
|
||||
}),
|
||||
|
@ -290,14 +278,10 @@ describe("CallConnection Unit Tests", () => {
|
|||
const promiseResult = callConnection.muteParticipant(target.targetParticipant);
|
||||
|
||||
// asserts
|
||||
promiseResult
|
||||
.then((result: MuteParticipantResult) => {
|
||||
const result = await promiseResult;
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(callConnection.muteParticipant.calledWith(target.targetParticipant));
|
||||
expect(callConnection.muteParticipant).toHaveBeenCalledWith(target.targetParticipant);
|
||||
assert.equal(result, muteParticipantResultMock);
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
|
||||
it("CancelAddParticipant", async () => {
|
||||
|
@ -308,21 +292,16 @@ describe("CallConnection Unit Tests", () => {
|
|||
return {} as CancelAddParticipantEventResult;
|
||||
},
|
||||
};
|
||||
callConnection.cancelAddParticipantOperation.returns(
|
||||
callConnection.cancelAddParticipantOperation.mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
resolve(cancelAddParticipantResultMock);
|
||||
}),
|
||||
);
|
||||
|
||||
callConnection
|
||||
.cancelAddParticipantOperation(invitationId)
|
||||
.then((result: CancelAddParticipantOperationResult) => {
|
||||
const result = await callConnection.cancelAddParticipantOperation(invitationId);
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(callConnection.cancelAddParticipantOperation.calledWith(invitationId));
|
||||
expect(callConnection.cancelAddParticipantOperation).toHaveBeenCalledWith(invitationId);
|
||||
assert.equal(result, cancelAddParticipantResultMock);
|
||||
return;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -336,15 +315,15 @@ describe("CallConnection Live Tests", function () {
|
|||
let callConnectionId: string;
|
||||
let testName: string;
|
||||
|
||||
beforeEach(async function (this: Context) {
|
||||
recorder = await createRecorder(this.currentTest);
|
||||
beforeEach(async function (ctx) {
|
||||
recorder = await createRecorder(ctx);
|
||||
testUser = await createTestUser(recorder);
|
||||
testUser2 = await createTestUser(recorder);
|
||||
callerCallAutomationClient = createCallAutomationClient(recorder, testUser);
|
||||
receiverCallAutomationClient = createCallAutomationClient(recorder, testUser2);
|
||||
});
|
||||
|
||||
afterEach(async function (this: Context) {
|
||||
afterEach(async function () {
|
||||
persistEvents(testName);
|
||||
serviceBusReceivers.forEach((receiver) => {
|
||||
receiver.close();
|
||||
|
@ -365,10 +344,12 @@ describe("CallConnection Live Tests", function () {
|
|||
}
|
||||
});
|
||||
|
||||
it("List all participants", async function () {
|
||||
testName = this.test?.fullTitle()
|
||||
? this.test?.fullTitle().replace(/ /g, "_")
|
||||
: "list_all_participants";
|
||||
it("List all participants", { timeout: 60000 }, async function (ctx) {
|
||||
const fullTitle: string | undefined =
|
||||
ctx.task.suite && ctx.task.suite.name && ctx.task.name
|
||||
? `${ctx.task.suite.name} ${ctx.task.name}`
|
||||
: undefined;
|
||||
testName = fullTitle ? fullTitle.replace(/ /g, "_") : "list_all_participants";
|
||||
await loadPersistedEvents(testName);
|
||||
|
||||
const callInvite: CallInvite = { targetParticipant: testUser2 };
|
||||
|
@ -400,12 +381,14 @@ describe("CallConnection Live Tests", function () {
|
|||
const allParticipants = await callConnection.listParticipants();
|
||||
assert.isDefined(allParticipants);
|
||||
assert.isDefined(allParticipants.values);
|
||||
}).timeout(60000);
|
||||
});
|
||||
|
||||
it("Add a participant and get call properties", async function () {
|
||||
testName = this.test?.fullTitle()
|
||||
? this.test?.fullTitle().replace(/ /g, "_")
|
||||
: "add_participant_and_get_call_props";
|
||||
it("Add a participant and get call properties", { timeout: 90000 }, async function (ctx) {
|
||||
const fullTitle: string | undefined =
|
||||
ctx.task.suite && ctx.task.suite.name && ctx.task.name
|
||||
? `${ctx.task.suite.name} ${ctx.task.name}`
|
||||
: undefined;
|
||||
testName = fullTitle ? fullTitle.replace(/ /g, "_") : "add_participant_and_get_call_props";
|
||||
await loadPersistedEvents(testName);
|
||||
|
||||
const callInvite: CallInvite = { targetParticipant: testUser2 };
|
||||
|
@ -467,12 +450,14 @@ describe("CallConnection Live Tests", function () {
|
|||
|
||||
const callProperties = await callConnection.getCallConnectionProperties();
|
||||
assert.isDefined(callProperties);
|
||||
}).timeout(90000);
|
||||
});
|
||||
|
||||
it("Remove a participant", async function () {
|
||||
testName = this.test?.fullTitle()
|
||||
? this.test?.fullTitle().replace(/ /g, "_")
|
||||
: "remove_a_participant";
|
||||
it("Remove a participant", { timeout: 60000 }, async function (ctx) {
|
||||
const fullTitle: string | undefined =
|
||||
ctx.task.suite && ctx.task.suite.name && ctx.task.name
|
||||
? `${ctx.task.suite.name} ${ctx.task.name}`
|
||||
: undefined;
|
||||
testName = fullTitle ? fullTitle.replace(/ /g, "_") : "remove_a_participant";
|
||||
await loadPersistedEvents(testName);
|
||||
|
||||
const callInvite: CallInvite = { targetParticipant: testUser2 };
|
||||
|
@ -512,12 +497,14 @@ describe("CallConnection Live Tests", function () {
|
|||
// A call needs at least 2 participants, removing one of the only 2 participants would end the call.
|
||||
const callEndedEvent = await waitForEvent("CallDisconnected", callConnectionId, 8000);
|
||||
assert.isDefined(callEndedEvent);
|
||||
}).timeout(60000);
|
||||
});
|
||||
|
||||
it("Mute a participant", async function () {
|
||||
testName = this.test?.fullTitle()
|
||||
? this.test?.fullTitle().replace(/ /g, "_")
|
||||
: "mute_participant";
|
||||
it("Mute a participant", { timeout: 90000 }, async function (ctx) {
|
||||
const fullTitle: string | undefined =
|
||||
ctx.task.suite && ctx.task.suite.name && ctx.task.name
|
||||
? `${ctx.task.suite.name} ${ctx.task.name}`
|
||||
: undefined;
|
||||
testName = fullTitle ? fullTitle.replace(/ /g, "_") : "mute_participant";
|
||||
await loadPersistedEvents(testName);
|
||||
|
||||
const callInvite: CallInvite = { targetParticipant: testUser2 };
|
||||
|
@ -577,12 +564,14 @@ describe("CallConnection Live Tests", function () {
|
|||
}
|
||||
}
|
||||
assert.isTrue(isMuted);
|
||||
}).timeout(90000);
|
||||
});
|
||||
|
||||
it("Add a participant cancels add participant request", async function () {
|
||||
testName = this.test?.fullTitle()
|
||||
? this.test?.fullTitle().replace(/ /g, "_")
|
||||
: "cancel_add_participant";
|
||||
it("Add a participant cancels add participant request", { timeout: 90000 }, async function (ctx) {
|
||||
const fullTitle: string | undefined =
|
||||
ctx.task.suite && ctx.task.suite.name && ctx.task.name
|
||||
? `${ctx.task.suite.name} ${ctx.task.name}`
|
||||
: undefined;
|
||||
testName = fullTitle ? fullTitle.replace(/ /g, "_") : "cancel_add_participant";
|
||||
await loadPersistedEvents(testName);
|
||||
|
||||
const callInvite: CallInvite = { targetParticipant: testUser2 };
|
||||
|
@ -637,5 +626,5 @@ describe("CallConnection Live Tests", function () {
|
|||
|
||||
assert.isDefined(addParticipantCancelledEvent);
|
||||
assert.equal(addResult.invitationId, addParticipantCancelledEvent?.invitationId);
|
||||
}).timeout(90000);
|
||||
});
|
||||
});
|
|
@ -1,9 +1,6 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
// External module imports
|
||||
import type { Context } from "mocha";
|
||||
|
||||
// Internal module imports
|
||||
import type { Recorder } from "@azure-tools/test-recorder";
|
||||
import type {
|
||||
CommunicationIdentifier,
|
||||
|
@ -11,11 +8,14 @@ import type {
|
|||
PhoneNumberIdentifier,
|
||||
} from "@azure/communication-common";
|
||||
import { serializeCommunicationIdentifier } from "@azure/communication-common";
|
||||
|
||||
// Parent directory imports
|
||||
import { CallMedia } from "../src/callMedia";
|
||||
import type { FileSource, TextSource, SsmlSource, RecognitionChoice } from "../src/models/models";
|
||||
import { DtmfTone } from "../src/models/models";
|
||||
import { CallMedia } from "../../src/callMedia.js";
|
||||
import type {
|
||||
FileSource,
|
||||
TextSource,
|
||||
SsmlSource,
|
||||
RecognitionChoice,
|
||||
} from "../../src/models/models.js";
|
||||
import { DtmfTone } from "../../src/models/models.js";
|
||||
import type {
|
||||
CallMediaRecognizeDtmfOptions,
|
||||
CallMediaRecognizeChoiceOptions,
|
||||
|
@ -32,8 +32,8 @@ import type {
|
|||
StopTranscriptionOptions,
|
||||
HoldOptions,
|
||||
UnholdOptions,
|
||||
} from "../src";
|
||||
import { CallAutomationEventProcessor } from "../src";
|
||||
} from "../../src/index.js";
|
||||
import { CallAutomationEventProcessor } from "../../src/index.js";
|
||||
|
||||
// Current directory imports
|
||||
import {
|
||||
|
@ -51,10 +51,8 @@ import {
|
|||
persistEvents,
|
||||
fileSourceUrl,
|
||||
getPhoneNumbers,
|
||||
} from "./utils/recordedClient";
|
||||
import sinon from "sinon";
|
||||
import { assert } from "chai";
|
||||
import { createMediaClient, generateHttpClient } from "./utils/mockClient";
|
||||
} from "../utils/recordedClient.js";
|
||||
import { createMediaClient, generateHttpClient } from "../utils/mockClient.js";
|
||||
import {
|
||||
CALL_CONNECTION_ID,
|
||||
CALL_TARGET_ID,
|
||||
|
@ -62,13 +60,14 @@ import {
|
|||
MEDIA_URL_WAV,
|
||||
baseUri,
|
||||
generateToken,
|
||||
} from "./utils/connectionUtils";
|
||||
} from "../utils/connectionUtils.js";
|
||||
import { describe, it, assert, vi, beforeEach, afterEach } from "vitest";
|
||||
|
||||
describe("CallMedia Unit Tests", async function () {
|
||||
let callMedia: CallMedia;
|
||||
|
||||
afterEach(function () {
|
||||
sinon.restore();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("can instantiate", async function () {
|
||||
|
@ -84,7 +83,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(202);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
|
||||
const playSource: FileSource[] = [
|
||||
{
|
||||
|
@ -96,7 +95,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const playTo: CommunicationIdentifier[] = [{ communicationUserId: CALL_TARGET_ID }];
|
||||
|
||||
await callMedia.play(playSource, playTo);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
|
||||
assert.equal(data.playTo[0].rawId, CALL_TARGET_ID);
|
||||
|
@ -109,7 +108,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(202);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
|
||||
const playSource: TextSource[] = [
|
||||
{
|
||||
|
@ -122,7 +121,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const playTo: CommunicationIdentifier[] = [{ communicationUserId: CALL_TARGET_ID }];
|
||||
|
||||
await callMedia.play(playSource, playTo);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
|
||||
assert.equal(data.playTo[0].rawId, CALL_TARGET_ID);
|
||||
|
@ -135,7 +134,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(202);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
|
||||
const playSource: SsmlSource[] = [
|
||||
{
|
||||
|
@ -149,7 +148,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const playTo: CommunicationIdentifier[] = [{ communicationUserId: CALL_TARGET_ID }];
|
||||
|
||||
await callMedia.play(playSource, playTo);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
|
||||
assert.equal(data.playTo[0].rawId, CALL_TARGET_ID);
|
||||
|
@ -162,7 +161,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(202);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
|
||||
const playSource: FileSource[] = [
|
||||
{
|
||||
|
@ -174,7 +173,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const playTo: CommunicationIdentifier[] = [];
|
||||
|
||||
await callMedia.play(playSource, playTo);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
|
||||
assert.equal(data.playSources[0].kind, "file");
|
||||
|
@ -186,7 +185,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(202);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
const targetParticipant: CommunicationIdentifier = { communicationUserId: CALL_TARGET_ID };
|
||||
const recognizeOptions: CallMediaRecognizeDtmfOptions = {
|
||||
kind: "callMediaRecognizeDtmfOptions",
|
||||
|
@ -194,7 +193,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
};
|
||||
|
||||
await callMedia.startRecognizing(targetParticipant, recognizeOptions);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
|
||||
assert.equal(data.recognizeInputType, "dtmf");
|
||||
|
@ -206,7 +205,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(202);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
const targetParticipant: CommunicationIdentifier = { communicationUserId: CALL_TARGET_ID };
|
||||
const choice: RecognitionChoice = {
|
||||
label: "choice",
|
||||
|
@ -218,7 +217,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
};
|
||||
|
||||
await callMedia.startRecognizing(targetParticipant, recognizeOptions);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
|
||||
assert.equal(data.recognizeInputType, "choices");
|
||||
|
@ -230,7 +229,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(202);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
const targetParticipant: CommunicationIdentifier = { communicationUserId: CALL_TARGET_ID };
|
||||
const recognizeOptions: CallMediaRecognizeSpeechOptions = {
|
||||
kind: "callMediaRecognizeSpeechOptions",
|
||||
|
@ -238,7 +237,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
};
|
||||
|
||||
await callMedia.startRecognizing(targetParticipant, recognizeOptions);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
|
||||
assert.equal(data.recognizeInputType, "speech");
|
||||
|
@ -250,10 +249,10 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(202);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
await callMedia.cancelAllOperations();
|
||||
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
|
||||
assert.equal(request.method, "POST");
|
||||
});
|
||||
|
@ -262,7 +261,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(200);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
const targetParticipant: CommunicationIdentifier = { communicationUserId: CALL_TARGET_ID };
|
||||
const continuousDtmfRecognitionOptions: ContinuousDtmfRecognitionOptions = {
|
||||
operationContext: "test_operation_context",
|
||||
|
@ -272,7 +271,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
targetParticipant,
|
||||
continuousDtmfRecognitionOptions,
|
||||
);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
|
||||
assert.deepEqual(data.targetParticipant, serializeCommunicationIdentifier(targetParticipant));
|
||||
|
@ -284,7 +283,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(200);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
const targetParticipant: CommunicationIdentifier = { communicationUserId: CALL_TARGET_ID };
|
||||
const continuousDtmfRecognitionOptions: ContinuousDtmfRecognitionOptions = {
|
||||
operationContext: "test_operation_context",
|
||||
|
@ -294,7 +293,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
targetParticipant,
|
||||
continuousDtmfRecognitionOptions,
|
||||
);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
|
||||
assert.deepEqual(data.targetParticipant, serializeCommunicationIdentifier(targetParticipant));
|
||||
|
@ -306,7 +305,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(202);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
const targetParticipant: CommunicationIdentifier = { communicationUserId: CALL_TARGET_ID };
|
||||
const sendDtmfOptions: SendDtmfTonesOptions = {
|
||||
operationContext: "test_operation_context",
|
||||
|
@ -314,7 +313,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const tones = ["one", "two", "three", "pound"];
|
||||
|
||||
await callMedia.sendDtmfTones(tones, targetParticipant, sendDtmfOptions);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
|
||||
assert.deepEqual(data.targetParticipant, serializeCommunicationIdentifier(targetParticipant));
|
||||
|
@ -327,7 +326,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(200);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
|
||||
const playSource: TextSource = {
|
||||
text: "test test test",
|
||||
|
@ -342,7 +341,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
operationCallbackUri: "https://localhost",
|
||||
};
|
||||
await callMedia.hold(participantToHold, options);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
assert.equal(data.targetParticipant.rawId, CALL_TARGET_ID);
|
||||
assert.equal(data.playSourceInfo.kind, "text");
|
||||
|
@ -356,11 +355,11 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(200);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
|
||||
const participantToHold: CommunicationIdentifier = { communicationUserId: CALL_TARGET_ID };
|
||||
await callMedia.hold(participantToHold);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
assert.equal(data.targetParticipant.rawId, CALL_TARGET_ID);
|
||||
assert.equal(request.method, "POST");
|
||||
|
@ -371,14 +370,14 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(200);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
|
||||
const participantToUnhold: CommunicationIdentifier = { communicationUserId: CALL_TARGET_ID };
|
||||
const options: UnholdOptions = {
|
||||
operationContext: "unholdContext",
|
||||
};
|
||||
await callMedia.unhold(participantToUnhold, options);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
assert.equal(data.targetParticipant.rawId, CALL_TARGET_ID);
|
||||
assert.equal(request.method, "POST");
|
||||
|
@ -389,7 +388,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(200);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
|
||||
const playSource: TextSource = {
|
||||
text: "test test test",
|
||||
|
@ -400,7 +399,7 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const participantToHold: CommunicationIdentifier = { communicationUserId: CALL_TARGET_ID };
|
||||
|
||||
await callMedia.startHoldMusic(participantToHold, playSource);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
assert.equal(data.targetParticipant.rawId, CALL_TARGET_ID);
|
||||
assert.equal(data.playSourceInfo.kind, "text");
|
||||
|
@ -412,11 +411,11 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(200);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
const participantToHold: CommunicationIdentifier = { communicationUserId: CALL_TARGET_ID };
|
||||
|
||||
await callMedia.startHoldMusic(participantToHold);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
assert.equal(data.targetParticipant.rawId, CALL_TARGET_ID);
|
||||
assert.equal(request.method, "POST");
|
||||
|
@ -427,12 +426,12 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(200);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
|
||||
const participantToUnhold: CommunicationIdentifier = { communicationUserId: CALL_TARGET_ID };
|
||||
|
||||
await callMedia.stopHoldMusic(participantToUnhold);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
assert.equal(data.targetParticipant.rawId, CALL_TARGET_ID);
|
||||
assert.equal(request.method, "POST");
|
||||
|
@ -442,14 +441,14 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(202);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
const startTranscriptionOptions: StartTranscriptionOptions = {
|
||||
locale: "en-US",
|
||||
operationContext: "test_operation_context",
|
||||
};
|
||||
|
||||
await callMedia.startTranscription(startTranscriptionOptions);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
|
||||
assert.equal(data.locale, startTranscriptionOptions.locale);
|
||||
|
@ -461,13 +460,13 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(202);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
const stopTranscriptionOptions: StopTranscriptionOptions = {
|
||||
operationContext: "test_operation_context",
|
||||
};
|
||||
|
||||
await callMedia.stopTranscription(stopTranscriptionOptions);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
|
||||
assert.equal(data.operationContext, stopTranscriptionOptions.operationContext);
|
||||
|
@ -478,11 +477,11 @@ describe("CallMedia Unit Tests", async function () {
|
|||
const mockHttpClient = generateHttpClient(202);
|
||||
|
||||
callMedia = createMediaClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
const locale = "en-US";
|
||||
|
||||
await callMedia.updateTranscription(locale);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
|
||||
assert.equal(data.locale, locale);
|
||||
|
@ -501,15 +500,15 @@ describe("Call Media Client Live Tests", function () {
|
|||
let receiverPhoneUser: PhoneNumberIdentifier;
|
||||
let testName: string;
|
||||
|
||||
beforeEach(async function (this: Context) {
|
||||
recorder = await createRecorder(this.currentTest);
|
||||
beforeEach(async function (ctx) {
|
||||
recorder = await createRecorder(ctx);
|
||||
testUser = await createTestUser(recorder);
|
||||
testUser2 = await createTestUser(recorder);
|
||||
callerCallAutomationClient = createCallAutomationClient(recorder, testUser);
|
||||
receiverCallAutomationClient = createCallAutomationClient(recorder, testUser2);
|
||||
});
|
||||
|
||||
afterEach(async function (this: Context) {
|
||||
afterEach(async function () {
|
||||
persistEvents(testName);
|
||||
serviceBusReceivers.forEach((receiver) => {
|
||||
receiver.close();
|
||||
|
@ -530,10 +529,12 @@ describe("Call Media Client Live Tests", function () {
|
|||
}
|
||||
});
|
||||
|
||||
it("Play audio to target participant", async function () {
|
||||
testName = this.test?.fullTitle()
|
||||
? this.test?.fullTitle().replace(/ /g, "_")
|
||||
: "create_call_and_hang_up";
|
||||
it("Play audio to target participant", { timeout: 60000 }, async function (ctx) {
|
||||
const fullTitle: string | undefined =
|
||||
ctx.task.suite && ctx.task.suite.name && ctx.task.name
|
||||
? `${ctx.task.suite.name} ${ctx.task.name}`
|
||||
: undefined;
|
||||
testName = fullTitle ? fullTitle.replace(/ /g, "_") : "create_call_and_hang_up";
|
||||
await loadPersistedEvents(testName);
|
||||
|
||||
const callInvite: CallInvite = { targetParticipant: testUser2 };
|
||||
|
@ -578,12 +579,14 @@ describe("Call Media Client Live Tests", function () {
|
|||
await callConnection.hangUp(true);
|
||||
const callDisconnectedEvent = await waitForEvent("CallDisconnected", callConnectionId, 8000);
|
||||
assert.isDefined(callDisconnectedEvent);
|
||||
}).timeout(60000);
|
||||
});
|
||||
|
||||
it("Play audio to all participants", async function () {
|
||||
testName = this.test?.fullTitle()
|
||||
? this.test?.fullTitle().replace(/ /g, "_")
|
||||
: "create_call_and_hang_up";
|
||||
it("Play audio to all participants", { timeout: 60000 }, async function (ctx) {
|
||||
const fullTitle: string | undefined =
|
||||
ctx.task.suite && ctx.task.suite.name && ctx.task.name
|
||||
? `${ctx.task.suite.name} ${ctx.task.name}`
|
||||
: undefined;
|
||||
testName = fullTitle ? fullTitle.replace(/ /g, "_") : "create_call_and_hang_up";
|
||||
await loadPersistedEvents(testName);
|
||||
|
||||
const callInvite: CallInvite = { targetParticipant: testUser2 };
|
||||
|
@ -630,12 +633,14 @@ describe("Call Media Client Live Tests", function () {
|
|||
await callConnection.hangUp(true);
|
||||
const callDisconnectedEvent = await waitForEvent("CallDisconnected", callConnectionId, 8000);
|
||||
assert.isDefined(callDisconnectedEvent);
|
||||
}).timeout(60000);
|
||||
});
|
||||
|
||||
it("Cancel all media operations", async function () {
|
||||
testName = this.test?.fullTitle()
|
||||
? this.test?.fullTitle().replace(/ /g, "_")
|
||||
: "create_call_and_hang_up";
|
||||
it("Cancel all media operations", { timeout: 60000 }, async function (ctx) {
|
||||
const fullTitle: string | undefined =
|
||||
ctx.task.suite && ctx.task.suite.name && ctx.task.name
|
||||
? `${ctx.task.suite.name} ${ctx.task.name}`
|
||||
: undefined;
|
||||
testName = fullTitle ? fullTitle.replace(/ /g, "_") : "create_call_and_hang_up";
|
||||
await loadPersistedEvents(testName);
|
||||
|
||||
const callInvite: CallInvite = { targetParticipant: testUser2 };
|
||||
|
@ -683,11 +688,15 @@ describe("Call Media Client Live Tests", function () {
|
|||
await callConnection.hangUp(true);
|
||||
const callDisconnectedEvent = await waitForEvent("CallDisconnected", callConnectionId, 8000);
|
||||
assert.isDefined(callDisconnectedEvent);
|
||||
}).timeout(60000);
|
||||
});
|
||||
|
||||
it("Trigger DTMF actions", async function () {
|
||||
testName = this.test?.fullTitle()
|
||||
? this.test?.fullTitle().replace(/ /g, "_")
|
||||
it("Trigger DTMF actions", { timeout: 60000 }, async function (ctx) {
|
||||
const fullTitle: string | undefined =
|
||||
ctx.task.suite && ctx.task.suite.name && ctx.task.name
|
||||
? `${ctx.task.suite.name} ${ctx.task.name}`
|
||||
: undefined;
|
||||
testName = fullTitle
|
||||
? fullTitle.replace(/ /g, "_")
|
||||
: "create_call_and_trigger_dtmf_actions_then_hang_up";
|
||||
await loadPersistedEvents(testName);
|
||||
|
||||
|
@ -753,5 +762,5 @@ describe("Call Media Client Live Tests", function () {
|
|||
await callConnection.hangUp(true);
|
||||
const callDisconnectedEvent = await waitForEvent("CallDisconnected", callConnectionId, 8000);
|
||||
assert.isDefined(callDisconnectedEvent);
|
||||
}).timeout(60000);
|
||||
});
|
||||
});
|
|
@ -1,10 +1,8 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import sinon from "sinon";
|
||||
import { assert } from "chai";
|
||||
import type * as RestModel from "../src/generated/src/models";
|
||||
import { createRecordingClient, generateHttpClient } from "./utils/mockClient";
|
||||
import type * as RestModel from "../../src/generated/src/models/index.js";
|
||||
import { createRecordingClient, generateHttpClient } from "../utils/mockClient.js";
|
||||
import {
|
||||
baseUri,
|
||||
CALL_CALLBACK_URL,
|
||||
|
@ -13,23 +11,22 @@ import {
|
|||
generateToken,
|
||||
RECORDING_ID,
|
||||
RECORDING_STATE,
|
||||
} from "./utils/connectionUtils";
|
||||
import { CallRecording } from "../src/callRecording";
|
||||
} from "../utils/connectionUtils.js";
|
||||
import { CallRecording } from "../../src/callRecording.js";
|
||||
import type {
|
||||
AnswerCallOptions,
|
||||
CreateCallOptions,
|
||||
PlayOptions,
|
||||
StartRecordingOptions,
|
||||
} from "../src/models/options";
|
||||
import { apiVersion } from "../src/generated/src/models/parameters";
|
||||
} from "../../src/models/options.js";
|
||||
import { apiVersion } from "../../src/generated/src/models/parameters.js";
|
||||
import type { ChannelAffinity } from "@azure/communication-call-automation";
|
||||
import type {
|
||||
CommunicationIdentifier,
|
||||
CommunicationUserIdentifier,
|
||||
} from "@azure/communication-common";
|
||||
import type { CallAutomationClient, CallInvite, CallConnection } from "../src";
|
||||
import type { CallAutomationClient, CallInvite, CallConnection } from "../../src/index.js";
|
||||
import type { Recorder } from "@azure-tools/test-recorder";
|
||||
import type { Context } from "mocha";
|
||||
import {
|
||||
createRecorder,
|
||||
createTestUser,
|
||||
|
@ -44,21 +41,22 @@ import {
|
|||
loadPersistedEvents,
|
||||
persistEvents,
|
||||
fileSourceUrl,
|
||||
} from "./utils/recordedClient";
|
||||
import type { FileSource } from "../src/models/models";
|
||||
} from "../utils/recordedClient.js";
|
||||
import type { FileSource } from "../../src/models/models.js";
|
||||
import { describe, it, assert, vi, beforeEach, afterEach } from "vitest";
|
||||
|
||||
describe("CallRecording Unit Tests", async function () {
|
||||
describe("CallRecording Unit Tests", () => {
|
||||
let callRecording: CallRecording;
|
||||
|
||||
afterEach(function () {
|
||||
sinon.restore();
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("can instantiate", async function () {
|
||||
it("can instantiate", async () => {
|
||||
new CallRecording(baseUri, { key: generateToken() });
|
||||
});
|
||||
|
||||
it("makes successful startRecording request with channel affinity", async function () {
|
||||
it("makes successful startRecording request with channel affinity", async () => {
|
||||
const mockResponse: RestModel.RecordingStateResponse = {
|
||||
recordingId: RECORDING_ID,
|
||||
recordingState: RECORDING_STATE,
|
||||
|
@ -66,7 +64,7 @@ describe("CallRecording Unit Tests", async function () {
|
|||
|
||||
const mockHttpClient = generateHttpClient(200, mockResponse);
|
||||
callRecording = createRecordingClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
|
||||
const channelZeroParticipant: CommunicationIdentifier = { communicationUserId: CALL_TARGET_ID };
|
||||
const channelAffinity: ChannelAffinity = {
|
||||
|
@ -84,7 +82,7 @@ describe("CallRecording Unit Tests", async function () {
|
|||
};
|
||||
|
||||
await callRecording.start(recOptions);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
|
||||
assert.equal(data.callLocator.kind, "serverCallLocator");
|
||||
|
@ -100,7 +98,7 @@ describe("CallRecording Unit Tests", async function () {
|
|||
);
|
||||
});
|
||||
|
||||
it("makes successful startRecording request", async function () {
|
||||
it("makes successful startRecording request", async () => {
|
||||
const mockResponse: RestModel.RecordingStateResponse = {
|
||||
recordingId: RECORDING_ID,
|
||||
recordingState: RECORDING_STATE,
|
||||
|
@ -108,7 +106,7 @@ describe("CallRecording Unit Tests", async function () {
|
|||
|
||||
const mockHttpClient = generateHttpClient(200, mockResponse);
|
||||
callRecording = createRecordingClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
|
||||
const recOptions: StartRecordingOptions = {
|
||||
recordingStateCallbackEndpointUrl: CALL_CALLBACK_URL,
|
||||
|
@ -119,7 +117,7 @@ describe("CallRecording Unit Tests", async function () {
|
|||
};
|
||||
|
||||
await callRecording.start(recOptions);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
const data = JSON.parse(request.body?.toString() || "");
|
||||
|
||||
assert.equal(data.callLocator.kind, "serverCallLocator");
|
||||
|
@ -131,7 +129,7 @@ describe("CallRecording Unit Tests", async function () {
|
|||
);
|
||||
});
|
||||
|
||||
it("makes successful getRecordingProperties request", async function () {
|
||||
it("makes successful getRecordingProperties request", async () => {
|
||||
const mockResponse: RestModel.RecordingStateResponse = {
|
||||
recordingId: RECORDING_ID,
|
||||
recordingState: RECORDING_STATE,
|
||||
|
@ -139,10 +137,10 @@ describe("CallRecording Unit Tests", async function () {
|
|||
|
||||
const mockHttpClient = generateHttpClient(200, mockResponse);
|
||||
callRecording = createRecordingClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
|
||||
await callRecording.getState(RECORDING_ID);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
|
||||
assert.equal(request.method, "GET");
|
||||
assert.equal(
|
||||
|
@ -154,9 +152,9 @@ describe("CallRecording Unit Tests", async function () {
|
|||
it("Sends correct args to stop a recording", async () => {
|
||||
const mockHttpClient = generateHttpClient(204);
|
||||
callRecording = createRecordingClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
await callRecording.stop(RECORDING_ID);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
|
||||
assert.equal(
|
||||
request.url,
|
||||
|
@ -168,9 +166,9 @@ describe("CallRecording Unit Tests", async function () {
|
|||
it("Sends correct args to pause a recording", async () => {
|
||||
const mockHttpClient = generateHttpClient(202);
|
||||
callRecording = createRecordingClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
await callRecording.pause(RECORDING_ID);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
|
||||
assert.equal(
|
||||
request.url,
|
||||
|
@ -182,9 +180,9 @@ describe("CallRecording Unit Tests", async function () {
|
|||
it("Sends correct args to resume a recording", async () => {
|
||||
const mockHttpClient = generateHttpClient(202);
|
||||
callRecording = createRecordingClient(mockHttpClient);
|
||||
const spy = sinon.spy(mockHttpClient, "sendRequest");
|
||||
const spy = vi.spyOn(mockHttpClient, "sendRequest");
|
||||
await callRecording.resume(RECORDING_ID);
|
||||
const request = spy.getCall(0).args[0];
|
||||
const request = spy.mock.calls[0][0];
|
||||
|
||||
assert.equal(
|
||||
request.url,
|
||||
|
@ -194,7 +192,7 @@ describe("CallRecording Unit Tests", async function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe("CallRecording Live Tests", function () {
|
||||
describe("CallRecording Live Tests", () => {
|
||||
let recorder: Recorder;
|
||||
let callerCallAutomationClient: CallAutomationClient;
|
||||
let receiverCallAutomationClient: CallAutomationClient;
|
||||
|
@ -203,15 +201,15 @@ describe("CallRecording Live Tests", function () {
|
|||
let testUser2: CommunicationUserIdentifier;
|
||||
let testName: string;
|
||||
|
||||
beforeEach(async function (this: Context) {
|
||||
recorder = await createRecorder(this.currentTest);
|
||||
beforeEach(async function (ctx) {
|
||||
recorder = await createRecorder(ctx);
|
||||
testUser = await createTestUser(recorder);
|
||||
testUser2 = await createTestUser(recorder);
|
||||
callerCallAutomationClient = createCallAutomationClient(recorder, testUser);
|
||||
receiverCallAutomationClient = createCallAutomationClient(recorder, testUser2);
|
||||
});
|
||||
|
||||
afterEach(async function (this: Context) {
|
||||
afterEach(async () => {
|
||||
persistEvents(testName);
|
||||
serviceBusReceivers.forEach((receiver) => {
|
||||
receiver.close();
|
||||
|
@ -232,10 +230,12 @@ describe("CallRecording Live Tests", function () {
|
|||
}
|
||||
});
|
||||
|
||||
it("Creates a call, start recording, and hangs up", async function () {
|
||||
testName = this.test?.fullTitle()
|
||||
? this.test?.fullTitle().replace(/ /g, "_")
|
||||
: "create_call_start_recording_and_hang_up";
|
||||
it("Creates a call, start recording, and hangs up", { timeout: 60000 }, async function (ctx) {
|
||||
const fullTitle: string | undefined =
|
||||
ctx.task.suite && ctx.task.suite.name && ctx.task.name
|
||||
? `${ctx.task.suite.name} ${ctx.task.name}`
|
||||
: undefined;
|
||||
testName = fullTitle ? fullTitle.replace(/ /g, "_") : "create_call_start_recording_and_hang_up";
|
||||
await loadPersistedEvents(testName);
|
||||
|
||||
const callInvite: CallInvite = { targetParticipant: testUser2 };
|
||||
|
@ -300,5 +300,5 @@ describe("CallRecording Live Tests", function () {
|
|||
.getState(recordingStateResult.recordingId);
|
||||
assert.equal(recStatus.recordingState, "active");
|
||||
await callerCallAutomationClient.getCallRecording().stop(recordingStateResult.recordingId);
|
||||
}).timeout(60000);
|
||||
});
|
||||
});
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import type { TranscriptionData, TranscriptionMetadata } from "../src/models/transcription";
|
||||
import { streamingData } from "../src/utli/streamingDataParser";
|
||||
import { assert } from "chai";
|
||||
import type { TranscriptionData, TranscriptionMetadata } from "../src/models/transcription.js";
|
||||
import { streamingData } from "../src/utli/streamingDataParser.js";
|
||||
import { describe, it, assert } from "vitest";
|
||||
|
||||
describe("Stream data parser unit tests", function () {
|
||||
const encoder = new TextEncoder();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import { isNode } from "@azure/core-util";
|
||||
import { isNodeLike } from "@azure/core-util";
|
||||
|
||||
export const baseUri = "https://contoso.api.fake";
|
||||
|
||||
|
@ -30,6 +30,6 @@ export const generateToken = (): string => {
|
|||
const validForMinutes = 60;
|
||||
const expiresOn = (Date.now() + validForMinutes * 60 * 1000) / 1000;
|
||||
const tokenString = JSON.stringify({ exp: expiresOn });
|
||||
const base64Token = isNode ? Buffer.from(tokenString).toString("base64") : btoa(tokenString);
|
||||
const base64Token = isNodeLike ? Buffer.from(tokenString).toString("base64") : btoa(tokenString);
|
||||
return `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.${base64Token}.adM-ddBZZlQ1WlN3pdPBOF5G4Wh9iZpxNP_fSvpF4cWs`;
|
||||
};
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
import type { HttpClient, PipelineRequest, PipelineResponse } from "@azure/core-rest-pipeline";
|
||||
import { createHttpHeaders } from "@azure/core-rest-pipeline";
|
||||
import { baseUri, CALL_CONNECTION_ID, generateToken } from "../utils/connectionUtils";
|
||||
import { CallMedia } from "../../src/callMedia";
|
||||
import { CallRecording } from "../../src/callRecording";
|
||||
import { CallAutomationEventProcessor } from "../../src/eventprocessor/callAutomationEventProcessor";
|
||||
import { baseUri, CALL_CONNECTION_ID, generateToken } from "../utils/connectionUtils.js";
|
||||
import { CallMedia } from "../../src/callMedia.js";
|
||||
import { CallRecording } from "../../src/callRecording.js";
|
||||
import { CallAutomationEventProcessor } from "../../src/eventprocessor/callAutomationEventProcessor.js";
|
||||
|
||||
export const generateHttpClient = (status: number, parsedBody?: unknown): HttpClient => {
|
||||
const mockHttpClient: HttpClient = {
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
import * as dotenv from "dotenv";
|
||||
import { isNode } from "@azure/core-util";
|
||||
import fs from "fs";
|
||||
import type { RecorderStartOptions } from "@azure-tools/test-recorder";
|
||||
import { isNodeLike } from "@azure/core-util";
|
||||
import fs from "node:fs";
|
||||
import type { RecorderStartOptions, TestInfo } from "@azure-tools/test-recorder";
|
||||
import {
|
||||
Recorder,
|
||||
env,
|
||||
|
@ -12,8 +12,7 @@ import {
|
|||
isRecordMode,
|
||||
isPlaybackMode,
|
||||
} from "@azure-tools/test-recorder";
|
||||
import type { Test } from "mocha";
|
||||
import { generateToken } from "./connectionUtils";
|
||||
import { generateToken } from "./connectionUtils.js";
|
||||
import type { CommunicationIdentityClientOptions } from "@azure/communication-identity";
|
||||
import { CommunicationIdentityClient } from "@azure/communication-identity";
|
||||
import type {
|
||||
|
@ -26,10 +25,9 @@ import {
|
|||
isPhoneNumberIdentifier,
|
||||
createIdentifierFromRawId,
|
||||
} from "@azure/communication-common";
|
||||
import type { CallAutomationClientOptions, CallAutomationEvent } from "../../src";
|
||||
import { CallAutomationClient, parseCallAutomationEvent } from "../../src";
|
||||
import type { CommunicationIdentifierModel } from "../../src/generated/src";
|
||||
import { assert } from "chai";
|
||||
import type { CallAutomationClientOptions, CallAutomationEvent } from "../../src/index.js";
|
||||
import { CallAutomationClient, parseCallAutomationEvent } from "../../src/index.js";
|
||||
import type { CommunicationIdentifierModel } from "../../src/generated/src/index.js";
|
||||
import {
|
||||
createDefaultHttpClient,
|
||||
createHttpHeaders,
|
||||
|
@ -43,8 +41,9 @@ import type {
|
|||
import { ServiceBusClient } from "@azure/service-bus";
|
||||
import type { PhoneNumbersClientOptions } from "@azure/communication-phone-numbers";
|
||||
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";
|
||||
import { assert } from "vitest";
|
||||
|
||||
if (isNode) {
|
||||
if (isNodeLike) {
|
||||
dotenv.config();
|
||||
}
|
||||
|
||||
|
@ -126,7 +125,7 @@ export const recorderOptions: RecorderStartOptions = {
|
|||
],
|
||||
};
|
||||
|
||||
export async function createRecorder(context: Test | undefined): Promise<Recorder> {
|
||||
export async function createRecorder(context: TestInfo | undefined): Promise<Recorder> {
|
||||
const recorder = new Recorder(context);
|
||||
await recorder.start(recorderOptions);
|
||||
await recorder.setMatcher("HeaderlessMatcher");
|
||||
|
@ -272,7 +271,7 @@ export async function waitForEvent(
|
|||
export function persistEvents(testName: string): void {
|
||||
if (isRecordMode()) {
|
||||
// sanitize the events values accordingly
|
||||
const sanatizedEvents: any[] = [];
|
||||
const sanitizedEvents: any[] = [];
|
||||
for (const event of eventsToPersist) {
|
||||
const jsonData = JSON.parse(event);
|
||||
sanitizeObject(jsonData, [
|
||||
|
@ -283,10 +282,10 @@ export function persistEvents(testName: string): void {
|
|||
"correlationId",
|
||||
"serverCallId",
|
||||
]);
|
||||
sanatizedEvents.push(jsonData);
|
||||
sanitizedEvents.push(jsonData);
|
||||
}
|
||||
|
||||
const jsonArrayString = JSON.stringify(sanatizedEvents, null, 2);
|
||||
const jsonArrayString = JSON.stringify(sanitizedEvents, null, 2);
|
||||
fs.writeFile(`recordings\\${testName}.json`, jsonArrayString, (err) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
|
@ -300,10 +299,10 @@ export function persistEvents(testName: string): void {
|
|||
export async function loadPersistedEvents(testName: string): Promise<void> {
|
||||
if (isPlaybackMode()) {
|
||||
let data: string = "";
|
||||
// Different OS has differnt file system path format.
|
||||
// Different OS has different file system path format.
|
||||
try {
|
||||
data = fs.readFileSync(`recordings\\${testName}.json`, "utf-8");
|
||||
} catch (e) {
|
||||
} catch {
|
||||
console.log("original path doesn't work");
|
||||
data = fs.readFileSync(`recordings/${testName}.json`, "utf-8");
|
||||
}
|
||||
|
@ -328,7 +327,7 @@ export async function getPhoneNumbers(recorder: Recorder): Promise<string[]> {
|
|||
return phoneNumbers;
|
||||
}
|
||||
|
||||
function sanitizeObject(obj: any, keysToSanitize: string[]) {
|
||||
function sanitizeObject(obj: any, keysToSanitize: string[]): void {
|
||||
for (const key in obj) {
|
||||
if (typeof obj[key] === "object") {
|
||||
sanitizeObject(obj[key], keysToSanitize);
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"extends": "./.tshy/build.json",
|
||||
"include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"],
|
||||
"exclude": ["./test/**/node/**/*.ts"],
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist-test/browser",
|
||||
"rootDir": ".",
|
||||
"skipLibCheck": true
|
||||
}
|
||||
}
|
|
@ -1,11 +1,12 @@
|
|||
{
|
||||
"extends": "../../../tsconfig",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist-esm",
|
||||
"declarationDir": "./types",
|
||||
"paths": {
|
||||
"@azure/communication-call-automation": ["./src/index"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*.ts", "test/**/*.ts", "samples-dev/**/*.ts"]
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"rootDir": "."
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.mts", "src/**/*.cts", "samples-dev/**/*.ts", "test/**/*.ts"]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import { defineConfig, mergeConfig } from "vitest/config";
|
||||
import viteConfig from "../../../vitest.browser.shared.config.ts";
|
||||
import browserMap from "@azure-tools/vite-plugin-browser-test-map";
|
||||
|
||||
export default mergeConfig(
|
||||
viteConfig,
|
||||
defineConfig({
|
||||
plugins: [browserMap()],
|
||||
test: {
|
||||
include: ["dist-test/browser/test/**/*.spec.js"],
|
||||
hookTimeout: 5000000,
|
||||
testTimeout: 5000000,
|
||||
},
|
||||
}),
|
||||
);
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import { defineConfig, mergeConfig } from "vitest/config";
|
||||
import viteConfig from "../../../vitest.shared.config.ts";
|
||||
|
||||
export default mergeConfig(
|
||||
viteConfig,
|
||||
defineConfig({
|
||||
test: {
|
||||
include: ["test/**/*.spec.ts"],
|
||||
hookTimeout: 5000000,
|
||||
testTimeout: 5000000,
|
||||
},
|
||||
}),
|
||||
);
|
|
@ -9,8 +9,8 @@ export default mergeConfig(
|
|||
defineConfig({
|
||||
test: {
|
||||
include: ["test/**/*.spec.ts"],
|
||||
},
|
||||
hookTimeout: 5000000,
|
||||
testTimeout: 5000000,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
|
@ -9,9 +8,9 @@ export default mergeConfig(
|
|||
viteConfig,
|
||||
defineConfig({
|
||||
test: {
|
||||
include: [
|
||||
"dist-test/browser/test/**/*.spec.js",
|
||||
],
|
||||
include: ["dist-test/browser/test/**/*.spec.js"],
|
||||
hookTimeout: 5000000,
|
||||
testTimeout: 5000000,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
|
@ -10,6 +9,8 @@ export default mergeConfig(
|
|||
defineConfig({
|
||||
test: {
|
||||
include: ["test/**/*.spec.ts"],
|
||||
hookTimeout: 5000000,
|
||||
testTimeout: 5000000,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
|
Загрузка…
Ссылка в новой задаче