From 29afe14ced16257dafc278e8612b8e5df9795cff Mon Sep 17 00:00:00 2001 From: Jiri Burant <83883278+jiriburant@users.noreply.github.com> Date: Fri, 24 Feb 2023 13:33:06 +0100 Subject: [PATCH] =?UTF-8?q?Modified=20public=20interface,=20instead=20of?= =?UTF-8?q?=20getRoutes/trunks=20use=20listTrunks=E2=80=A6=20(#24918)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Packages impacted by this PR Communication Phone-Numbers ### Issues associated with this PR https://skype.visualstudio.com/SPOOL/_workitems/edit/3149585/ ### Describe the problem that is addressed by this PR On the latest Internal Board Review, we got the feedback to change naming of functions retrieving the trunks and routes from "get" to "list". This PR aims to solve this. We don't provide options to set page size or skip, because: 1) The collections returned by ListTrunks and ListRoutes are short (usually 1~5 items), bigger collections don't make sense from use case perspective. 2) Underlying API doesnt support paging, therefore no cost would be saved with setting the page size. ### 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) --------- Co-authored-by: Petr Švihlík --- .../communication-phone-numbers/CHANGELOG.md | 1 + .../review/communication-phone-numbers.api.md | 12 +- .../siprouting/getSipRoutingConfiguration.ts | 8 +- .../manageSipRoutingConfiguration.ts | 8 +- .../communication-phone-numbers/src/models.ts | 10 ++ .../src/sipRoutingClient.ts | 118 +++++++++++++++--- .../test/internal/siprouting/headers.spec.ts | 12 +- .../public/siprouting/deleteTrunk.spec.ts | 9 +- .../test/public/siprouting/getRoutes.spec.ts | 9 +- .../test/public/siprouting/getTrunks.spec.ts | 9 +- .../test/public/siprouting/setRoutes.spec.ts | 28 +++-- .../test/public/siprouting/setTrunks.spec.ts | 18 +-- .../public/siprouting/utils/recordedClient.ts | 27 +++- 13 files changed, 203 insertions(+), 66 deletions(-) diff --git a/sdk/communication/communication-phone-numbers/CHANGELOG.md b/sdk/communication/communication-phone-numbers/CHANGELOG.md index 17a10dfa134d..e4ff4a5c1439 100644 --- a/sdk/communication/communication-phone-numbers/CHANGELOG.md +++ b/sdk/communication/communication-phone-numbers/CHANGELOG.md @@ -5,6 +5,7 @@ ### Features Added ### Breaking Changes +- Changed public methods `getTrunks` to `listTrunks` and `getRoutes` to `listRoutes`. ### Bugs Fixed diff --git a/sdk/communication/communication-phone-numbers/review/communication-phone-numbers.api.md b/sdk/communication/communication-phone-numbers/review/communication-phone-numbers.api.md index 9c6fb994ce88..229be0c26921 100644 --- a/sdk/communication/communication-phone-numbers/review/communication-phone-numbers.api.md +++ b/sdk/communication/communication-phone-numbers/review/communication-phone-numbers.api.md @@ -60,6 +60,14 @@ export interface ListOfferingsOptions extends OperationOptions { export interface ListPurchasedPhoneNumbersOptions extends OperationOptions { } +// @public +export interface ListSipRoutesOptions extends OperationOptions { +} + +// @public +export interface ListSipTrunksOptions extends OperationOptions { +} + // @public export interface ListTollFreeAreaCodesOptions extends Omit { } @@ -207,9 +215,9 @@ export class SipRoutingClient { constructor(endpoint: string, credential: KeyCredential, options?: SipRoutingClientOptions); constructor(endpoint: string, credential: TokenCredential, options?: SipRoutingClientOptions); deleteTrunk(fqdn: string, options?: OperationOptions): Promise; - getRoutes(options?: OperationOptions): Promise; getTrunk(fqdn: string, options?: OperationOptions): Promise; - getTrunks(options?: OperationOptions): Promise; + listRoutes(options?: ListSipRoutesOptions): PagedAsyncIterableIterator; + listTrunks(options?: ListSipTrunksOptions): PagedAsyncIterableIterator; setRoutes(routes: SipTrunkRoute[], options?: OperationOptions): Promise; setTrunk(trunk: SipTrunk, options?: OperationOptions): Promise; setTrunks(trunks: SipTrunk[], options?: OperationOptions): Promise; diff --git a/sdk/communication/communication-phone-numbers/samples-dev/siprouting/getSipRoutingConfiguration.ts b/sdk/communication/communication-phone-numbers/samples-dev/siprouting/getSipRoutingConfiguration.ts index 2653091ecd5b..36b2f4742765 100644 --- a/sdk/communication/communication-phone-numbers/samples-dev/siprouting/getSipRoutingConfiguration.ts +++ b/sdk/communication/communication-phone-numbers/samples-dev/siprouting/getSipRoutingConfiguration.ts @@ -17,14 +17,14 @@ export async function main() { const client = new SipRoutingClient(connectionString); // Get trunks - const trunks = await client.getTrunks(); - for (const trunk of trunks) { + const trunks = await client.listTrunks(); + for await (const trunk of trunks) { console.log(`Trunk ${trunk.fqdn}:${trunk.sipSignalingPort}`); } // Get routes - const routes = await client.getRoutes(); - for (const route of routes) { + const routes = await client.listRoutes(); + for await (const route of routes) { console.log(`Route ${route.name} with pattern ${route.numberPattern}`); console.log(`Route's trunks: ${route.trunks?.join()}`); } diff --git a/sdk/communication/communication-phone-numbers/samples-dev/siprouting/manageSipRoutingConfiguration.ts b/sdk/communication/communication-phone-numbers/samples-dev/siprouting/manageSipRoutingConfiguration.ts index 64b18b218bf2..e22d38b1b85d 100644 --- a/sdk/communication/communication-phone-numbers/samples-dev/siprouting/manageSipRoutingConfiguration.ts +++ b/sdk/communication/communication-phone-numbers/samples-dev/siprouting/manageSipRoutingConfiguration.ts @@ -64,14 +64,14 @@ export async function main() { }); // Get trunks - const trunks = await client.getTrunks(); - for (const trunk of trunks) { + const trunks = await client.listTrunks(); + for await (const trunk of trunks) { console.log(`Trunk ${trunk.fqdn}:${trunk.sipSignalingPort}`); } // Get routes - const routes = await client.getRoutes(); - for (const route of routes) { + const routes = await client.listRoutes(); + for await (const route of routes) { console.log(`Route ${route.name} with pattern ${route.numberPattern}`); console.log(`Route's trunks: ${route.trunks?.join()}`); } diff --git a/sdk/communication/communication-phone-numbers/src/models.ts b/sdk/communication/communication-phone-numbers/src/models.ts index 83e3c1d4dda0..195fecdcb925 100644 --- a/sdk/communication/communication-phone-numbers/src/models.ts +++ b/sdk/communication/communication-phone-numbers/src/models.ts @@ -66,6 +66,16 @@ export interface ListLocalitiesOptions extends OperationOptions { administrativeDivision?: string; } +/** + * Additional options that can be passed to list SIP routes. + */ +export interface ListSipRoutesOptions extends OperationOptions {} + +/** + * Additional options that can be passed to list SIP trunks. + */ +export interface ListSipTrunksOptions extends OperationOptions {} + /** * Additional options that can be passed to the available offerings request. */ diff --git a/sdk/communication/communication-phone-numbers/src/sipRoutingClient.ts b/sdk/communication/communication-phone-numbers/src/sipRoutingClient.ts index 531e4f77e7a8..b726f88034c6 100644 --- a/sdk/communication/communication-phone-numbers/src/sipRoutingClient.ts +++ b/sdk/communication/communication-phone-numbers/src/sipRoutingClient.ts @@ -11,10 +11,11 @@ import { InternalPipelineOptions } from "@azure/core-rest-pipeline"; import { logger } from "./utils"; import { SipRoutingClient as SipRoutingGeneratedClient } from "./generated/src/siprouting/sipRoutingClient"; import { SipConfigurationPatch, SipRoutingError } from "./generated/src/siprouting/models"; -import { SipTrunk, SipTrunkRoute } from "./models"; +import { ListSipRoutesOptions, ListSipTrunksOptions, SipTrunk, SipTrunkRoute } from "./models"; import { transformFromRestModel, transformIntoRestModel } from "./mappers"; import { CommonClientOptions, OperationOptions } from "@azure/core-client"; import { tracingClient } from "./generated/src/tracing"; +import { PagedAsyncIterableIterator } from "@azure/core-paging"; export * from "./models"; @@ -99,14 +100,37 @@ export class SipRoutingClient { } /** - * Gets the SIP trunks. + * Lists the SIP trunks. * @param options - The options parameters. */ - public async getTrunks(options: OperationOptions = {}): Promise { - return tracingClient.withSpan("SipRoutingClient-getTrunks", options, async (updatedOptions) => { - const config = await this.client.getSipConfiguration(updatedOptions); - return transformFromRestModel(config.trunks); - }); + public listTrunks(options: ListSipTrunksOptions = {}): PagedAsyncIterableIterator { + const { span, updatedOptions } = tracingClient.startSpan( + "SipRoutingClient-listTrunks", + options + ); + + try { + const iter = this.listTrunksPagingAll({ ...updatedOptions }); + return { + next() { + return iter.next(); + }, + [Symbol.asyncIterator]() { + return this; + }, + byPage: () => { + return this.listTrunksPagingPage({ ...updatedOptions }); + }, + }; + } catch (e: any) { + span.setStatus({ + status: "error", + error: e, + }); + throw e; + } finally { + span.end(); + } } /** @@ -116,25 +140,47 @@ export class SipRoutingClient { */ public async getTrunk(fqdn: string, options: OperationOptions = {}): Promise { return tracingClient.withSpan("SipRoutingClient-getTrunk", options, async (updatedOptions) => { - const trunks = await this.getTrunks(updatedOptions); + const trunks = await this.getTrunksInternal(updatedOptions); const trunk = trunks.find((value: SipTrunk) => value.fqdn === fqdn); if (trunk) { return trunk; } - throw { code: "NotFound", message: "Not Found" } as SipRoutingError; }); } /** - * Gets the SIP trunk routes. + * Lists the SIP trunk routes. * @param options - The options parameters. */ - public async getRoutes(options: OperationOptions = {}): Promise { - return tracingClient.withSpan("SipRoutingClient-getRoutes", options, async (updatedOptions) => { - const config = await this.client.getSipConfiguration(updatedOptions); - return config.routes || []; - }); + public listRoutes(options: ListSipRoutesOptions = {}): PagedAsyncIterableIterator { + const { span, updatedOptions } = tracingClient.startSpan( + "SipRoutingClient-listRoutes", + options + ); + + try { + const iter = this.listRoutesPagingAll({ ...updatedOptions }); + return { + next() { + return iter.next(); + }, + [Symbol.asyncIterator]() { + return this; + }, + byPage: () => { + return this.listRoutesPagingPage({ ...updatedOptions }); + }, + }; + } catch (e: any) { + span.setStatus({ + status: "error", + error: e, + }); + throw e; + } finally { + span.end(); + } } /** @@ -212,7 +258,7 @@ export class SipRoutingClient { ...patch, }; const config = await this.client.patchSipConfiguration(payload); - const storedRoutes = config.routes || (await this.getRoutes(updatedOptions)); + const storedRoutes = config.routes || (await this.getRoutesInternal(updatedOptions)); return storedRoutes; }); } @@ -241,4 +287,44 @@ export class SipRoutingClient { } ); } + + private async getRoutesInternal(options: OperationOptions): Promise { + const config = await this.client.getSipConfiguration(options); + return config.routes || []; + } + + private async getTrunksInternal(options: OperationOptions): Promise { + const config = await this.client.getSipConfiguration(options); + return transformFromRestModel(config.trunks); + } + + private async *listRoutesPagingAll( + options?: ListSipRoutesOptions + ): AsyncIterableIterator { + for await (const page of this.listRoutesPagingPage(options)) { + yield* page; + } + } + + private async *listTrunksPagingAll( + options?: ListSipTrunksOptions + ): AsyncIterableIterator { + for await (const page of this.listTrunksPagingPage(options)) { + yield* page; + } + } + + private async *listTrunksPagingPage( + options: ListSipTrunksOptions = {} + ): AsyncIterableIterator { + const apiResult = await this.getTrunksInternal(options as OperationOptions); + yield apiResult; + } + + private async *listRoutesPagingPage( + options: ListSipRoutesOptions = {} + ): AsyncIterableIterator { + const apiResult = await this.getRoutesInternal(options as OperationOptions); + yield apiResult; + } } diff --git a/sdk/communication/communication-phone-numbers/test/internal/siprouting/headers.spec.ts b/sdk/communication/communication-phone-numbers/test/internal/siprouting/headers.spec.ts index c1c289400c10..7aa00a835117 100644 --- a/sdk/communication/communication-phone-numbers/test/internal/siprouting/headers.spec.ts +++ b/sdk/communication/communication-phone-numbers/test/internal/siprouting/headers.spec.ts @@ -27,7 +27,8 @@ describe("SipRoutingClient - headers", function () { it("calls the spy", async function () { const spy = sinon.spy(getTrunksHttpClient, "sendRequest"); - await client.getTrunks(); + const iter = await client.listTrunks(); + await iter.next(); sinon.assert.calledOnce(spy); request = spy.getCall(0).args[0]; @@ -67,7 +68,8 @@ describe("SipRoutingClient - headers", function () { }); const spy = sinon.spy(getTrunksHttpClient, "sendRequest"); - await client.getTrunks(); + const iter = await client.listTrunks(); + await iter.next(); sinon.assert.calledOnce(spy); request = spy.getCall(0).args[0]; @@ -86,7 +88,8 @@ describe("SipRoutingClient - headers", function () { }); const spy = sinon.spy(getTrunksHttpClient, "sendRequest"); - await client.getTrunks(); + const iter = await client.listTrunks(); + await iter.next(); sinon.assert.calledOnce(spy); request = spy.getCall(0).args[0]; @@ -103,7 +106,8 @@ describe("SipRoutingClient - headers", function () { }); const spy = sinon.spy(getTrunksHttpClient, "sendRequest"); - await client.getTrunks(); + const iter = await client.listTrunks(); + await iter.next(); sinon.assert.calledOnce(spy); request = spy.getCall(0).args[0]; diff --git a/sdk/communication/communication-phone-numbers/test/public/siprouting/deleteTrunk.spec.ts b/sdk/communication/communication-phone-numbers/test/public/siprouting/deleteTrunk.spec.ts index a18750b9d918..64b5ff047888 100644 --- a/sdk/communication/communication-phone-numbers/test/public/siprouting/deleteTrunk.spec.ts +++ b/sdk/communication/communication-phone-numbers/test/public/siprouting/deleteTrunk.spec.ts @@ -6,13 +6,14 @@ import { Context } from "mocha"; import { SipRoutingClient } from "../../../src"; -import { isPlaybackMode, Recorder } from "@azure-tools/test-recorder"; +import { Recorder, isPlaybackMode } from "@azure-tools/test-recorder"; import { SipTrunk } from "../../../src/models"; import { clearSipConfiguration, createRecordedClient, createRecordedClientWithToken, getUniqueFqdn, + listAllTrunks, resetUniqueFqdns, } from "./utils/recordedClient"; import { matrix } from "@azure/test-utils"; @@ -50,11 +51,11 @@ matrix([[true, false]], async function (useAad) { }; const storedTrunk = await client.setTrunk(trunk); assert.deepEqual(storedTrunk, trunk); - assert.exists((await client.getTrunks()).find((value) => value.fqdn === trunk.fqdn)); + assert.exists((await listAllTrunks(client)).find((value) => value.fqdn === trunk.fqdn)); await client.deleteTrunk(testFqdn); - assert.notExists((await client.getTrunks()).find((value) => value.fqdn === trunk.fqdn)); + assert.notExists((await listAllTrunks(client)).find((value) => value.fqdn === trunk.fqdn)); }); it("cannot delete a not existing trunk but succeeds", async () => { @@ -62,7 +63,7 @@ matrix([[true, false]], async function (useAad) { await client.deleteTrunk("notExisting.fqdn.com"); - const storedTrunks = await client.getTrunks(); + const storedTrunks = await listAllTrunks(client); assert.isNotNull(storedTrunks); assert.isArray(storedTrunks); assert.isEmpty(storedTrunks); diff --git a/sdk/communication/communication-phone-numbers/test/public/siprouting/getRoutes.spec.ts b/sdk/communication/communication-phone-numbers/test/public/siprouting/getRoutes.spec.ts index d68a6ef4b76e..4b9c9b181390 100644 --- a/sdk/communication/communication-phone-numbers/test/public/siprouting/getRoutes.spec.ts +++ b/sdk/communication/communication-phone-numbers/test/public/siprouting/getRoutes.spec.ts @@ -7,11 +7,12 @@ import { Context } from "mocha"; import { SipRoutingClient } from "../../../src"; import { matrix } from "@azure/test-utils"; -import { isPlaybackMode, Recorder } from "@azure-tools/test-recorder"; +import { Recorder, isPlaybackMode } from "@azure-tools/test-recorder"; import { clearSipConfiguration, createRecordedClient, createRecordedClientWithToken, + listAllRoutes, } from "./utils/recordedClient"; matrix([[true, false]], async function (useAad) { @@ -38,13 +39,13 @@ matrix([[true, false]], async function (useAad) { }); it("can retrieve routes", async () => { - assert.isArray(await client.getRoutes()); + assert.isArray(await listAllRoutes(client)); }); it("can retrieve empty routes", async () => { await client.setRoutes([]); - const routes = await client.getRoutes(); + const routes = await listAllRoutes(client); assert.isNotNull(routes); assert.isArray(routes); @@ -68,7 +69,7 @@ matrix([[true, false]], async function (useAad) { ]; await client.setRoutes(expectedRoutes); - const routes = await client.getRoutes(); + const routes = await listAllRoutes(client); assert.isNotNull(routes); assert.isArray(routes); diff --git a/sdk/communication/communication-phone-numbers/test/public/siprouting/getTrunks.spec.ts b/sdk/communication/communication-phone-numbers/test/public/siprouting/getTrunks.spec.ts index a3be4077b149..651097740f41 100644 --- a/sdk/communication/communication-phone-numbers/test/public/siprouting/getTrunks.spec.ts +++ b/sdk/communication/communication-phone-numbers/test/public/siprouting/getTrunks.spec.ts @@ -6,13 +6,14 @@ import { Context } from "mocha"; import { SipRoutingClient } from "../../../src"; -import { isPlaybackMode, Recorder } from "@azure-tools/test-recorder"; +import { Recorder, isPlaybackMode } from "@azure-tools/test-recorder"; import { SipTrunk } from "../../../src/models"; import { clearSipConfiguration, createRecordedClient, createRecordedClientWithToken, getUniqueFqdn, + listAllTrunks, resetUniqueFqdns, } from "./utils/recordedClient"; import { matrix } from "@azure/test-utils"; @@ -69,13 +70,13 @@ matrix([[true, false]], async function (useAad) { }); it("can retrieve trunks", async () => { - assert.isArray(await client.getTrunks()); + assert.isArray(await listAllTrunks(client)); }); it("can retrieve empty trunks", async () => { await client.setTrunks([]); - const trunks = await client.getTrunks(); + const trunks = await listAllTrunks(client); assert.isNotNull(trunks); assert.isArray(trunks); @@ -90,7 +91,7 @@ matrix([[true, false]], async function (useAad) { ]; await client.setTrunks(expectedTrunks); - const trunks = await client.getTrunks(); + const trunks = await listAllTrunks(client); assert.isNotNull(trunks); assert.isArray(trunks); diff --git a/sdk/communication/communication-phone-numbers/test/public/siprouting/setRoutes.spec.ts b/sdk/communication/communication-phone-numbers/test/public/siprouting/setRoutes.spec.ts index da13a321cce6..a2ee5cbe3900 100644 --- a/sdk/communication/communication-phone-numbers/test/public/siprouting/setRoutes.spec.ts +++ b/sdk/communication/communication-phone-numbers/test/public/siprouting/setRoutes.spec.ts @@ -6,13 +6,15 @@ import { Context } from "mocha"; import { SipRoutingClient } from "../../../src"; -import { isPlaybackMode, Recorder } from "@azure-tools/test-recorder"; +import { Recorder, isPlaybackMode } from "@azure-tools/test-recorder"; import { SipTrunk, SipTrunkRoute } from "../../../src/models"; import { clearSipConfiguration, createRecordedClient, createRecordedClientWithToken, getUniqueFqdn, + listAllRoutes, + listAllTrunks, resetUniqueFqdns, } from "./utils/recordedClient"; import { matrix } from "@azure/test-utils"; @@ -66,7 +68,7 @@ matrix([[true, false]], async function (useAad) { const setRoutes = await client.setRoutes(routes); assert.deepEqual(setRoutes, routes); - const storedRoutes = await client.getRoutes(); + const storedRoutes = await listAllRoutes(client); assert.deepEqual(storedRoutes, routes); }); @@ -99,7 +101,7 @@ matrix([[true, false]], async function (useAad) { const setRoutes = await client.setRoutes(expectedRoutes); assert.deepEqual(setRoutes, expectedRoutes); - const storedRoutes = await client.getRoutes(); + const storedRoutes = await listAllRoutes(client); assert.deepEqual(storedRoutes, expectedRoutes); }); @@ -117,7 +119,7 @@ matrix([[true, false]], async function (useAad) { trunks: [firstFqdn], }; assert.deepEqual(await client.setRoutes([route]), [route]); - assert.deepEqual(await client.getRoutes(), [route]); + assert.deepEqual(await listAllRoutes(client), [route]); }); it("can set empty routes when empty before", async () => { @@ -125,7 +127,7 @@ matrix([[true, false]], async function (useAad) { await client.setRoutes([]); - const storedRoutes = await client.getRoutes(); + const storedRoutes = await listAllRoutes(client); assert.isNotNull(storedRoutes); assert.isArray(storedRoutes); assert.isEmpty(storedRoutes); @@ -150,7 +152,7 @@ matrix([[true, false]], async function (useAad) { await client.setRoutes([]); - const storedRoutes = await client.getRoutes(); + const storedRoutes = await listAllRoutes(client); assert.isNotNull(storedRoutes); assert.isArray(storedRoutes); assert.isEmpty(storedRoutes); @@ -167,7 +169,7 @@ matrix([[true, false]], async function (useAad) { await client.setRoutes([invalidRoute]); } catch (error: any) { assert.equal(error.code, "UnprocessableConfiguration"); - const storedRoutes = await client.getRoutes(); + const storedRoutes = await listAllRoutes(client); assert.isUndefined(storedRoutes.find((item) => item.name === "")); return; } @@ -184,7 +186,7 @@ matrix([[true, false]], async function (useAad) { await client.setRoutes([invalidRoute]); } catch (error: any) { assert.equal(error.code, "UnprocessableConfiguration"); - const storedRoutes = await client.getRoutes(); + const storedRoutes = await listAllRoutes(client); assert.isUndefined(storedRoutes.find((item) => item.name === "invalidNumberPatternRoute")); return; } @@ -207,7 +209,7 @@ matrix([[true, false]], async function (useAad) { await client.setRoutes(invalidRoutes); } catch (error: any) { assert.equal(error.code, "UnprocessableConfiguration"); - const storedRoutes = await client.getRoutes(); + const storedRoutes = await listAllRoutes(client); assert.isUndefined(storedRoutes.find((item) => item.name === "sameNameRoute")); return; } @@ -231,7 +233,7 @@ matrix([[true, false]], async function (useAad) { await client.setRoutes([invalidRoute]); } catch (error: any) { assert.equal(error.code, "UnprocessableConfiguration"); - const storedRoutes = await client.getRoutes(); + const storedRoutes = await listAllRoutes(client); assert.isUndefined( storedRoutes.find((item) => item.name === "invalidDuplicatedRoutingTrunksRoute") ); @@ -251,7 +253,7 @@ matrix([[true, false]], async function (useAad) { await client.setRoutes([invalidRoute]); } catch (error: any) { assert.equal(error.code, "UnprocessableConfiguration"); - const storedRoutes = await client.getRoutes(); + const storedRoutes = await listAllRoutes(client); assert.isUndefined(storedRoutes.find((item) => item.name === "invalidRoutingTrunkRoute")); return; } @@ -287,8 +289,8 @@ matrix([[true, false]], async function (useAad) { ]; await client.setRoutes(routes); - assert.deepEqual(await client.getTrunks(), trunks); - assert.deepEqual(await client.getRoutes(), routes); + assert.deepEqual(await listAllTrunks(client), trunks); + assert.deepEqual(await listAllRoutes(client), routes); }); }); }); diff --git a/sdk/communication/communication-phone-numbers/test/public/siprouting/setTrunks.spec.ts b/sdk/communication/communication-phone-numbers/test/public/siprouting/setTrunks.spec.ts index 3fa9da78ca38..25e685203a98 100644 --- a/sdk/communication/communication-phone-numbers/test/public/siprouting/setTrunks.spec.ts +++ b/sdk/communication/communication-phone-numbers/test/public/siprouting/setTrunks.spec.ts @@ -6,13 +6,15 @@ import { Context } from "mocha"; import { SipRoutingClient } from "../../../src"; -import { isPlaybackMode, Recorder } from "@azure-tools/test-recorder"; +import { Recorder, isPlaybackMode } from "@azure-tools/test-recorder"; import { SipTrunk, SipTrunkRoute } from "../../../src/models"; import { clearSipConfiguration, createRecordedClient, createRecordedClientWithToken, getUniqueFqdn, + listAllRoutes, + listAllTrunks, resetUniqueFqdns, } from "./utils/recordedClient"; import { matrix } from "@azure/test-utils"; @@ -79,7 +81,7 @@ matrix([[true, false]], async function (useAad) { const setTrunks = await client.setTrunks(trunks); assert.deepEqual(setTrunks, trunks); - const storedTrunks = await client.getTrunks(); + const storedTrunks = await listAllTrunks(client); assert.deepEqual(storedTrunks, trunks); }); @@ -96,7 +98,7 @@ matrix([[true, false]], async function (useAad) { const setTrunks = await client.setTrunks(trunks); assert.deepEqual(setTrunks, trunks); - const storedTrunks = await client.getTrunks(); + const storedTrunks = await listAllTrunks(client); assert.deepEqual(storedTrunks, trunks); }); @@ -105,7 +107,7 @@ matrix([[true, false]], async function (useAad) { await client.setTrunks([]); - const storedTrunks = await client.getTrunks(); + const storedTrunks = await listAllTrunks(client); assert.isNotNull(storedTrunks); assert.isArray(storedTrunks); assert.isEmpty(storedTrunks); @@ -120,7 +122,7 @@ matrix([[true, false]], async function (useAad) { await client.setTrunks([]); - const storedTrunks = await client.getTrunks(); + const storedTrunks = await listAllTrunks(client); assert.isNotNull(storedTrunks); assert.isArray(storedTrunks); assert.isEmpty(storedTrunks); @@ -192,7 +194,7 @@ matrix([[true, false]], async function (useAad) { await client.setTrunks([{ fqdn: firstFqdn, sipSignalingPort: 1234 }]); } catch (error: any) { assert.equal(error.code, "UnprocessableConfiguration"); - const storedTrunks = await client.getTrunks(); + const storedTrunks = await listAllTrunks(client); assert.isNotNull(storedTrunks); assert.isArray(storedTrunks); assert.deepEqual(storedTrunks, expectedTrunks); @@ -230,8 +232,8 @@ matrix([[true, false]], async function (useAad) { ]; await client.setTrunks(trunks); - assert.deepEqual(await client.getTrunks(), trunks); - assert.deepEqual(await client.getRoutes(), routes); + assert.deepEqual(await listAllTrunks(client), trunks); + assert.deepEqual(await listAllRoutes(client), routes); }); }); }); diff --git a/sdk/communication/communication-phone-numbers/test/public/siprouting/utils/recordedClient.ts b/sdk/communication/communication-phone-numbers/test/public/siprouting/utils/recordedClient.ts index d569980c0f1f..db5927eb5064 100644 --- a/sdk/communication/communication-phone-numbers/test/public/siprouting/utils/recordedClient.ts +++ b/sdk/communication/communication-phone-numbers/test/public/siprouting/utils/recordedClient.ts @@ -7,12 +7,12 @@ import * as dotenv from "dotenv"; import { Recorder, RecorderStartOptions, - env, + SanitizerOptions, assertEnvironmentVariable, + env, isPlaybackMode, - SanitizerOptions, } from "@azure-tools/test-recorder"; -import { SipRoutingClient } from "../../../../src"; +import { SipRoutingClient, SipTrunk, SipTrunkRoute } from "../../../../src"; import { parseConnectionString } from "@azure/communication-common"; import { TokenCredential } from "@azure/identity"; import { isNode } from "@azure/test-utils"; @@ -136,3 +136,24 @@ export function getUniqueFqdn(recorder: Recorder): string { export function resetUniqueFqdns(): void { fqdnNumber = 1; } + +export async function listAllTrunks(client: SipRoutingClient): Promise { + const result: SipTrunk[] = []; + + for await (const trunk of client.listTrunks()) { + if (trunk) { + result.push(trunk); + } + } + return result; +} + +export async function listAllRoutes(client: SipRoutingClient): Promise { + const result: SipTrunkRoute[] = []; + for await (const route of client.listRoutes()) { + if (route) { + result.push(route); + } + } + return result; +}