[communication] Migrate @azure-rest/communication-job-router to ESM/vitest (#31774)
### Packages impacted by this PR - @azure-rest/communication-job-router ### 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 the @azure-rest/communication-job-router package to ESM and vitest. ### 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:
Родитель
909440a1c5
Коммит
10ab5dc4a8
|
@ -19237,7 +19237,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/communication-job-router.tgz:
|
||||
resolution: {integrity: sha512-5LLJCERriFc6PMsBRCH2FAYffKFHxBTudi1OCbylAy5IUtqtIwzPME18A0VE/ixM90FkKYtJUc9vnIn9+8cfWA==, tarball: file:projects/communication-job-router.tgz}
|
||||
resolution: {integrity: sha512-xPt7oEFIEnDcZHXkEsgPlaOBwbjSF6dQq4uDtXsp/yeslQgiTdGNnO5bUMfuqpTTiiwSsXCyCKEy2FmmrcRHLw==, tarball: file:projects/communication-job-router.tgz}
|
||||
name: '@rush-temp/communication-job-router'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
|
@ -19247,6 +19247,8 @@ packages:
|
|||
'@types/chai': 4.3.20
|
||||
'@types/mocha': 10.0.9
|
||||
'@types/node': 18.19.64
|
||||
'@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)
|
||||
autorest: 3.7.1
|
||||
chai: 4.3.10
|
||||
dotenv: 16.4.5
|
||||
|
@ -19263,18 +19265,32 @@ packages:
|
|||
karma-sourcemap-loader: 0.4.0
|
||||
mocha: 10.8.2
|
||||
nyc: 17.1.0
|
||||
playwright: 1.48.2
|
||||
source-map-support: 0.5.21
|
||||
ts-node: 10.9.2(@types/node@18.19.64)(typescript@5.6.3)
|
||||
tslib: 2.8.1
|
||||
typescript: 5.6.3
|
||||
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-messages.tgz:
|
||||
|
|
|
@ -1,18 +1,31 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
||||
"mainEntryPointFilePath": "./types/src/index.d.ts",
|
||||
"docModel": { "enabled": true },
|
||||
"apiReport": { "enabled": true, "reportFolder": "./review" },
|
||||
"mainEntryPointFilePath": "dist/esm/index.d.ts",
|
||||
"docModel": {
|
||||
"enabled": true
|
||||
},
|
||||
"apiReport": {
|
||||
"enabled": true,
|
||||
"reportFolder": "./review"
|
||||
},
|
||||
"dtsRollup": {
|
||||
"enabled": true,
|
||||
"untrimmedFilePath": "",
|
||||
"publicTrimmedFilePath": "./types/communication-job-router.d.ts"
|
||||
"publicTrimmedFilePath": "dist/communication-job-router.d.ts"
|
||||
},
|
||||
"messages": {
|
||||
"tsdocMessageReporting": { "default": { "logLevel": "none" } },
|
||||
"tsdocMessageReporting": {
|
||||
"default": {
|
||||
"logLevel": "none"
|
||||
}
|
||||
},
|
||||
"extractorMessageReporting": {
|
||||
"ae-missing-release-tag": { "logLevel": "none" },
|
||||
"ae-unresolved-link": { "logLevel": "none" }
|
||||
"ae-missing-release-tag": {
|
||||
"logLevel": "none"
|
||||
},
|
||||
"ae-unresolved-link": {
|
||||
"logLevel": "none"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,134 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// https://github.com/karma-runner/karma-chrome-launcher
|
||||
process.env.CHROME_BIN = require("puppeteer").executablePath();
|
||||
require("dotenv").config();
|
||||
const { relativeRecordingsPath } = require("@azure-tools/test-recorder");
|
||||
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: ["source-map-support", "mocha"],
|
||||
|
||||
plugins: [
|
||||
"karma-mocha",
|
||||
"karma-mocha-reporter",
|
||||
"karma-chrome-launcher",
|
||||
"karma-firefox-launcher",
|
||||
"karma-env-preprocessor",
|
||||
"karma-coverage",
|
||||
"karma-sourcemap-loader",
|
||||
"karma-junit-reporter",
|
||||
"karma-source-map-support",
|
||||
],
|
||||
|
||||
// list of files / patterns to load in the browser
|
||||
files: [
|
||||
"dist-test/index.browser.js",
|
||||
{
|
||||
pattern: "dist-test/index.browser.js.map",
|
||||
type: "html",
|
||||
included: false,
|
||||
served: true,
|
||||
},
|
||||
],
|
||||
|
||||
// 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.js": ["coverage"]
|
||||
},
|
||||
|
||||
envPreprocessor: [
|
||||
"TEST_MODE",
|
||||
"ENDPOINT",
|
||||
"AZURE_CLIENT_SECRET",
|
||||
"AZURE_CLIENT_ID",
|
||||
"AZURE_TENANT_ID",
|
||||
"SUBSCRIPTION_ID",
|
||||
"RECORDINGS_RELATIVE_PATH",
|
||||
"COMMUNICATION_CONNECTION_STRING",
|
||||
],
|
||||
|
||||
// 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,
|
||||
|
||||
// --no-sandbox allows our tests to run in Linux without having to change the system.
|
||||
// --disable-web-security allows us to authenticate from the browser without having to write tests using interactive auth, which would be far more complex.
|
||||
browsers: ["ChromeHeadlessNoSandbox"],
|
||||
customLaunchers: {
|
||||
ChromeHeadlessNoSandbox: {
|
||||
base: "ChromeHeadless",
|
||||
flags: ["--no-sandbox", "--disable-web-security"],
|
||||
},
|
||||
},
|
||||
|
||||
// Continuous Integration mode
|
||||
// if true, Karma captures browsers, runs the tests and exits
|
||||
singleRun: false,
|
||||
|
||||
// Concurrency level
|
||||
// how many browser should be started simultaneous
|
||||
concurrency: 1,
|
||||
|
||||
browserNoActivityTimeout: 60000000,
|
||||
browserDisconnectTimeout: 10000,
|
||||
browserDisconnectTolerance: 3,
|
||||
|
||||
client: {
|
||||
mocha: {
|
||||
// change Karma's debug.html to the mocha web reporter
|
||||
reporter: "html",
|
||||
timeout: "600000",
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
|
@ -13,31 +13,28 @@
|
|||
"isomorphic"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "dist/index.js",
|
||||
"module": "./dist-esm/src/index.js",
|
||||
"types": "./types/communication-job-router.d.ts",
|
||||
"main": "./dist/commonjs/index.js",
|
||||
"module": "./dist/esm/index.js",
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"repository": "github:Azure/azure-sdk-for-js",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
|
||||
},
|
||||
"files": [
|
||||
"dist/",
|
||||
"dist-esm/src/",
|
||||
"types/communication-job-router.d.ts",
|
||||
"README.md",
|
||||
"LICENSE",
|
||||
"review/*"
|
||||
"LICENSE"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run clean && tsc -p . && dev-tool run bundle && dev-tool run vendored mkdirp ./review && dev-tool run extract-api",
|
||||
"build:browser": "tsc -p . && dev-tool run vendored cross-env ONLY_BROWSER=true rollup -c 2>&1",
|
||||
"build:debug": "tsc -p . && dev-tool run bundle && dev-tool run extract-api",
|
||||
"build:node": "tsc -p . && dev-tool run vendored cross-env ONLY_NODE=true rollup -c 2>&1",
|
||||
"build": "npm run clean && dev-tool run build-package && dev-tool run extract-api",
|
||||
"build:browser": "dev-tool run build-package && dev-tool run vendored cross-env ONLY_BROWSER=true rollup -c 2>&1",
|
||||
"build:debug": "dev-tool run build-package && dev-tool run bundle && dev-tool run extract-api",
|
||||
"build:node": "dev-tool run build-package && dev-tool run vendored cross-env ONLY_NODE=true rollup -c 2>&1",
|
||||
"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\" \"*.{js,json}\" \"test/**/*.ts\"",
|
||||
"clean": "dev-tool run vendored rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log",
|
||||
"execute:samples": "dev-tool samples run samples-dev",
|
||||
|
@ -45,8 +42,8 @@
|
|||
"format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\"",
|
||||
"generate:client": "echo skipped",
|
||||
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
|
||||
"integration-test:browser": "dev-tool run test:browser",
|
||||
"integration-test:node": "dev-tool run test:node-js-input -- --timeout 5000000 'dist-esm/test/**/*.spec.js'",
|
||||
"integration-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
|
||||
"integration-test:node": "dev-tool run test:vitest",
|
||||
"lint": "eslint package.json api-extractor.json src test",
|
||||
"lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]",
|
||||
"pack": "npm pack 2>&1",
|
||||
|
@ -54,50 +51,38 @@
|
|||
"test:browser": "npm run clean && npm run build:test && npm run unit-test:browser",
|
||||
"test:node": "npm run clean && npm run build:test && npm run unit-test:node",
|
||||
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
|
||||
"unit-test:browser": "dev-tool run test:browser",
|
||||
"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"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"autoPublish": false,
|
||||
"dependencies": {
|
||||
"@azure-rest/core-client": "^1.1.4",
|
||||
"@azure/communication-common": "^2.2.0",
|
||||
"@azure/core-auth": "^1.3.0",
|
||||
"@azure/core-paging": "^1.5.0",
|
||||
"@azure/core-rest-pipeline": "^1.12.0",
|
||||
"@azure/logger": "^1.0.0",
|
||||
"tslib": "^2.2.0"
|
||||
"@azure-rest/core-client": "^2.3.1",
|
||||
"@azure/communication-common": "^2.3.1",
|
||||
"@azure/core-auth": "^1.9.0",
|
||||
"@azure/core-paging": "^1.6.2",
|
||||
"@azure/core-rest-pipeline": "^1.18.0",
|
||||
"@azure/logger": "^1.1.4",
|
||||
"tslib": "^2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@azure-tools/test-credential": "^1.0.0",
|
||||
"@azure-tools/test-recorder": "^3.0.0",
|
||||
"@azure/core-util": "^1.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/core-util": "^1.11.0",
|
||||
"@azure/dev-tool": "^1.0.0",
|
||||
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
|
||||
"@azure/identity": "^4.0.1",
|
||||
"@types/chai": "^4.2.8",
|
||||
"@types/mocha": "^10.0.0",
|
||||
"@types/node": "^18.0.0",
|
||||
"@vitest/browser": "^2.1.5",
|
||||
"@vitest/coverage-istanbul": "^2.1.5",
|
||||
"autorest": "latest",
|
||||
"chai": "^4.2.0",
|
||||
"dotenv": "^16.0.0",
|
||||
"eslint": "^9.9.0",
|
||||
"karma": "^6.2.0",
|
||||
"karma-chrome-launcher": "^3.0.0",
|
||||
"karma-coverage": "^2.0.0",
|
||||
"karma-env-preprocessor": "^0.1.1",
|
||||
"karma-firefox-launcher": "^2.1.2",
|
||||
"karma-junit-reporter": "^2.0.1",
|
||||
"karma-mocha": "^2.0.1",
|
||||
"karma-mocha-reporter": "^2.2.5",
|
||||
"karma-source-map-support": "~1.4.0",
|
||||
"karma-sourcemap-loader": "^0.4.0",
|
||||
"mocha": "^10.0.0",
|
||||
"nyc": "^17.0.0",
|
||||
"source-map-support": "^0.5.9",
|
||||
"ts-node": "^10.0.0",
|
||||
"typescript": "~5.6.2"
|
||||
"playwright": "^1.48.2",
|
||||
"typescript": "~5.6.2",
|
||||
"vitest": "^2.1.5"
|
||||
},
|
||||
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-job-router-rest/README.md",
|
||||
"//metadata": {
|
||||
|
@ -108,14 +93,49 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"browser": {
|
||||
"./dist-esm/test/public/utils/env.js": "./dist-esm/test/public/utils/env.browser.js"
|
||||
},
|
||||
"browser": "./dist/browser/index.js",
|
||||
"//sampleConfiguration": {
|
||||
"productName": "Azure client library for Azure Communication Job Router services",
|
||||
"productSlugs": [
|
||||
"azure",
|
||||
"azure-communication-services"
|
||||
]
|
||||
},
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ import type { ClientOptions } from "@azure-rest/core-client";
|
|||
import { getClient } from "@azure-rest/core-client";
|
||||
import type { KeyCredential, TokenCredential } from "@azure/core-auth";
|
||||
import { isTokenCredential } from "@azure/core-auth";
|
||||
import { logger } from "./logger";
|
||||
import type { AzureCommunicationRoutingServiceClient } from "./clientDefinitions";
|
||||
import { logger } from "./logger.js";
|
||||
import type { AzureCommunicationRoutingServiceClient } from "./clientDefinitions.js";
|
||||
import {
|
||||
createCommunicationAuthPolicy,
|
||||
isKeyCredential,
|
||||
|
|
|
@ -35,7 +35,7 @@ import type {
|
|||
GetWorkerParameters,
|
||||
DeleteWorkerParameters,
|
||||
ListWorkersParameters,
|
||||
} from "./parameters";
|
||||
} from "./parameters.js";
|
||||
import type {
|
||||
UpsertClassificationPolicy200Response,
|
||||
UpsertClassificationPolicy201Response,
|
||||
|
@ -109,7 +109,7 @@ import type {
|
|||
DeleteWorkerDefaultResponse,
|
||||
ListWorkers200Response,
|
||||
ListWorkersDefaultResponse,
|
||||
} from "./responses";
|
||||
} from "./responses.js";
|
||||
import type { Client, StreamableMethod } from "@azure-rest/core-client";
|
||||
|
||||
export interface UpsertClassificationPolicy {
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import AzureCommunicationRoutingServiceClient from "./azureCommunicationRoutingServiceClient";
|
||||
import AzureCommunicationRoutingServiceClient from "./azureCommunicationRoutingServiceClient.js";
|
||||
|
||||
export * from "./azureCommunicationRoutingServiceClient";
|
||||
export * from "./parameters";
|
||||
export * from "./responses";
|
||||
export * from "./clientDefinitions";
|
||||
export * from "./isUnexpected";
|
||||
export * from "./models";
|
||||
export * from "./outputModels";
|
||||
export * from "./paginateHelper";
|
||||
export * from "./azureCommunicationRoutingServiceClient.js";
|
||||
export * from "./parameters.js";
|
||||
export * from "./responses.js";
|
||||
export * from "./clientDefinitions.js";
|
||||
export * from "./isUnexpected.js";
|
||||
export * from "./models.js";
|
||||
export * from "./outputModels.js";
|
||||
export * from "./paginateHelper.js";
|
||||
|
||||
export default AzureCommunicationRoutingServiceClient;
|
||||
|
|
|
@ -74,7 +74,7 @@ import type {
|
|||
DeleteWorkerDefaultResponse,
|
||||
ListWorkers200Response,
|
||||
ListWorkersDefaultResponse,
|
||||
} from "./responses";
|
||||
} from "./responses.js";
|
||||
|
||||
const responseMap: Record<string, string[]> = {
|
||||
"PATCH /routing/classificationPolicies/{classificationPolicyId}": ["200", "201"],
|
||||
|
|
|
@ -16,7 +16,7 @@ import type {
|
|||
UnassignJobOptions,
|
||||
DeclineJobOfferOptions,
|
||||
RouterWorker,
|
||||
} from "./models";
|
||||
} from "./models.js";
|
||||
|
||||
export interface UpsertClassificationPolicyHeaders {
|
||||
/** The request should only proceed if an entity matches this string. */
|
||||
|
|
|
@ -25,7 +25,7 @@ import type {
|
|||
RouterQueueStatisticsOutput,
|
||||
RouterWorkerOutput,
|
||||
PagedRouterWorkerOutput,
|
||||
} from "./outputModels";
|
||||
} from "./outputModels.js";
|
||||
|
||||
export interface UpsertClassificationPolicy200Headers {
|
||||
/** The entity tag for the response. */
|
||||
|
|
|
@ -3,15 +3,14 @@
|
|||
|
||||
import type { ClientOptions } from "@azure-rest/core-client";
|
||||
import * as dotenv from "dotenv";
|
||||
import type { RecorderStartOptions } from "@azure-tools/test-recorder";
|
||||
import type { RecorderStartOptions, TestInfo } from "@azure-tools/test-recorder";
|
||||
import { Recorder, env } from "@azure-tools/test-recorder";
|
||||
import JobRouter from "../../../src";
|
||||
import type { AzureCommunicationRoutingServiceClient } from "../../../src";
|
||||
import type { Context, Test } from "mocha";
|
||||
import { isNode } from "@azure/core-util";
|
||||
import { generateToken } from "../../public/utils/connection";
|
||||
import JobRouter from "../../../src/index.js";
|
||||
import type { AzureCommunicationRoutingServiceClient } from "../../../src/index.js";
|
||||
import { isNodeLike } from "@azure/core-util";
|
||||
import { generateToken } from "../../public/utils/connection.js";
|
||||
|
||||
if (isNode) {
|
||||
if (isNodeLike) {
|
||||
dotenv.config();
|
||||
}
|
||||
|
||||
|
@ -31,7 +30,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.addSanitizers(recorderOptions.sanitizerOptions!, ["record", "playback"]);
|
||||
|
@ -45,9 +44,9 @@ export interface RecordedRouterClient {
|
|||
}
|
||||
|
||||
export async function createRecordedRouterClientWithConnectionString(
|
||||
context: Context,
|
||||
context: TestInfo,
|
||||
): Promise<RecordedRouterClient> {
|
||||
const recorder = await createRecorder(context.currentTest);
|
||||
const recorder = await createRecorder(context);
|
||||
|
||||
return {
|
||||
routerClient: JobRouter(
|
||||
|
|
|
@ -2,23 +2,22 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
import type { Recorder } from "@azure-tools/test-recorder";
|
||||
import { assert } from "chai";
|
||||
import type { Context } from "mocha";
|
||||
import type {
|
||||
AzureCommunicationRoutingServiceClient,
|
||||
ClassificationPolicyOutput,
|
||||
} from "../../../src";
|
||||
import { paginate } from "../../../src";
|
||||
} from "../../../src/index.js";
|
||||
import { paginate } from "../../../src/index.js";
|
||||
import {
|
||||
getClassificationPolicyRequest,
|
||||
getDistributionPolicyRequest,
|
||||
getExceptionPolicyRequest,
|
||||
getQueueRequest,
|
||||
} from "../utils/testData";
|
||||
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient";
|
||||
import { timeoutMs } from "../utils/constants";
|
||||
} from "../utils/testData.js";
|
||||
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient.js";
|
||||
import { timeoutMs } from "../utils/constants.js";
|
||||
import { describe, it, assert, beforeEach, afterEach } from "vitest";
|
||||
|
||||
describe("JobRouterClient", function () {
|
||||
describe("JobRouterClient", () => {
|
||||
let routerClient: AzureCommunicationRoutingServiceClient;
|
||||
let recorder: Recorder;
|
||||
|
||||
|
@ -34,9 +33,9 @@ describe("JobRouterClient", function () {
|
|||
|
||||
const { queueId, queueRequest } = getQueueRequest(testRunId);
|
||||
|
||||
describe("classification Policy Operations", function () {
|
||||
this.beforeEach(async function (this: Context) {
|
||||
({ routerClient, recorder } = await createRecordedRouterClientWithConnectionString(this));
|
||||
describe("classification Policy Operations", () => {
|
||||
beforeEach(async (ctx) => {
|
||||
({ routerClient, recorder } = await createRecordedRouterClientWithConnectionString(ctx));
|
||||
|
||||
await routerClient
|
||||
.path("/routing/distributionPolicies/{distributionPolicyId}", distributionPolicyId)
|
||||
|
@ -56,7 +55,7 @@ describe("JobRouterClient", function () {
|
|||
});
|
||||
});
|
||||
|
||||
this.afterEach(async function (this: Context) {
|
||||
afterEach(async (ctx) => {
|
||||
await routerClient
|
||||
.path("/routing/distributionPolicies/{distributionPolicyId}", distributionPolicyId)
|
||||
.delete();
|
||||
|
@ -65,12 +64,12 @@ describe("JobRouterClient", function () {
|
|||
.delete();
|
||||
await routerClient.path("/routing/queues/{queueId}", queueId).delete();
|
||||
|
||||
if (!this.currentTest?.isPending() && recorder) {
|
||||
if (!ctx.task.pending && recorder) {
|
||||
await recorder.stop();
|
||||
}
|
||||
});
|
||||
|
||||
it("should create a classification policy", async function () {
|
||||
it("should create a classification policy", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient
|
||||
.path("/routing/classificationPolicies/{classificationPolicyId}", classificationPolicyId)
|
||||
.patch({
|
||||
|
@ -86,9 +85,9 @@ describe("JobRouterClient", function () {
|
|||
assert.isDefined(result);
|
||||
assert.isDefined(result?.id);
|
||||
assert.equal(result.name, classificationPolicyRequest.name);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should get a classification policy", async function () {
|
||||
it("should get a classification policy", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient
|
||||
.path("/routing/classificationPolicies/{classificationPolicyId}", classificationPolicyId)
|
||||
.get();
|
||||
|
@ -100,9 +99,9 @@ describe("JobRouterClient", function () {
|
|||
|
||||
assert.equal(result.id, classificationPolicyId);
|
||||
assert.equal(result.name, classificationPolicyRequest.name);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should update a classification policy", async function () {
|
||||
it("should update a classification policy", { timeout: timeoutMs }, async () => {
|
||||
const updatePatch = { ...classificationPolicyRequest, name: "new-name" };
|
||||
let response = await routerClient
|
||||
.path("/routing/classificationPolicies/{classificationPolicyId}", classificationPolicyId)
|
||||
|
@ -135,9 +134,9 @@ describe("JobRouterClient", function () {
|
|||
assert.isDefined(removeResult.id);
|
||||
assert.equal(updateResult.name, updatePatch.name);
|
||||
assert.isUndefined(removeResult.name);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should list classification policies", async function () {
|
||||
it("should list classification policies", { timeout: timeoutMs }, async () => {
|
||||
const result: ClassificationPolicyOutput[] = [];
|
||||
const response = await routerClient
|
||||
.path("/routing/classificationPolicies")
|
||||
|
@ -154,9 +153,9 @@ describe("JobRouterClient", function () {
|
|||
}
|
||||
|
||||
assert.isNotEmpty(result);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should delete a classification policy", async function () {
|
||||
it("should delete a classification policy", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient
|
||||
.path("/routing/classificationPolicies/{classificationPolicyId}", classificationPolicyId)
|
||||
.delete();
|
||||
|
@ -166,6 +165,6 @@ describe("JobRouterClient", function () {
|
|||
}
|
||||
|
||||
assert.isDefined(response);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,18 +2,17 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
import type { Recorder } from "@azure-tools/test-recorder";
|
||||
import { assert } from "chai";
|
||||
import type { Context } from "mocha";
|
||||
import type {
|
||||
AzureCommunicationRoutingServiceClient,
|
||||
DistributionPolicyOutput,
|
||||
} from "../../../src";
|
||||
import { paginate } from "../../../src";
|
||||
import { getDistributionPolicyRequest } from "../utils/testData";
|
||||
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient";
|
||||
import { timeoutMs } from "../utils/constants";
|
||||
} from "../../../src/index.js";
|
||||
import { paginate } from "../../../src/index.js";
|
||||
import { getDistributionPolicyRequest } from "../utils/testData.js";
|
||||
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient.js";
|
||||
import { timeoutMs } from "../utils/constants.js";
|
||||
import { describe, it, assert, beforeEach, afterEach } from "vitest";
|
||||
|
||||
describe("JobRouterClient", function () {
|
||||
describe("JobRouterClient", () => {
|
||||
let routerClient: AzureCommunicationRoutingServiceClient;
|
||||
let recorder: Recorder;
|
||||
|
||||
|
@ -22,18 +21,18 @@ describe("JobRouterClient", function () {
|
|||
const { distributionPolicyIdForCreationAndDeletionTest, distributionPolicyRequest } =
|
||||
getDistributionPolicyRequest(testRunId);
|
||||
|
||||
describe("Distribution Policy Operations", function () {
|
||||
this.beforeEach(async function (this: Context) {
|
||||
({ routerClient, recorder } = await createRecordedRouterClientWithConnectionString(this));
|
||||
describe("Distribution Policy Operations", () => {
|
||||
beforeEach(async (ctx) => {
|
||||
({ routerClient, recorder } = await createRecordedRouterClientWithConnectionString(ctx));
|
||||
});
|
||||
|
||||
this.afterEach(async function (this: Context) {
|
||||
if (!this.currentTest?.isPending() && recorder) {
|
||||
afterEach(async (ctx) => {
|
||||
if (!ctx.task.pending && recorder) {
|
||||
await recorder.stop();
|
||||
}
|
||||
});
|
||||
|
||||
it("should create a distribution policy", async function () {
|
||||
it("should create a distribution policy", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient
|
||||
.path(
|
||||
"/routing/distributionPolicies/{distributionPolicyId}",
|
||||
|
@ -52,9 +51,9 @@ describe("JobRouterClient", function () {
|
|||
assert.isDefined(result);
|
||||
assert.isDefined(result?.id);
|
||||
assert.equal(result.name, distributionPolicyRequest.name);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should get a distribution policy", async function () {
|
||||
it("should get a distribution policy", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient
|
||||
.path(
|
||||
"/routing/distributionPolicies/{distributionPolicyId}",
|
||||
|
@ -74,9 +73,9 @@ describe("JobRouterClient", function () {
|
|||
distributionPolicyRequest.offerExpiresAfterSeconds,
|
||||
);
|
||||
assert.deepEqual(result.mode, distributionPolicyRequest.mode);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should update a distribution policy", async function () {
|
||||
it("should update a distribution policy", { timeout: timeoutMs }, async () => {
|
||||
const updatePatch = { ...distributionPolicyRequest, name: "new-name" };
|
||||
let response = await routerClient
|
||||
.path(
|
||||
|
@ -115,9 +114,9 @@ describe("JobRouterClient", function () {
|
|||
assert.isDefined(removeResult.id);
|
||||
assert.equal(updateResult.name, updatePatch.name);
|
||||
assert.isUndefined(removeResult.name);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should list distribution policies", async function () {
|
||||
it("should list distribution policies", { timeout: timeoutMs }, async () => {
|
||||
const result: DistributionPolicyOutput[] = [];
|
||||
const response = await routerClient
|
||||
.path("/routing/distributionPolicies")
|
||||
|
@ -134,9 +133,9 @@ describe("JobRouterClient", function () {
|
|||
}
|
||||
|
||||
assert.isNotEmpty(result);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should delete a distribution policy", async function () {
|
||||
it("should delete a distribution policy", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient
|
||||
.path(
|
||||
"/routing/distributionPolicies/{distributionPolicyId}",
|
||||
|
@ -149,6 +148,6 @@ describe("JobRouterClient", function () {
|
|||
}
|
||||
|
||||
assert.isDefined(response);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,15 +2,17 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
import type { Recorder } from "@azure-tools/test-recorder";
|
||||
import { assert } from "chai";
|
||||
import type { Context } from "mocha";
|
||||
import type { AzureCommunicationRoutingServiceClient, ExceptionPolicyOutput } from "../../../src";
|
||||
import { paginate } from "../../../src";
|
||||
import { getExceptionPolicyRequest } from "../utils/testData";
|
||||
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient";
|
||||
import { timeoutMs } from "../utils/constants";
|
||||
import type {
|
||||
AzureCommunicationRoutingServiceClient,
|
||||
ExceptionPolicyOutput,
|
||||
} from "../../../src/index.js";
|
||||
import { paginate } from "../../../src/index.js";
|
||||
import { getExceptionPolicyRequest } from "../utils/testData.js";
|
||||
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient.js";
|
||||
import { timeoutMs } from "../utils/constants.js";
|
||||
import { describe, it, assert, beforeEach, afterEach } from "vitest";
|
||||
|
||||
describe("JobRouterClient", function () {
|
||||
describe("JobRouterClient", () => {
|
||||
let routerClient: AzureCommunicationRoutingServiceClient;
|
||||
let recorder: Recorder;
|
||||
|
||||
|
@ -19,18 +21,18 @@ describe("JobRouterClient", function () {
|
|||
const { exceptionPolicyIdForCreationAndDeletionTest, exceptionPolicyRequest } =
|
||||
getExceptionPolicyRequest(testRunId);
|
||||
|
||||
describe("exception Policy Operations", function () {
|
||||
this.beforeEach(async function (this: Context) {
|
||||
({ routerClient, recorder } = await createRecordedRouterClientWithConnectionString(this));
|
||||
describe("exception Policy Operations", () => {
|
||||
beforeEach(async (ctx) => {
|
||||
({ routerClient, recorder } = await createRecordedRouterClientWithConnectionString(ctx));
|
||||
});
|
||||
|
||||
this.afterEach(async function (this: Context) {
|
||||
if (!this.currentTest?.isPending() && recorder) {
|
||||
afterEach(async (ctx) => {
|
||||
if (!ctx.task.pending && recorder) {
|
||||
await recorder.stop();
|
||||
}
|
||||
});
|
||||
|
||||
it("should create a exception policy", async function () {
|
||||
it("should create a exception policy", { timeout: timeoutMs }, async () => {
|
||||
// TODO. we have a transient bug for creating existed exception policy return 400, try rotate the id for Record testing if this fails
|
||||
const response = await routerClient
|
||||
.path(
|
||||
|
@ -50,9 +52,9 @@ describe("JobRouterClient", function () {
|
|||
assert.isDefined(result);
|
||||
assert.isDefined(result?.id);
|
||||
assert.equal(result.name, exceptionPolicyRequest.name);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should get a exception policy", async function () {
|
||||
it("should get a exception policy", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient
|
||||
.path(
|
||||
"/routing/exceptionPolicies/{exceptionPolicyId}",
|
||||
|
@ -69,9 +71,9 @@ describe("JobRouterClient", function () {
|
|||
assert.equal(result.name, exceptionPolicyRequest.name);
|
||||
// TODO. Minor. need to fix "id" in actions in exceptionRules on service repo
|
||||
// assert.deepEqual(result.exceptionRules, exceptionPolicyRequest.exceptionRules);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should update a exception policy", async function () {
|
||||
it("should update a exception policy", { timeout: timeoutMs }, async () => {
|
||||
const updatePatch = { ...exceptionPolicyRequest, name: "new-name" };
|
||||
let response = await routerClient
|
||||
.path(
|
||||
|
@ -110,9 +112,9 @@ describe("JobRouterClient", function () {
|
|||
assert.isDefined(removeResult.id);
|
||||
assert.equal(updateResult.name, updatePatch.name);
|
||||
assert.isUndefined(removeResult.name);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should list exception policies", async function () {
|
||||
it("should list exception policies", { timeout: timeoutMs }, async () => {
|
||||
const result: ExceptionPolicyOutput[] = [];
|
||||
const response = await routerClient
|
||||
.path("/routing/exceptionPolicies")
|
||||
|
@ -129,9 +131,9 @@ describe("JobRouterClient", function () {
|
|||
}
|
||||
|
||||
assert.isNotEmpty(result);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should delete a exception policy", async function () {
|
||||
it("should delete a exception policy", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient
|
||||
.path(
|
||||
"/routing/exceptionPolicies/{exceptionPolicyId}",
|
||||
|
@ -144,6 +146,6 @@ describe("JobRouterClient", function () {
|
|||
}
|
||||
|
||||
assert.isDefined(response);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,27 +2,26 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
import type { Recorder } from "@azure-tools/test-recorder";
|
||||
import { assert } from "chai";
|
||||
import type {
|
||||
AzureCommunicationRoutingServiceClient,
|
||||
RouterJob,
|
||||
RouterJobOutput,
|
||||
RouterJobPositionDetailsOutput,
|
||||
} from "../../../src";
|
||||
import { paginate } from "../../../src";
|
||||
import type { Context } from "mocha";
|
||||
} from "../../../src/index.js";
|
||||
import { paginate } from "../../../src/index.js";
|
||||
import {
|
||||
getClassificationPolicyRequest,
|
||||
getDistributionPolicyRequest,
|
||||
getExceptionPolicyRequest,
|
||||
getJobRequest,
|
||||
getQueueRequest,
|
||||
} from "../utils/testData";
|
||||
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient";
|
||||
import { timeoutMs } from "../utils/constants";
|
||||
import { pollForJobQueued, retry } from "../utils/polling";
|
||||
} from "../utils/testData.js";
|
||||
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient.js";
|
||||
import { timeoutMs } from "../utils/constants.js";
|
||||
import { pollForJobQueued, retry } from "../utils/polling.js";
|
||||
import { describe, it, assert, beforeEach, afterEach } from "vitest";
|
||||
|
||||
describe("JobRouterClient", function () {
|
||||
describe("JobRouterClient", () => {
|
||||
let routerClient: AzureCommunicationRoutingServiceClient;
|
||||
let recorder: Recorder;
|
||||
|
||||
|
@ -36,21 +35,9 @@ describe("JobRouterClient", function () {
|
|||
getClassificationPolicyRequest(testRunId);
|
||||
const { jobId, jobRequest } = getJobRequest(testRunId);
|
||||
|
||||
// function getScheduledJob(scheduledTime: string) {
|
||||
// const matchingMode: ScheduleAndSuspendMode = {
|
||||
// kind: "schedule-and-suspend",
|
||||
// scheduleAt: new Date(scheduledTime)
|
||||
// }
|
||||
// return {
|
||||
// ...jobRequest,
|
||||
// notes: [],
|
||||
// matchingMode: matchingMode,
|
||||
// };
|
||||
// }
|
||||
|
||||
describe("Job Operations", function () {
|
||||
this.beforeEach(async function (this: Context) {
|
||||
({ routerClient, recorder } = await createRecordedRouterClientWithConnectionString(this));
|
||||
describe("Job Operations", () => {
|
||||
beforeEach(async (ctx) => {
|
||||
({ routerClient, recorder } = await createRecordedRouterClientWithConnectionString(ctx));
|
||||
|
||||
await routerClient
|
||||
.path("/routing/distributionPolicies/{distributionPolicyId}", distributionPolicyId)
|
||||
|
@ -76,7 +63,7 @@ describe("JobRouterClient", function () {
|
|||
});
|
||||
});
|
||||
|
||||
this.afterEach(async function (this: Context) {
|
||||
afterEach(async (ctx) => {
|
||||
await routerClient
|
||||
.path("/routing/classificationPolicies/{classificationPolicyId}", classificationPolicyId)
|
||||
.delete();
|
||||
|
@ -88,12 +75,12 @@ describe("JobRouterClient", function () {
|
|||
.delete();
|
||||
await routerClient.path("/routing/queues/{queueId}", queueId).delete();
|
||||
|
||||
if (!this.currentTest?.isPending() && recorder) {
|
||||
if (!ctx.task.pending && recorder) {
|
||||
await recorder.stop();
|
||||
}
|
||||
});
|
||||
|
||||
it("should create a job", async function () {
|
||||
it("should create a job", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient.path("/routing/jobs/{jobId}", jobId).patch({
|
||||
contentType: "application/merge-patch+json",
|
||||
body: jobRequest,
|
||||
|
@ -106,10 +93,10 @@ describe("JobRouterClient", function () {
|
|||
assert.isDefined(result);
|
||||
assert.isDefined(result.id);
|
||||
assert.equal(result.id, jobId);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
// TODO. Fix the transient bug on existing job
|
||||
// it("should create a scheduled job", async function () {
|
||||
// it("should create a scheduled job", async () => {
|
||||
// const currentTime: Date = new Date();
|
||||
// currentTime.setSeconds(currentTime.getSeconds() + 5);
|
||||
// const scheduledTime: string = recorder.variable("scheduledTime", currentTime.toISOString());
|
||||
|
@ -136,7 +123,7 @@ describe("JobRouterClient", function () {
|
|||
// );
|
||||
// }).timeout(timeoutMs);
|
||||
|
||||
it("should get a job", async function () {
|
||||
it("should get a job", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient.path("/routing/jobs/{jobId}", jobId).get();
|
||||
|
||||
if (response.status !== "200") {
|
||||
|
@ -147,9 +134,9 @@ describe("JobRouterClient", function () {
|
|||
assert.isDefined(result);
|
||||
assert.isDefined(result.id);
|
||||
assert.equal(result.id, jobId);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should update a job", async function () {
|
||||
it("should update a job", { timeout: timeoutMs }, async () => {
|
||||
const updatePatch = { ...jobRequest, priority: 25, dispositionCode: "testCode" };
|
||||
let response = await routerClient.path("/routing/jobs/{jobId}", jobId).patch({
|
||||
contentType: "application/merge-patch+json",
|
||||
|
@ -181,9 +168,9 @@ describe("JobRouterClient", function () {
|
|||
assert.equal(updateResult.priority, updatePatch.priority);
|
||||
assert.equal(removeResult.priority, 1);
|
||||
assert.isUndefined(removeResult.dispositionCode);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should get queue position for a job", async function () {
|
||||
it("should get queue position for a job", { timeout: timeoutMs }, async () => {
|
||||
await pollForJobQueued(jobId, routerClient);
|
||||
const response = await routerClient.path("/routing/jobs/{jobId}/position", jobId).get();
|
||||
|
||||
|
@ -195,9 +182,9 @@ describe("JobRouterClient", function () {
|
|||
assert.isDefined(result);
|
||||
assert.isDefined(result.position);
|
||||
assert.equal(jobId, result.jobId);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should reclassify a job", async function () {
|
||||
it("should reclassify a job", { timeout: timeoutMs }, async () => {
|
||||
let result;
|
||||
await retry(
|
||||
async () => {
|
||||
|
@ -214,9 +201,9 @@ describe("JobRouterClient", function () {
|
|||
);
|
||||
|
||||
assert.isDefined(result);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should list jobs", async function () {
|
||||
it("should list jobs", { timeout: timeoutMs }, async () => {
|
||||
const result: RouterJob[] = [];
|
||||
const response = await routerClient
|
||||
.path("/routing/jobs")
|
||||
|
@ -233,9 +220,9 @@ describe("JobRouterClient", function () {
|
|||
}
|
||||
|
||||
assert.isNotEmpty(result);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
// it("should list scheduled jobs", async function () {
|
||||
// it("should list scheduled jobs", async () => {
|
||||
// const currentTime: Date = new Date();
|
||||
// currentTime.setSeconds(currentTime.getSeconds() + 30);
|
||||
// const scheduledTime: string = recorder.variable("scheduledTime", currentTime.toISOString());
|
||||
|
@ -261,7 +248,7 @@ describe("JobRouterClient", function () {
|
|||
// assert.isNotEmpty(result);
|
||||
// }).timeout(timeoutMs);
|
||||
|
||||
it("should cancel a job", async function () {
|
||||
it("should cancel a job", { timeout: timeoutMs }, async () => {
|
||||
let result;
|
||||
await retry(
|
||||
async () => {
|
||||
|
@ -276,9 +263,9 @@ describe("JobRouterClient", function () {
|
|||
);
|
||||
|
||||
assert.isDefined(result);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should delete a job", async function () {
|
||||
it("should delete a job", { timeout: timeoutMs * 4 }, async () => {
|
||||
let deleted = false;
|
||||
await retry(
|
||||
async () => {
|
||||
|
@ -304,10 +291,10 @@ describe("JobRouterClient", function () {
|
|||
);
|
||||
|
||||
assert.isTrue(deleted);
|
||||
}).timeout(timeoutMs * 4);
|
||||
});
|
||||
|
||||
// TODO. Fix the transient bug on existing job
|
||||
// it("should delete a scheduled job", async function () {
|
||||
// it("should delete a scheduled job", async () => {
|
||||
// let deleted = false;
|
||||
// await retry(
|
||||
// async () => {
|
||||
|
|
|
@ -2,19 +2,21 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
import type { Recorder } from "@azure-tools/test-recorder";
|
||||
import { assert } from "chai";
|
||||
import type { AzureCommunicationRoutingServiceClient, RouterQueueOutput } from "../../../src";
|
||||
import { paginate } from "../../../src";
|
||||
import type { Context } from "mocha";
|
||||
import type {
|
||||
AzureCommunicationRoutingServiceClient,
|
||||
RouterQueueOutput,
|
||||
} from "../../../src/index.js";
|
||||
import { paginate } from "../../../src/index.js";
|
||||
import {
|
||||
getQueueRequest,
|
||||
getExceptionPolicyRequest,
|
||||
getDistributionPolicyRequest,
|
||||
} from "../utils/testData";
|
||||
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient";
|
||||
import { timeoutMs } from "../utils/constants";
|
||||
} from "../utils/testData.js";
|
||||
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient.js";
|
||||
import { timeoutMs } from "../utils/constants.js";
|
||||
import { describe, it, assert, beforeEach, afterEach } from "vitest";
|
||||
|
||||
describe("JobRouterClient", function () {
|
||||
describe("JobRouterClient", () => {
|
||||
let routerClient: AzureCommunicationRoutingServiceClient;
|
||||
let recorder: Recorder;
|
||||
|
||||
|
@ -25,9 +27,9 @@ describe("JobRouterClient", function () {
|
|||
const { exceptionPolicyId, exceptionPolicyRequest } = getExceptionPolicyRequest(testRunId);
|
||||
const { queueId, queueRequest } = getQueueRequest(testRunId);
|
||||
|
||||
describe("Queue Operations", function () {
|
||||
this.beforeEach(async function (this: Context) {
|
||||
({ routerClient, recorder } = await createRecordedRouterClientWithConnectionString(this));
|
||||
describe("Queue Operations", () => {
|
||||
beforeEach(async (ctx) => {
|
||||
({ routerClient, recorder } = await createRecordedRouterClientWithConnectionString(ctx));
|
||||
|
||||
await routerClient
|
||||
.path("/routing/distributionPolicies/{distributionPolicyId}", distributionPolicyId)
|
||||
|
@ -43,7 +45,7 @@ describe("JobRouterClient", function () {
|
|||
});
|
||||
});
|
||||
|
||||
this.afterEach(async function (this: Context) {
|
||||
afterEach(async (ctx) => {
|
||||
await routerClient
|
||||
.path("/routing/distributionPolicies/{distributionPolicyId}", distributionPolicyId)
|
||||
.delete();
|
||||
|
@ -51,12 +53,12 @@ describe("JobRouterClient", function () {
|
|||
.path("/routing/exceptionPolicies/{exceptionPolicyId}", exceptionPolicyId)
|
||||
.delete();
|
||||
|
||||
if (!this.currentTest?.isPending() && recorder) {
|
||||
if (!ctx.task.pending && recorder) {
|
||||
await recorder.stop();
|
||||
}
|
||||
});
|
||||
|
||||
it("should create a queue", async function () {
|
||||
it("should create a queue", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient.path("/routing/queues/{queueId}", queueId).patch({
|
||||
contentType: "application/merge-patch+json",
|
||||
body: queueRequest,
|
||||
|
@ -70,9 +72,9 @@ describe("JobRouterClient", function () {
|
|||
assert.isDefined(result);
|
||||
assert.isDefined(result?.id);
|
||||
assert.equal(result.name, queueRequest.name);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should get a queue", async function () {
|
||||
it("should get a queue", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient.path("/routing/queues/{queueId}", queueId).get();
|
||||
|
||||
if (response.status !== "200") {
|
||||
|
@ -82,9 +84,9 @@ describe("JobRouterClient", function () {
|
|||
|
||||
assert.equal(result.id, queueId);
|
||||
assert.equal(result.name, queueRequest.name);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should update a queue", async function () {
|
||||
it("should update a queue", { timeout: timeoutMs }, async () => {
|
||||
const updatePatch = { ...queueRequest, name: "new-name" };
|
||||
let response = await routerClient.path("/routing/queues/{queueId}", queueId).patch({
|
||||
contentType: "application/merge-patch+json",
|
||||
|
@ -113,9 +115,9 @@ describe("JobRouterClient", function () {
|
|||
assert.isDefined(removeResult.id);
|
||||
assert.equal(updateResult.name, updatePatch.name);
|
||||
assert.isUndefined(removeResult.name);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should list queues", async function () {
|
||||
it("should list queues", { timeout: timeoutMs }, async () => {
|
||||
const result: RouterQueueOutput[] = [];
|
||||
const response = await routerClient
|
||||
.path("/routing/queues")
|
||||
|
@ -132,9 +134,9 @@ describe("JobRouterClient", function () {
|
|||
}
|
||||
|
||||
assert.isNotEmpty(result);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should delete a queue", async function () {
|
||||
it("should delete a queue", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient.path("/routing/queues/{queueId}", queueId).delete();
|
||||
|
||||
if (response.status !== "204") {
|
||||
|
@ -142,6 +144,6 @@ describe("JobRouterClient", function () {
|
|||
}
|
||||
|
||||
assert.isDefined(response);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,20 +2,22 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
import type { Recorder } from "@azure-tools/test-recorder";
|
||||
import { assert } from "chai";
|
||||
import type { Context } from "mocha";
|
||||
import type { AzureCommunicationRoutingServiceClient, RouterWorkerOutput } from "../../../src";
|
||||
import { paginate } from "../../../src";
|
||||
import type {
|
||||
AzureCommunicationRoutingServiceClient,
|
||||
RouterWorkerOutput,
|
||||
} from "../../../src/index.js";
|
||||
import { paginate } from "../../../src/index.js";
|
||||
import {
|
||||
getDistributionPolicyRequest,
|
||||
getExceptionPolicyRequest,
|
||||
getQueueRequest,
|
||||
getWorkerRequest,
|
||||
} from "../utils/testData";
|
||||
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient";
|
||||
import { sleep, timeoutMs } from "../utils/constants";
|
||||
} from "../utils/testData.js";
|
||||
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient.js";
|
||||
import { sleep, timeoutMs } from "../utils/constants.js";
|
||||
import { describe, it, assert, beforeEach, afterEach } from "vitest";
|
||||
|
||||
describe("JobRouterClient", function () {
|
||||
describe("JobRouterClient", () => {
|
||||
let routerClient: AzureCommunicationRoutingServiceClient;
|
||||
let recorder: Recorder;
|
||||
|
||||
|
@ -27,9 +29,9 @@ describe("JobRouterClient", function () {
|
|||
const { queueId, queueRequest } = getQueueRequest(testRunId);
|
||||
const { workerId, workerRequest } = getWorkerRequest(testRunId);
|
||||
|
||||
describe("Worker Operations", function () {
|
||||
this.beforeEach(async function (this: Context) {
|
||||
({ routerClient, recorder } = await createRecordedRouterClientWithConnectionString(this));
|
||||
describe("Worker Operations", () => {
|
||||
beforeEach(async (ctx) => {
|
||||
({ routerClient, recorder } = await createRecordedRouterClientWithConnectionString(ctx));
|
||||
|
||||
await routerClient
|
||||
.path("/routing/distributionPolicies/{distributionPolicyId}", distributionPolicyId)
|
||||
|
@ -49,7 +51,7 @@ describe("JobRouterClient", function () {
|
|||
});
|
||||
});
|
||||
|
||||
this.afterEach(async function (this: Context) {
|
||||
afterEach(async (ctx) => {
|
||||
await routerClient
|
||||
.path("/routing/distributionPolicies/{distributionPolicyId}", distributionPolicyId)
|
||||
.delete();
|
||||
|
@ -58,12 +60,12 @@ describe("JobRouterClient", function () {
|
|||
.delete();
|
||||
await routerClient.path("/routing/queues/{queueId}", queueId).delete();
|
||||
|
||||
if (!this.currentTest?.isPending() && recorder) {
|
||||
if (!ctx.task.pending && recorder) {
|
||||
await recorder.stop();
|
||||
}
|
||||
});
|
||||
|
||||
it("should create a worker", async function () {
|
||||
it("should create a worker", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient.path("/routing/workers/{workerId}", workerId).patch({
|
||||
contentType: "application/merge-patch+json",
|
||||
body: workerRequest,
|
||||
|
@ -77,9 +79,9 @@ describe("JobRouterClient", function () {
|
|||
assert.isDefined(result);
|
||||
assert.isDefined(result?.id);
|
||||
assert.equal(result.capacity, workerRequest.capacity);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should get a worker", async function () {
|
||||
it("should get a worker", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient.path("/routing/workers/{workerId}", workerId).get();
|
||||
|
||||
if (response.status !== "200") {
|
||||
|
@ -90,9 +92,9 @@ describe("JobRouterClient", function () {
|
|||
assert.equal(result.id, workerId);
|
||||
assert.equal(result.capacity, workerRequest.capacity);
|
||||
assert.deepEqual(result.channels, workerRequest.channels);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should update a worker", async function () {
|
||||
it("should update a worker", { timeout: timeoutMs }, async () => {
|
||||
const updatePatch = {
|
||||
...workerRequest,
|
||||
capacity: 100,
|
||||
|
@ -126,9 +128,9 @@ describe("JobRouterClient", function () {
|
|||
assert.isDefined(removeResult.id);
|
||||
assert.equal(updateResult.capacity, updatePatch.capacity);
|
||||
assert.isEmpty(removeResult.tags);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should register and deregister a worker", async function () {
|
||||
it("should register and deregister a worker", { timeout: timeoutMs }, async () => {
|
||||
const registerPatch = { ...workerRequest, availableForOffers: true };
|
||||
let response = await routerClient.path("/routing/workers/{workerId}", workerId).patch({
|
||||
contentType: "application/merge-patch+json",
|
||||
|
@ -159,9 +161,9 @@ describe("JobRouterClient", function () {
|
|||
assert.isDefined(deregisterResult);
|
||||
assert.isDefined(deregisterResult?.id);
|
||||
assert.equal(deregisterResult.availableForOffers, false);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should list workers", async function () {
|
||||
it("should list workers", { timeout: timeoutMs }, async () => {
|
||||
const result: RouterWorkerOutput[] = [];
|
||||
const response = await routerClient
|
||||
.path("/routing/workers")
|
||||
|
@ -178,9 +180,9 @@ describe("JobRouterClient", function () {
|
|||
}
|
||||
|
||||
assert.isNotEmpty(result);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
|
||||
it("should delete a worker", async function () {
|
||||
it("should delete a worker", { timeout: timeoutMs }, async () => {
|
||||
const response = await routerClient.path("/routing/workers/{workerId}", workerId).delete();
|
||||
|
||||
if (response.status !== "204") {
|
||||
|
@ -188,6 +190,6 @@ describe("JobRouterClient", function () {
|
|||
}
|
||||
|
||||
assert.isDefined(response);
|
||||
}).timeout(timeoutMs);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import type { Recorder } from "@azure-tools/test-recorder";
|
||||
import { assert } from "chai";
|
||||
import { createRecorder } from "./utils/recordedClient";
|
||||
import type { Context } from "mocha";
|
||||
|
||||
describe("My test", () => {
|
||||
let recorder: Recorder;
|
||||
|
||||
beforeEach(async function (this: Context) {
|
||||
recorder = await createRecorder(this);
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
await recorder.stop();
|
||||
});
|
||||
|
||||
it("sample test", async function () {
|
||||
assert.equal(1, 1);
|
||||
});
|
||||
});
|
|
@ -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";
|
||||
|
||||
|
@ -11,6 +11,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`;
|
||||
};
|
||||
|
|
|
@ -1,32 +1,11 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import type { AzureCommunicationRoutingServiceClient, RouterJobOutput } from "../../../src";
|
||||
import type { RouterJob } from "../../../src";
|
||||
|
||||
// export async function pollForJobOffer(
|
||||
// workerId: string,
|
||||
// client: JobRouterClient
|
||||
// ): Promise<RouterJobOffer> {
|
||||
// let worker: RouterWorker = {};
|
||||
// while (worker.offers?.length === undefined || worker.offers.length < 1) {
|
||||
// worker = await client.getWorker(workerId);
|
||||
// }
|
||||
//
|
||||
// return worker.offers[0];
|
||||
// }
|
||||
//
|
||||
// export async function pollForJobAssignment(
|
||||
// jobId: string,
|
||||
// client: JobRouterClient
|
||||
// ): Promise<RouterJobAssignment> {
|
||||
// let job: RouterJob = {};
|
||||
// while (job.assignments === undefined || Object.keys(job.assignments).length < 1) {
|
||||
// job = await client.getJob(jobId);
|
||||
// }
|
||||
//
|
||||
// return Object.values(job.assignments)[0];
|
||||
// }
|
||||
import type {
|
||||
AzureCommunicationRoutingServiceClient,
|
||||
RouterJobOutput,
|
||||
} from "../../../src/index.js";
|
||||
import type { RouterJob } from "../../../src/index.js";
|
||||
|
||||
export async function pollForJobQueued(
|
||||
jobId: string,
|
||||
|
@ -47,18 +26,6 @@ export async function pollForJobQueued(
|
|||
return job;
|
||||
}
|
||||
|
||||
// export async function pollForJobCancelled(
|
||||
// jobId: string,
|
||||
// client: JobRouterClient
|
||||
// ): Promise<RouterJob> {
|
||||
// let job: RouterJob = {};
|
||||
// while (job.status !== "cancelled") {
|
||||
// job = await client.getJob(jobId);
|
||||
// }
|
||||
//
|
||||
// return job;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Runs the function `fn`
|
||||
* and retries automatically if it fails.
|
||||
|
@ -72,7 +39,7 @@ export const retry = async <T>(
|
|||
fn: () => Promise<T> | T,
|
||||
{ retries, retryIntervalMs }: { retries: number; retryIntervalMs: number },
|
||||
): Promise<T> => {
|
||||
const sleep = (ms = 0) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
const sleep = (ms = 0): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
try {
|
||||
return await fn();
|
||||
} catch (error) {
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import type { Context } from "mocha";
|
||||
import type { RecorderStartOptions } from "@azure-tools/test-recorder";
|
||||
import type { RecorderStartOptions, TestInfo } from "@azure-tools/test-recorder";
|
||||
import { Recorder } from "@azure-tools/test-recorder";
|
||||
import "./env";
|
||||
import "./env.js";
|
||||
|
||||
const envSetupForPlayback: Record<string, string> = {
|
||||
ENDPOINT: "https://endpoint",
|
||||
|
@ -27,8 +25,8 @@ const recorderEnvSetup: RecorderStartOptions = {
|
|||
* Should be called first in the test suite to make sure environment variables are
|
||||
* read before they are being used.
|
||||
*/
|
||||
export async function createRecorder(context: Context): Promise<Recorder> {
|
||||
const recorder = new Recorder(context.currentTest);
|
||||
export async function createRecorder(context: TestInfo): Promise<Recorder> {
|
||||
const recorder = new Recorder(context);
|
||||
await recorder.start(recorderEnvSetup);
|
||||
return recorder;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import type {
|
|||
RouterWorker,
|
||||
StaticQueueSelectorAttachment,
|
||||
RouterJob,
|
||||
} from "../../../src";
|
||||
} from "../../../src/index.js";
|
||||
|
||||
const queueId = "test-a-queue";
|
||||
const exceptionPolicyId = "test-e-policy";
|
||||
|
|
|
@ -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,5 +1,17 @@
|
|||
{
|
||||
"extends": "../../../tsconfig",
|
||||
"compilerOptions": { "outDir": "./dist-esm", "declarationDir": "./types" },
|
||||
"include": ["src/**/*.ts", "./test/**/*.ts"]
|
||||
"compilerOptions": {
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"rootDir": "."
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.mts",
|
||||
"src/**/*.cts",
|
||||
"samples-dev/**/*.ts",
|
||||
"test/**/*.ts",
|
||||
"test/**/*.mts",
|
||||
"test/**/*.cts"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import { defineConfig, mergeConfig } from "vitest/config";
|
||||
import viteConfig from "../../../vitest.browser.shared.config.ts";
|
||||
|
||||
export default mergeConfig(
|
||||
viteConfig,
|
||||
defineConfig({
|
||||
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,
|
||||
},
|
||||
}),
|
||||
);
|
Загрузка…
Ссылка в новой задаче