diff --git a/sdk/communication/communication-call-automation/.eslintrc.json b/sdk/communication/communication-call-automation/.eslintrc.json index a33aa33c57d9..c840cf82f893 100644 --- a/sdk/communication/communication-call-automation/.eslintrc.json +++ b/sdk/communication/communication-call-automation/.eslintrc.json @@ -1,8 +1,13 @@ { - "plugins": ["@azure/azure-sdk"], - "extends": ["plugin:@azure/azure-sdk/azure-sdk-base"], + "plugins": [ + "@azure/azure-sdk" + ], + "extends": [ + "plugin:@azure/azure-sdk/azure-sdk-base", + "typescript" + ], "rules": { // Removing `src` would be a breaking change so leaving it for the package owners to address "@azure/azure-sdk/ts-package-json-files-required": "warn" } -} +} \ No newline at end of file diff --git a/sdk/communication/communication-call-automation/test/public/callAutomationClient.spec.ts b/sdk/communication/communication-call-automation/test/public/callAutomationClient.spec.ts index fd2aca680c7b..993234234b71 100644 --- a/sdk/communication/communication-call-automation/test/public/callAutomationClient.spec.ts +++ b/sdk/communication/communication-call-automation/test/public/callAutomationClient.spec.ts @@ -1,2 +1,50 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. + +import { CommunicationIdentifier } from "@azure/communication-common"; +import { fail } from "assert"; +import { assert } from "chai"; +import Sinon, { SinonStubbedInstance } from "sinon"; +import { CallAutomationClient } from "../../src/callAutomationClient"; +import { CallConnection } from "../../src/callConnection"; +import { CallConnectionProperties } from "../../src/models/models"; +import { CreateCallResult } from "../../src/models/responses"; +import { CALL_CALLBACK_URL, CALL_TARGET_ID } from "./utils/connectionUtils"; + +describe("Call Automation Client Unit Tests", () => { + var targets: CommunicationIdentifier[]; + var client: SinonStubbedInstance & CallAutomationClient; + + beforeEach(() => { + // set up + targets = [{ + communicationUserId: CALL_TARGET_ID + }]; + // stub CallAutomationClient + client = Sinon.createStubInstance(CallAutomationClient) as SinonStubbedInstance & CallAutomationClient; + }); + + it("CreateCall", async () => { + + // mocks + const createCallResultMock: CreateCallResult = { + callConnectionProperties: {} as CallConnectionProperties, + callConnection: {} as CallConnection + }; + client.createCall.returns(new Promise((resolve) => { + resolve(createCallResultMock); + })); + + var promiseResult = client.createCall(targets, CALL_CALLBACK_URL); + + // asserts + promiseResult.then((result: CreateCallResult) => { + assert.isNotNull(result); + assert.isTrue(client.createCall.calledWith(targets, CALL_CALLBACK_URL)); + assert.equal(result, createCallResultMock); + }).catch((reject) => { + fail(reject); // should not reach here + }); + }); + +}) diff --git a/sdk/communication/communication-call-automation/test/public/utils/connectionUtils.ts b/sdk/communication/communication-call-automation/test/public/utils/connectionUtils.ts index 829a6230cfdb..1464b139e494 100644 --- a/sdk/communication/communication-call-automation/test/public/utils/connectionUtils.ts +++ b/sdk/communication/communication-call-automation/test/public/utils/connectionUtils.ts @@ -5,6 +5,20 @@ import { isNode } from "@azure/core-util"; export const baseUri = "https://contoso.api.fake"; +export const MOCK_ENDPOINT = "https://REDACTED.communication.azure.com/"; +export const MOCK_CONNECTION_STRING = `endpoint=${MOCK_ENDPOINT};accesskey=eyJhbG`; +export const CALL_CONNECTION_ID = "callConnectionId"; +export const CALL_SERVER_CALL_ID = "serverCallId"; +export const CALL_CALLER_ID = "callerId"; +export const CALL_CALLER_DISPLAY_NAME = "callerDisplayName"; +export const CALL_TARGET_ID = "targetId"; +export const CALL_CONNECTION_STATE = "connected"; +export const CALL_SUBJECT = "subject"; +export const CALL_CALLBACK_URL = "https://REDACTED.com/events"; +export const CALL_INCOMING_CALL_CONTEXT = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.REDACTED"; +export const CALL_OPERATION_CONTEXT = "operationContext"; +export const MEDIA_SUBSCRIPTION_ID = "mediaSubscriptionId"; + declare function btoa(stringToEncode: string): string; export const generateToken = (): string => {