Skip to content

Commit

Permalink
Unit Test Setup (#25051)
Browse files Browse the repository at this point in the history
- setting up first unit test using chai/sinon
- adding ESLint config for VSCode

### Packages impacted by this PR

### Issues associated with this PR

### Describe the problem that is addressed by this PR

### 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)
  • Loading branch information
edwardho-ms authored and minwoolee-msft committed Mar 7, 2023
1 parent 208f9b8 commit 0b2e7a8
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
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

0 comments on commit 0b2e7a8

Please sign in to comment.