Skip to content

Commit

Permalink
Add VerifyEmailResponse (#151)
Browse files Browse the repository at this point in the history
* Add VerifyEmailResponse

* Test fix
  • Loading branch information
Patrick committed Sep 1, 2023
1 parent 8b42557 commit a46340c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public UserManagementService(WorkOSClient client)
/// </summary>
/// <param name="options"> Parameters used to complete email verification.</param>
/// <param name="cancellationToken">An optional token to cancel the request.</param>
/// <returns> The corresponding User object.</returns>
public async Task<User> VerifyEmail(
/// <returns> The corresponding VerifyEmailResponse object.</returns>
public async Task<VerifyEmailResponse> VerifyEmail(
VerifyEmailOptions options,
CancellationToken cancellationToken = default)
{
Expand All @@ -193,7 +193,7 @@ public UserManagementService(WorkOSClient client)
Method = HttpMethod.Post,
Path = $"/users/{options.UserId}/verify_email",
};
return await this.Client.MakeAPIRequest<User>(request, cancellationToken);
return await this.Client.MakeAPIRequest<VerifyEmailResponse>(request, cancellationToken);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace WorkOS
{
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;

/// <summary>
/// Represents a response for a Verify Email.
/// </summary>
public class VerifyEmailResponse
{
/// <summary>
/// The corresponding User object.
/// </summary>
[JsonProperty("user")]
public User User { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class UserManagementServiceTest
private readonly SendVerificationEmailResponse mockSendVerificationEmailResponse;
private readonly AuthenticateUserResponse mockAuthenticateUserResponse;

private readonly VerifyEmailResponse mockVerifyEmailResponse;

private readonly CreateUserOptions mockCreateUserOptions;

private readonly AuthenticateUserWithPasswordOptions mockAuthenticateUserWithPasswordOptions;
Expand Down Expand Up @@ -183,6 +185,11 @@ public UserManagementServiceTest()
User = this.mockUser,
};

this.mockVerifyEmailResponse = new VerifyEmailResponse
{
User = this.mockUser,
};

this.mockListUsersOptions = new ListUsersOptions
{
Email = "marcelina.davis@gmail.com",
Expand Down Expand Up @@ -431,16 +438,16 @@ public async void TestVerifyEmail()
HttpMethod.Post,
$"/users/{this.mockUser.Id}/verify_email",
HttpStatusCode.Created,
RequestUtilities.ToJsonString(this.mockUser));
RequestUtilities.ToJsonString(this.mockVerifyEmailResponse));

var user = await this.service.VerifyEmail(this.mockVerifyEmailOptions);
var response = await this.service.VerifyEmail(this.mockVerifyEmailOptions);

this.httpMock.AssertRequestWasMade(
HttpMethod.Post,
$"/users/{this.mockUser.Id}/verify_email");
Assert.Equal(
JsonConvert.SerializeObject(user),
JsonConvert.SerializeObject(this.mockUser));
JsonConvert.SerializeObject(response),
JsonConvert.SerializeObject(this.mockVerifyEmailResponse));
}

[Fact]
Expand Down

0 comments on commit a46340c

Please sign in to comment.