Skip to content

Commit 9ecbb85

Browse files
fix: comm-chat: remove mocha arrow functions (Azure#24127)
### Packages impacted by this PR `sdk\communication\communication-chat` ### Issues associated with this PR #13005 ### Describe the problem that is addressed by this PR The existing mocha tests for the `sdk\communication\communication-chat` made use of the arrow syntax for callback functions. Mocha recommends not to do this because you lose access to the mocha context (https://mochajs.org/#arrow-functions). ### 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? The reason for utilizing the function keyword instead of an arrow syntax to write the callback functions in these mocha tests is to maintain access to the mocha context. ### Are there test cases added in this PR? _(If not, why?)_ No additional test cases were added in this PR as the change only required modifying existing test cases. ### Provide a list of related PRs _(if any)_ Azure#23761 - Same fix, but for the `sdk\search\search-documents` package Azure#23789 - Same fix but for the `sdk\attestation\attestation` package Azure#23835 - Same fix but for the `sdk\batch\batch` package Azure#23850 - Same fix but for the `sdk\cognitivelanguage\ai-language-conversations` package Azure#23881 - Same fix but for the `sdk\cognitiveservices\cognitiveservices-luis-authoring` Azure#24126 - Same fix but for the `sdk\cognitiveservices\cognitiveservices-luis-runtime` ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ **_Not applicable_** ### Checklists - [x] 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)_ - **_I don't believe this is relevant._** - [ ] Added a changelog (if necessary) - **_I don't believe this is necessary_**
1 parent 87463eb commit 9ecbb85

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

sdk/communication/communication-chat/test/internal/chatClient.mocked.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ import {
2121

2222
const API_VERSION = apiVersion.mapper.defaultValue;
2323

24-
describe("[Mocked] ChatClient", async () => {
24+
describe("[Mocked] ChatClient", async function () {
2525
let chatClient: ChatClient;
2626

27-
afterEach(() => {
27+
afterEach(function () {
2828
sinon.restore();
2929
});
3030

31-
it("can instantiate", async () => {
31+
it("can instantiate", async function () {
3232
new ChatClient(baseUri, new AzureCommunicationTokenCredential(generateToken()));
3333
});
3434

35-
it("makes successful create thread request", async () => {
35+
it("makes successful create thread request", async function () {
3636
const mockHttpClient = generateHttpClient(201, mockCreateThreadResult);
3737

3838
chatClient = createChatClient(mockHttpClient);
@@ -63,7 +63,7 @@ describe("[Mocked] ChatClient", async () => {
6363
assert.isNotEmpty(request.headers.get("repeatability-request-id"));
6464
});
6565

66-
it("makes successful list threads request", async () => {
66+
it("makes successful list threads request", async function () {
6767
const mockResponse: RestModel.ChatThreadsItemCollection = {
6868
value: [mockThreadItem, mockThreadItem],
6969
};
@@ -87,7 +87,7 @@ describe("[Mocked] ChatClient", async () => {
8787
assert.equal(request.method, "GET");
8888
});
8989

90-
it("makes successful delete thread request", async () => {
90+
it("makes successful delete thread request", async function () {
9191
const mockHttpClient = generateHttpClient(204);
9292
chatClient = createChatClient(mockHttpClient);
9393
const spy = sinon.spy(mockHttpClient, "sendRequest");

sdk/communication/communication-chat/test/internal/chatThreadClient.mocked.spec.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ import {
2929

3030
const API_VERSION = apiVersion.mapper.defaultValue;
3131

32-
describe("[Mocked] ChatThreadClient", async () => {
32+
describe("[Mocked] ChatThreadClient", async function () {
3333
const threadId: string = "threadId";
3434
let chatThreadClient: ChatThreadClient;
3535

36-
afterEach(() => {
36+
afterEach(function () {
3737
sinon.restore();
3838
});
3939

40-
it("can instantiate", async () => {
40+
it("can instantiate", async function () {
4141
new ChatThreadClient(threadId, baseUri, new AzureCommunicationTokenCredential(generateToken()));
4242
});
4343

44-
it("makes successful get properties request", async () => {
44+
it("makes successful get properties request", async function () {
4545
const mockHttpClient = generateHttpClient(200, mockThread);
4646
chatThreadClient = createChatThreadClient(mockThread.id, mockHttpClient);
4747

@@ -68,7 +68,7 @@ describe("[Mocked] ChatThreadClient", async () => {
6868
assert.equal(request.method, "GET");
6969
});
7070

71-
it("makes successful update thread topic", async () => {
71+
it("makes successful update thread topic", async function () {
7272
const mockHttpClient = generateHttpClient(204);
7373
chatThreadClient = createChatThreadClient(threadId, mockHttpClient);
7474

@@ -85,7 +85,7 @@ describe("[Mocked] ChatThreadClient", async () => {
8585
assert.deepEqual(JSON.parse(request.body as string), { topic: topic });
8686
});
8787

88-
it("makes successful send message request", async () => {
88+
it("makes successful send message request", async function () {
8989
const mockHttpClient = generateHttpClient(201, {
9090
id: mockMessage.id,
9191
});
@@ -119,7 +119,7 @@ describe("[Mocked] ChatThreadClient", async () => {
119119
});
120120
});
121121

122-
it("makes successful get message request", async () => {
122+
it("makes successful get message request", async function () {
123123
const mockHttpClient = generateHttpClient(200, mockMessage);
124124
chatThreadClient = createChatThreadClient(threadId, mockHttpClient);
125125
const spy = sinon.spy(mockHttpClient, "sendRequest");
@@ -155,7 +155,7 @@ describe("[Mocked] ChatThreadClient", async () => {
155155
assert.equal(request.method, "GET");
156156
});
157157

158-
it("makes successful list messages request", async () => {
158+
it("makes successful list messages request", async function () {
159159
const { senderCommunicationIdentifier, ...rest } = mockMessage;
160160

161161
const mockResponse: RestModel.ChatMessagesCollection = {
@@ -205,7 +205,7 @@ describe("[Mocked] ChatThreadClient", async () => {
205205
assert.equal(request.method, "GET");
206206
});
207207

208-
it("makes successful update message request", async () => {
208+
it("makes successful update message request", async function () {
209209
const mockHttpClient = generateHttpClient(204);
210210
chatThreadClient = createChatThreadClient(threadId, mockHttpClient);
211211
const spy = sinon.spy(mockHttpClient, "sendRequest");
@@ -230,7 +230,7 @@ describe("[Mocked] ChatThreadClient", async () => {
230230
});
231231
});
232232

233-
it("makes successful delete message request", async () => {
233+
it("makes successful delete message request", async function () {
234234
const mockHttpClient = generateHttpClient(204);
235235
chatThreadClient = createChatThreadClient(threadId, mockHttpClient);
236236
const spy = sinon.spy(mockHttpClient, "sendRequest");
@@ -246,7 +246,7 @@ describe("[Mocked] ChatThreadClient", async () => {
246246
assert.equal(request.method, "DELETE");
247247
});
248248

249-
it("makes successful add chat participants request", async () => {
249+
it("makes successful add chat participants request", async function () {
250250
const mockHttpClient = generateHttpClient(201);
251251
chatThreadClient = createChatThreadClient(threadId, mockHttpClient);
252252
const spy = sinon.spy(mockHttpClient, "sendRequest");
@@ -277,7 +277,7 @@ describe("[Mocked] ChatThreadClient", async () => {
277277
);
278278
});
279279

280-
it("makes successful list chat participants request", async () => {
280+
it("makes successful list chat participants request", async function () {
281281
const mockHttpClient = generateHttpClient(200, {
282282
value: [mockParticipant],
283283
});
@@ -309,7 +309,7 @@ describe("[Mocked] ChatThreadClient", async () => {
309309
assert.equal(request.method, "GET");
310310
});
311311

312-
it("makes successful remove chat participant request", async () => {
312+
it("makes successful remove chat participant request", async function () {
313313
const mockHttpClient = generateHttpClient(204);
314314
chatThreadClient = createChatThreadClient(threadId, mockHttpClient);
315315
const spy = sinon.spy(mockHttpClient, "sendRequest");
@@ -327,7 +327,7 @@ describe("[Mocked] ChatThreadClient", async () => {
327327
assert.deepEqual(mockParticipant.communicationIdentifier, requestJson);
328328
});
329329

330-
it("makes successful sent typing notification request", async () => {
330+
it("makes successful sent typing notification request", async function () {
331331
const mockHttpClient = generateHttpClient(200);
332332
chatThreadClient = createChatThreadClient(threadId, mockHttpClient);
333333
const spy = sinon.spy(mockHttpClient, "sendRequest");
@@ -344,7 +344,7 @@ describe("[Mocked] ChatThreadClient", async () => {
344344
assert.equal(request.method, "POST");
345345
});
346346

347-
it("makes only one sent typing notification request within 8 secs", async () => {
347+
it("makes only one sent typing notification request within 8 secs", async function () {
348348
const mockHttpClient = generateHttpClient(400);
349349
chatThreadClient = createChatThreadClient(threadId, mockHttpClient);
350350
const spy = sinon.spy(mockHttpClient, "sendRequest");
@@ -368,7 +368,7 @@ describe("[Mocked] ChatThreadClient", async () => {
368368
}
369369
});
370370

371-
it("makes successful sent typing notification request with sender display name", async () => {
371+
it("makes successful sent typing notification request with sender display name", async function () {
372372
const mockHttpClient = generateHttpClient(200);
373373
chatThreadClient = createChatThreadClient(threadId, mockHttpClient);
374374
const spy = sinon.spy(mockHttpClient, "sendRequest");
@@ -387,7 +387,7 @@ describe("[Mocked] ChatThreadClient", async () => {
387387
assert.deepEqual(JSON.parse(request.body as string), options);
388388
});
389389

390-
it("makes successful sent read receipt request", async () => {
390+
it("makes successful sent read receipt request", async function () {
391391
const mockHttpClient = generateHttpClient(200);
392392
chatThreadClient = createChatThreadClient(threadId, mockHttpClient);
393393
const spy = sinon.spy(mockHttpClient, "sendRequest");
@@ -403,7 +403,7 @@ describe("[Mocked] ChatThreadClient", async () => {
403403
assert.equal(request.method, "POST");
404404
});
405405

406-
it("makes successful list read receipts request", async () => {
406+
it("makes successful list read receipts request", async function () {
407407
const mockHttpClient = generateHttpClient(200, {
408408
value: [mockChatMessageReadReceipt, mockChatMessageReadReceipt],
409409
});

0 commit comments

Comments
 (0)