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

fix: communication-sms: remove mocha arrow functions #26659

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
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import { HttpClient } from "@azure/core-rest-pipeline";

import { Uuid } from "../../src/utils/uuid";
import { generateSendMessageRequest } from "../../src/utils/smsUtils";
import { Uuid } from "../../src/utils/uuid";

import { assert } from "chai";
import sinon from "sinon";
Expand All @@ -15,7 +15,7 @@ import { MockHttpClient } from "../public/utils/mockHttpClient";
const API_VERSION = apiVersion.mapper.defaultValue;
const TEST_NUMBER = "+14255550123";

describe("[mocked] SmsClient Internal", async () => {
describe("[mocked] SmsClient Internal", async function () {
const baseUri = "https://contoso.api.fake";
const connectionString = `endpoint=${baseUri};accesskey=banana`;
let sendRequestSpy: sinon.SinonSpy;
Expand All @@ -29,17 +29,17 @@ describe("[mocked] SmsClient Internal", async () => {
message: "message",
};

describe("when sending an SMS", () => {
describe("when sending an SMS", function () {
let smsClient: SmsClient;
beforeEach(() => {
beforeEach(function () {
uuidStub = sinon.stub(Uuid, "generateUuid");
uuidStub.returns(mockedGuid);
sendRequestSpy = sinon.spy(mockHttpClient, "sendRequest");
sinon.useFakeTimers();
smsClient = new SmsClient(connectionString, { httpClient: mockHttpClient });
});

it("sends with the correct request body", async () => {
it("sends with the correct request body", async function () {
await smsClient.send(testSendRequest);

const request = sendRequestSpy.getCall(0).args[0];
Expand All @@ -49,14 +49,14 @@ describe("[mocked] SmsClient Internal", async () => {
assert.deepEqual(JSON.parse(request.body as string), expectedRequestBody);
});

it("generates a new repeatability id each time", async () => {
it("generates a new repeatability id each time", async function () {
await smsClient.send(testSendRequest);
assert.isTrue(uuidStub.calledOnce);
await smsClient.send(testSendRequest);
assert.isTrue(uuidStub.calledTwice);
});

afterEach(() => {
afterEach(function () {
sinon.restore();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
* These tests will be skipped in Live Mode since the public tests run in live mode only.
*/

import { matrix } from "@azure/test-utils";
import { Recorder, isLiveMode, isPlaybackMode } from "@azure-tools/test-recorder";
import { matrix } from "@azure/test-utils";
import { Context } from "mocha";
import * as sinon from "sinon";
import { SmsClient } from "../../src";
import { Uuid } from "../../src/utils/uuid";
import sendSmsSuites from "../public/suites/smsClient.send";
import {
createRecordedSmsClient,
createRecordedSmsClientWithToken,
} from "../public/utils/recordedClient";
import { Context } from "mocha";
import sendSmsSuites from "../public/suites/smsClient.send";
import { SmsClient } from "../../src";

matrix([[true, false]], async function (useAad: boolean) {
describe(`SmsClient [Playback/Record]${useAad ? " [AAD]" : ""}`, async () => {
describe(`SmsClient [Playback/Record]${useAad ? " [AAD]" : ""}`, async function () {
let recorder: Recorder;
let client: SmsClient;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { isNode } from "@azure/core-util";
import { HttpClient } from "@azure/core-rest-pipeline";
import { AzureKeyCredential } from "@azure/core-auth";
import { HttpClient } from "@azure/core-rest-pipeline";
import { isNode } from "@azure/core-util";
import { TokenCredential } from "@azure/identity";
import { assert } from "chai";
import sinon from "sinon";
import { SmsClient, SmsClientOptions, SmsSendRequest } from "../../src";
import { MockHttpClient } from "./utils/mockHttpClient";
import { TokenCredential } from "@azure/identity";

const TEST_NUMBER = "+14255550123";

describe("[mocked] SmsClient", async () => {
describe("[mocked] SmsClient", async function () {
const baseUri = "https://contoso.api.fake";
const connectionString = `endpoint=${baseUri};accesskey=banana`;
const dateHeader = "x-ms-date";
Expand All @@ -25,16 +25,16 @@ describe("[mocked] SmsClient", async () => {
message: "message",
};

describe("when instantiating SMS client", () => {
it("can instantiate with a connection string", async () => {
describe("when instantiating SMS client", function () {
it("can instantiate with a connection string", async function () {
new SmsClient(connectionString);
});

it("can instantiate with a url and KeyCredential ", async () => {
it("can instantiate with a url and KeyCredential ", async function () {
new SmsClient(baseUri, new AzureKeyCredential("banana"));
});

it("can instantiate with a token", async () => {
it("can instantiate with a token", async function () {
const fakeToken: TokenCredential = {
getToken: async (_scopes) => {
return { token: "testToken", expiresOnTimestamp: 11111 };
Expand All @@ -44,9 +44,9 @@ describe("[mocked] SmsClient", async () => {
});
});

describe("when sending an SMS", () => {
describe("when sending an SMS", function () {
let smsClient: SmsClient;
beforeEach(() => {
beforeEach(function () {
sendRequestSpy = sinon.spy(mockHttpClient, "sendRequest");
sinon.useFakeTimers();
// workaround: casting because min testing has issues with httpClient newer versions having extra optional fields
Expand All @@ -55,7 +55,7 @@ describe("[mocked] SmsClient", async () => {
} as SmsClientOptions);
});

it("sends with the correct headers", async () => {
it("sends with the correct headers", async function () {
await smsClient.send(testSendRequest);

const request = sendRequestSpy.getCall(0).args[0];
Expand All @@ -70,7 +70,7 @@ describe("[mocked] SmsClient", async () => {
);
});

it("returns the correct results", async () => {
it("returns the correct results", async function () {
const smsTestResults = await smsClient.send(testSendRequest);

const smsTestResult = smsTestResults[0];
Expand All @@ -79,7 +79,7 @@ describe("[mocked] SmsClient", async () => {
assert.equal(smsTestResult.messageId, "id");
});

afterEach(() => {
afterEach(function () {
sinon.restore();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
* They are duplicated in an internal test which contains workaround logic to record/playback the tests
*/

import { matrix } from "@azure/test-utils";
import { Recorder, env, isPlaybackMode } from "@azure-tools/test-recorder";
import { createRecordedSmsClient, createRecordedSmsClientWithToken } from "./utils/recordedClient";
import { matrix } from "@azure/test-utils";
import { Context } from "mocha";
import sendSmsSuites from "./suites/smsClient.send";
import { SmsClient } from "../../src";
import sinon from "sinon";
import { SmsClient } from "../../src";
import { Uuid } from "../../src/utils/uuid";
import sendSmsSuites from "./suites/smsClient.send";
import { createRecordedSmsClient, createRecordedSmsClientWithToken } from "./utils/recordedClient";

matrix([[true, false]], async function (useAad: boolean) {
describe(`SmsClient [Live]${useAad ? " [AAD]" : ""}`, async () => {
describe(`SmsClient [Live]${useAad ? " [AAD]" : ""}`, async function () {
let recorder: Recorder;
let client: SmsClient;

Expand Down