Skip to content

Commit

Permalink
[communication][phone-numbers] enable samples (#14814)
Browse files Browse the repository at this point in the history
  • Loading branch information
0rland0Wats0n authored Apr 15, 2021
1 parent 6dca0f2 commit 4261997
Show file tree
Hide file tree
Showing 24 changed files with 70 additions and 47 deletions.
5 changes: 1 addition & 4 deletions sdk/communication/communication-phone-numbers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,8 @@
"Azure Communication Services account": "https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource"
},
"skip": [
"getPurchasedPhoneNumber.js",
"getPurchasedPhoneNumbers.js",
"purchasePhoneNumber.js",
"releasePhoneNumber.js",
"updatePhoneNumberCapabilities.js"
"releasePhoneNumber.js"
]
}
}
2 changes: 1 addition & 1 deletion sdk/communication/communication-phone-numbers/sample.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Used in most samples. Retrieve these values from a Communication Services instance
# in the Azure Portal.
COMMUNICATION_CONNECTION_STRING="endpoint=https://<resource name>.communication.azure.net/;accessKey=<key>"
COMMUNICATION_SAMPLES_CONNECTION_STRING="endpoint=https://<resource name>.communication.azure.net/;accessKey=<key>"

# The phone number to be retrieved by the getPurchasedPhoneNumber sample
PHONE_NUMBER_TO_GET="+16135550147"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ export async function main() {

// You will need to set this environment variable or edit the following values
const connectionString =
process.env.COMMUNICATION_CONNECTION_STRING ||
process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING ||
"endpoint=https://resourceName.communication.azure.net/;accessKey=test-key";

// create new client
const client = new PhoneNumbersClient(connectionString);

// You will need to set this environment variable or edit the following values
const phoneNumberToGet = process.env.PHONE_NUMBER_TO_GET || "<phone number to get>";
// You will need to set any of these environment variables or edit the following values
const phoneNumberToGet =
process.env.PHONE_NUMBER_TO_GET || process.env.AZURE_PHONE_NUMBER || "<phone number to get>";

// get the phone number
const phoneNumber = await client.getPurchasedPhoneNumber(phoneNumberToGet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import * as dotenv from "dotenv";
dotenv.config();

export async function main() {
console.log("\n== Get a Purchased Phone Numbers Sample ==\n");
console.log("\n== Get Purchased Phone Numbers Sample ==\n");

// You will need to set this environment variable or edit the following values
const connectionString =
process.env.COMMUNICATION_CONNECTION_STRING ||
process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING ||
"endpoint=https://resourceName.communication.azure.net/;accessKey=test-key";

// create new client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function main() {

// You will need to set this environment variable or edit the following values
const connectionString =
process.env.COMMUNICATION_CONNECTION_STRING ||
process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING ||
"endpoint=https://resourceName.communication.azure.net/;accessKey=test-key";

// create new client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ export async function main() {

// You will need to set this environment variable or edit the following values
const connectionString =
process.env.COMMUNICATION_CONNECTION_STRING ||
process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING ||
"endpoint=https://resourceName.communication.azure.net/;accessKey=test-key";

// create new client
const client = new PhoneNumbersClient(connectionString);

// You will need to set this environment variable or edit the following values
const phoneNumberToRelease = process.env.PHONE_NUMBER_TO_RELEASE || "<phone number to release>";
// You will need to set any of these environment variables or edit the following values
const phoneNumberToRelease =
process.env.PHONE_NUMBER_TO_RELEASE ||
process.env.AZURE_PHONE_NUMBER ||
"<phone number to release>";

// get poller to monitor release
const releasePoller = await client.beginReleasePhoneNumber(phoneNumberToRelease);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ export async function main() {

// You will need to set this environment variable or edit the following values
const connectionString =
process.env.COMMUNICATION_CONNECTION_STRING ||
process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING ||
"endpoint=https://resourceName.communication.azure.net/;accessKey=test-key";

// create new client
const client = new PhoneNumbersClient(connectionString);

// You will need to set this environment variable or edit the following values
const phoneNumberToUpdate = process.env.PHONE_NUMBER_TO_UPDATE || "<phone number to update>";
// You will need to set any of these environment variables or edit the following values
const phoneNumberToUpdate =
process.env.PHONE_NUMBER_TO_UPDATE ||
process.env.AZURE_PHONE_NUMBER ||
"<phone number to update>";

// This will update the phone number to send and receive sms, but only send calls.
const updateRequest: PhoneNumberCapabilitiesRequest = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ node getPurchasedPhoneNumber.js
Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform):

```bash
npx cross-env COMMUNICATION_CONNECTION_STRING="<communication connection string>" PHONE_NUMBER_TO_GET="<phone number to get>" node getPurchasedPhoneNumber.js
npx cross-env COMMUNICATION_SAMPLES_CONNECTION_STRING="<communication samples connection string>" PHONE_NUMBER_TO_GET="<phone number to get>" AZURE_PHONE_NUMBER="<azure phone number>" node getPurchasedPhoneNumber.js
```

## Next Steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ async function main() {

// You will need to set this environment variable or edit the following values
const connectionString =
process.env.COMMUNICATION_CONNECTION_STRING ||
process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING ||
"endpoint=https://resourceName.communication.azure.net/;accessKey=test-key";

// create new client
const client = new PhoneNumbersClient(connectionString);

// You will need to set this environment variable or edit the following values
const phoneNumberToGet = process.env.PHONE_NUMBER_TO_GET || "<phone number to get>";
// You will need to set any of these environment variables or edit the following values
const phoneNumberToGet =
process.env.PHONE_NUMBER_TO_GET || process.env.AZURE_PHONE_NUMBER || "<phone number to get>";

// get the phone number
const phoneNumber = await client.getPurchasedPhoneNumber(phoneNumberToGet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ const dotenv = require("dotenv");
dotenv.config();

async function main() {
console.log("\n== Get a Purchased Phone Numbers Sample ==\n");
console.log("\n== Get Purchased Phone Numbers Sample ==\n");

// You will need to set this environment variable or edit the following values
const connectionString =
process.env.COMMUNICATION_CONNECTION_STRING ||
process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING ||
"endpoint=https://resourceName.communication.azure.net/;accessKey=test-key";

// create new client
Expand All @@ -29,6 +29,7 @@ async function main() {
console.log(`Phone number type is ${phoneNumber.phoneNumberType}`);
}
}

main().catch((error) => {
console.log("The sample encountered an error:", error);
process.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function main() {

// You will need to set this environment variable or edit the following values
const connectionString =
process.env.COMMUNICATION_CONNECTION_STRING ||
process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING ||
"endpoint=https://resourceName.communication.azure.net/;accessKey=test-key";

// create new client
Expand Down Expand Up @@ -57,6 +57,7 @@ async function main() {
console.log("Did not find any phone numbers.");
}
}

main().catch((error) => {
console.log("The sample encountered an error:", error);
process.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ async function main() {

// You will need to set this environment variable or edit the following values
const connectionString =
process.env.COMMUNICATION_CONNECTION_STRING ||
process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING ||
"endpoint=https://resourceName.communication.azure.net/;accessKey=test-key";

// create new client
const client = new PhoneNumbersClient(connectionString);

// You will need to set this environment variable or edit the following values
const phoneNumberToRelease = process.env.PHONE_NUMBER_TO_RELEASE || "<phone number to release>";
// You will need to set any of these environment variables or edit the following values
const phoneNumberToRelease =
process.env.PHONE_NUMBER_TO_RELEASE ||
process.env.AZURE_PHONE_NUMBER ||
"<phone number to release>";

// get poller to monitor release
const releasePoller = await client.beginReleasePhoneNumber(phoneNumberToRelease);
Expand All @@ -33,6 +36,7 @@ async function main() {

console.log("Successfully release phone number.");
}

main().catch((error) => {
console.log("The sample encountered an error:", error);
process.exit(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Used in most samples. Retrieve these values from a Communication Services instance
# in the Azure Portal.
COMMUNICATION_CONNECTION_STRING="endpoint=https://<resource name>.communication.azure.net/;accessKey=<key>"
COMMUNICATION_SAMPLES_CONNECTION_STRING="endpoint=https://<resource name>.communication.azure.net/;accessKey=<key>"

# The phone number to be retrieved by the getPurchasedPhoneNumber sample
PHONE_NUMBER_TO_GET="+16135550147"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ async function main() {

// You will need to set this environment variable or edit the following values
const connectionString =
process.env.COMMUNICATION_CONNECTION_STRING ||
process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING ||
"endpoint=https://resourceName.communication.azure.net/;accessKey=test-key";

// create new client
const client = new PhoneNumbersClient(connectionString);

// You will need to set this environment variable or edit the following values
const phoneNumberToUpdate = process.env.PHONE_NUMBER_TO_UPDATE || "<phone number to update>";
// You will need to set any of these environment variables or edit the following values
const phoneNumberToUpdate =
process.env.PHONE_NUMBER_TO_UPDATE ||
process.env.AZURE_PHONE_NUMBER ||
"<phone number to update>";

// This will update the phone number to send and receive sms, but only send calls.
const updateRequest = {
Expand All @@ -40,6 +43,7 @@ async function main() {
const { capabilities } = await updatePoller.pollUntilDone();
console.log(`These are the update capabilities: ${capabilities}`);
}

main().catch((error) => {
console.log("The sample encountered an error:", error);
process.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ node dist/getPurchasedPhoneNumber.ts
Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform):

```bash
npx cross-env COMMUNICATION_CONNECTION_STRING="<communication connection string>" PHONE_NUMBER_TO_GET="<phone number to get>" node dist/getPurchasedPhoneNumber.js
npx cross-env COMMUNICATION_SAMPLES_CONNECTION_STRING="<communication samples connection string>" PHONE_NUMBER_TO_GET="<phone number to get>" AZURE_PHONE_NUMBER="<azure phone number>" node dist/getPurchasedPhoneNumber.js
```

## Next Steps
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Used in most samples. Retrieve these values from a Communication Services instance
# in the Azure Portal.
COMMUNICATION_CONNECTION_STRING="endpoint=https://<resource name>.communication.azure.net/;accessKey=<key>"
COMMUNICATION_SAMPLES_CONNECTION_STRING="endpoint=https://<resource name>.communication.azure.net/;accessKey=<key>"

# The phone number to be retrieved by the getPurchasedPhoneNumber sample
PHONE_NUMBER_TO_GET="+16135550147"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ export async function main() {

// You will need to set this environment variable or edit the following values
const connectionString =
process.env.COMMUNICATION_CONNECTION_STRING ||
process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING ||
"endpoint=https://resourceName.communication.azure.net/;accessKey=test-key";

// create new client
const client = new PhoneNumbersClient(connectionString);

// You will need to set this environment variable or edit the following values
const phoneNumberToGet = process.env.PHONE_NUMBER_TO_GET || "<phone number to get>";
// You will need to set any of these environment variables or edit the following values
const phoneNumberToGet =
process.env.PHONE_NUMBER_TO_GET || process.env.AZURE_PHONE_NUMBER || "<phone number to get>";

// get the phone number
const phoneNumber = await client.getPurchasedPhoneNumber(phoneNumberToGet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import * as dotenv from "dotenv";
dotenv.config();

export async function main() {
console.log("\n== Get a Purchased Phone Numbers Sample ==\n");
console.log("\n== Get Purchased Phone Numbers Sample ==\n");

// You will need to set this environment variable or edit the following values
const connectionString =
process.env.COMMUNICATION_CONNECTION_STRING ||
process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING ||
"endpoint=https://resourceName.communication.azure.net/;accessKey=test-key";

// create new client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function main() {

// You will need to set this environment variable or edit the following values
const connectionString =
process.env.COMMUNICATION_CONNECTION_STRING ||
process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING ||
"endpoint=https://resourceName.communication.azure.net/;accessKey=test-key";

// create new client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ export async function main() {

// You will need to set this environment variable or edit the following values
const connectionString =
process.env.COMMUNICATION_CONNECTION_STRING ||
process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING ||
"endpoint=https://resourceName.communication.azure.net/;accessKey=test-key";

// create new client
const client = new PhoneNumbersClient(connectionString);

// You will need to set this environment variable or edit the following values
const phoneNumberToRelease = process.env.PHONE_NUMBER_TO_RELEASE || "<phone number to release>";
// You will need to set any of these environment variables or edit the following values
const phoneNumberToRelease =
process.env.PHONE_NUMBER_TO_RELEASE ||
process.env.AZURE_PHONE_NUMBER ||
"<phone number to release>";

// get poller to monitor release
const releasePoller = await client.beginReleasePhoneNumber(phoneNumberToRelease);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ export async function main() {

// You will need to set this environment variable or edit the following values
const connectionString =
process.env.COMMUNICATION_CONNECTION_STRING ||
process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING ||
"endpoint=https://resourceName.communication.azure.net/;accessKey=test-key";

// create new client
const client = new PhoneNumbersClient(connectionString);

// You will need to set this environment variable or edit the following values
const phoneNumberToUpdate = process.env.PHONE_NUMBER_TO_UPDATE || "<phone number to update>";
// You will need to set any of these environment variables or edit the following values
const phoneNumberToUpdate =
process.env.PHONE_NUMBER_TO_UPDATE ||
process.env.AZURE_PHONE_NUMBER ||
"<phone number to update>";

// This will update the phone number to send and receive sms, but only send calls.
const updateRequest: PhoneNumberCapabilitiesRequest = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ matrix([[true, false]], async function(useAad) {
const { phoneNumber } = await client.getPurchasedPhoneNumber(purchasedPhoneNumber);

assert.strictEqual(purchasedPhoneNumber, phoneNumber);
}).timeout(7000);
}).timeout(10000);

it("errors if phone number not found", async function() {
const fake = "+14155550100";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ matrix([[true, false]], async function(useAad) {
const phoneNumber = await updatePoller.pollUntilDone();
assert.ok(updatePoller.getOperationState().isCompleted);
assert.deepEqual(phoneNumber.capabilities, update);
}).timeout(30000);
}).timeout(60000);
});
});
1 change: 1 addition & 0 deletions sdk/communication/communication-phone-numbers/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ stages:
AZURE_TENANT_ID: $(aad-azure-sdk-test-tenant-id)
AZURE_CLIENT_SECRET: $(aad-azure-sdk-test-client-secret)
AZURE_CLIENT_ID: $(aad-azure-sdk-test-client-id)
COMMUNICATION_SAMPLES_CONNECTION_STRING: $(communication-livetest-connection-string)

0 comments on commit 4261997

Please sign in to comment.