Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Test Setup #25051

Merged
merged 2 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions sdk/communication/communication-call-automation/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
@@ -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> & CallAutomationClient;

beforeEach(() => {
// set up
targets = [{
communicationUserId: CALL_TARGET_ID
}];
// stub CallAutomationClient
client = Sinon.createStubInstance(CallAutomationClient) as SinonStubbedInstance<CallAutomationClient> & 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
});
});

})
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down