-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added endpoint to get list of Zoom Phone users (#344)
* Get list of Phone users endpoint is added * Fix: set missing default value for pageSize and added a check for the value to be in available range; added unit test * Changed type of get phone users endpoint response * Added new model 'PhoneUser' and reused it in Phone.ListPhoneUsers resource instead of 'PhoneCallUserProfile' model --------- Co-authored-by: Snezhanna Roshchupkina <Snezhanna.Roshchupkina@lanit-tercom.com>
- Loading branch information
1 parent
9389bc5
commit 4d586b5
Showing
8 changed files
with
367 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System.Text.Json; | ||
using Shouldly; | ||
using Xunit; | ||
using ZoomNet.Json; | ||
using ZoomNet.Models; | ||
|
||
namespace ZoomNet.UnitTests.Models | ||
{ | ||
public class PhoneUserTests | ||
{ | ||
#region constants | ||
|
||
internal const string PHONE_USER = @"{ | ||
""id"": ""NL3cEpSdRc-c2t8aLoZqiw"", | ||
""phone_user_id"": ""u7pnC468TaS46OuNoEw6GA"", | ||
""email"": ""test_phone_user@testapi.com"", | ||
""name"": ""test phone user"", | ||
""extension_id"": ""CcrEGgmeQem1uyJsuIRKwA"", | ||
""extension_number"": 123, | ||
""status"": ""activate"", | ||
""calling_plans"": [ | ||
{ | ||
""type"": 600, | ||
""name"": ""Delhi billing"", | ||
""billing_account_id"": ""3WWAEiEjTj2IQuyDiKMd_A"", | ||
""billing_account_name"": ""Delhi billing"" | ||
} | ||
], | ||
""phone_numbers"": [ | ||
{ | ||
""id"": ""---M1padRvSUtw7YihN7sA"", | ||
""number"": ""14232058798"" | ||
} | ||
], | ||
""site"": { | ||
""id"": ""8f71O6rWT8KFUGQmJIFAdQ"", | ||
""name"": ""Test Site"" | ||
}, | ||
""department"": ""Test"", | ||
""cost_center"": ""Cost Test Center"" | ||
}"; | ||
|
||
#endregion | ||
|
||
#region tests | ||
|
||
[Fact] | ||
public void Parse_Json_PhoneUserTests() | ||
{ | ||
// Arrange | ||
|
||
// Act | ||
var result = JsonSerializer.Deserialize<PhoneUser>( | ||
PHONE_USER, JsonFormatter.SerializerOptions); | ||
|
||
// Assert | ||
result.Id.ShouldBe("NL3cEpSdRc-c2t8aLoZqiw"); | ||
result.PhoneUserId.ShouldBe("u7pnC468TaS46OuNoEw6GA"); | ||
result.Email.ShouldBe("test_phone_user@testapi.com"); | ||
result.Name.ShouldBe("test phone user"); | ||
result.ExtensionId.ShouldBe("CcrEGgmeQem1uyJsuIRKwA"); | ||
result.ExtensionNumber.ShouldBe(123); | ||
result.Status.ShouldBe(PhoneCallUserStatus.Active); | ||
result.CallingPlans.ShouldNotBeNull(); | ||
result.CallingPlans.Length.ShouldBe(1); | ||
result.PhoneNumbers.ShouldNotBeNull(); | ||
result.PhoneNumbers.Length.ShouldBe(1); | ||
result.Department.ShouldBe("Test"); | ||
result.CostCenter.ShouldBe("Cost Test Center"); | ||
result.Site.Id.ShouldBe("8f71O6rWT8KFUGQmJIFAdQ"); | ||
result.Site.Name.ShouldBe("Test Site"); | ||
|
||
var callingPlan = result.CallingPlans[0]; | ||
callingPlan.BillingAccountId.ShouldBe("3WWAEiEjTj2IQuyDiKMd_A"); | ||
callingPlan.BillingAccountName.ShouldBe("Delhi billing"); | ||
|
||
var phoneNumber = result.PhoneNumbers[0]; | ||
phoneNumber.PhoneNumberId.ShouldBe("---M1padRvSUtw7YihN7sA"); | ||
phoneNumber.PhoneNumber.ShouldBe("14232058798"); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using RichardSzalay.MockHttp; | ||
using Shouldly; | ||
using Xunit; | ||
using ZoomNet.Resources; | ||
|
||
namespace ZoomNet.UnitTests.Resources | ||
{ | ||
public class PhoneUserTests | ||
{ | ||
#region constants | ||
|
||
internal const string PHONE_USERS_PAGINATED_OBJECT = @"{ | ||
""next_page_token"": ""F2qwertyg5eIqRRgC2YMauur8ZHUaJqtS3i"", | ||
""page_size"": 1, | ||
""total_records"": 10, | ||
""users"": [ | ||
{ | ||
""id"": ""NL3cEpSdRc-c2t8aLoZqiw"", | ||
""phone_user_id"": ""u7pnC468TaS46OuNoEw6GA"", | ||
""email"": ""test_phone_user@testapi.com"", | ||
""name"": ""test phone user"", | ||
""extension_id"": ""CcrEGgmeQem1uyJsuIRKwA"", | ||
""extension_number"": 123, | ||
""status"": ""activate"", | ||
""calling_plans"": [ | ||
{ | ||
""type"": 600, | ||
""name"": ""Delhi billing"", | ||
""billing_account_id"": ""3WWAEiEjTj2IQuyDiKMd_A"", | ||
""billing_account_name"": ""Delhi billing"" | ||
} | ||
], | ||
""phone_numbers"": [ | ||
{ | ||
""id"": ""---M1padRvSUtw7YihN7sA"", | ||
""number"": ""14232058798"" | ||
} | ||
], | ||
""site"": { | ||
""id"": ""8f71O6rWT8KFUGQmJIFAdQ"", | ||
""name"": ""Test Site"" | ||
}, | ||
""department"": ""Test"", | ||
""cost_center"": ""Cost Test Center"" | ||
} | ||
] | ||
}"; | ||
|
||
#endregion | ||
|
||
#region tests | ||
|
||
[Fact] | ||
public async Task GetPhoneUsersPaginatedResponseTestsAsync() | ||
{ | ||
// Arrange | ||
var pageSize = 1; | ||
|
||
var mockHttp = new MockHttpMessageHandler(); | ||
mockHttp | ||
.Expect( | ||
HttpMethod.Get, | ||
Utils.GetZoomApiUri("phone/users")) | ||
.Respond( | ||
"application/json", | ||
PHONE_USERS_PAGINATED_OBJECT); | ||
|
||
var client = Utils.GetFluentClient(mockHttp); | ||
var phone = new Phone(client); | ||
|
||
// Act | ||
var result = await phone | ||
.ListPhoneUsersAsync(pageSize: pageSize) | ||
.ConfigureAwait(true); | ||
|
||
// Assert | ||
mockHttp.VerifyNoOutstandingExpectation(); | ||
mockHttp.VerifyNoOutstandingRequest(); | ||
result.NextPageToken.ShouldNotBeNullOrEmpty(); | ||
result.PageSize.ShouldBe(1); | ||
result.TotalRecords.ShouldBe(10); | ||
result.Records.ShouldNotBeNull(); | ||
result.Records.Length.ShouldBe(1); | ||
result.Records[0].Id.ShouldBe("NL3cEpSdRc-c2t8aLoZqiw"); | ||
result.Records[0].PhoneNumbers[0].PhoneNumberId.ShouldBe("---M1padRvSUtw7YihN7sA"); | ||
result.Records[0].PhoneNumbers[0].PhoneNumber.ShouldBe("14232058798"); | ||
} | ||
|
||
[Theory] | ||
[InlineData(0)] | ||
[InlineData(101)] | ||
public void InvalidPageSize_GetPhoneUsersPaginatedResponseTests(int pageSize) | ||
{ | ||
// Arrange | ||
var mockHttp = new MockHttpMessageHandler(); | ||
|
||
var client = Utils.GetFluentClient(mockHttp); | ||
var phone = new Phone(client); | ||
|
||
// Act and Assert | ||
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => phone | ||
.ListPhoneUsersAsync(pageSize: pageSize) | ||
.ConfigureAwait(true)); | ||
|
||
exception.ParamName.ShouldBe(nameof(pageSize)); | ||
exception.Message.ShouldBe($"Records per page must be between 1 and 100 (Parameter '{nameof(pageSize)}')"); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using System.Text.Json.Serialization; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace ZoomNet.Models; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace ZoomNet.Models; | ||
|
||
/// <summary> | ||
/// Zoom Phone user information. | ||
/// </summary> | ||
public class PhoneUser | ||
{ | ||
/// <summary> | ||
/// Gets or sets the calling plans. | ||
/// </summary> | ||
[JsonPropertyName("calling_plans")] | ||
public CallingPlan[] CallingPlans { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the cost center. | ||
/// </summary> | ||
[JsonPropertyName("cost_center")] | ||
public string CostCenter { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the department of the object. | ||
/// </summary> | ||
[JsonPropertyName("department")] | ||
public string Department { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the email address. | ||
/// </summary> | ||
[JsonPropertyName("email")] | ||
public string Email { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the extension ID. | ||
/// </summary> | ||
[JsonPropertyName("extension_id")] | ||
public string ExtensionId { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the extension number. | ||
/// </summary> | ||
[JsonPropertyName("extension_number")] | ||
public int ExtensionNumber { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the Zoom user ID. | ||
/// </summary> | ||
[JsonPropertyName("id")] | ||
public string Id { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the Zoom user name. | ||
/// </summary> | ||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the phone numbers. | ||
/// </summary> | ||
[JsonPropertyName("phone_numbers")] | ||
public PhoneCallPhoneNumber[] PhoneNumbers { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the Zoom phone user id. | ||
/// </summary> | ||
[JsonPropertyName("phone_user_id")] | ||
public string PhoneUserId { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a site. | ||
/// </summary> | ||
[JsonPropertyName("site")] | ||
public Site Site { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the status of the user. | ||
/// </summary> | ||
[JsonPropertyName("status")] | ||
public PhoneCallUserStatus Status { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace ZoomNet.Models; | ||
|
||
/// <summary> | ||
/// Site information to which a user belongs to. | ||
/// </summary> | ||
public class Site | ||
{ | ||
/// <summary> | ||
/// Gets or sets the Id. | ||
/// </summary> | ||
[JsonPropertyName("id")] | ||
public string Id { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the name. | ||
/// </summary> | ||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.