From 70ad06eeda8b5509492a6379614638bb0f6f53b5 Mon Sep 17 00:00:00 2001 From: Aaron Po Date: Sun, 29 Mar 2026 20:42:52 -0400 Subject: [PATCH] Test updates --- .../API.Core/Controllers/AuthController.cs | 7 ++++ .../Auth/AuthRepository.test.cs | 28 ++++++++++++++-- .../Auth/AuthRepository.cs | 32 ++++++++++++++++++- 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/Core/API/API.Core/Controllers/AuthController.cs b/src/Core/API/API.Core/Controllers/AuthController.cs index 7b2dcc4..a6cc9af 100644 --- a/src/Core/API/API.Core/Controllers/AuthController.cs +++ b/src/Core/API/API.Core/Controllers/AuthController.cs @@ -86,6 +86,13 @@ namespace API.Core.Controllers ); } + [HttpPost("confirm/resend")] + public async Task ResendConfirmation([FromQuery] Guid userId) + { + await confirmationService.ResendConfirmationEmailAsync(userId); + return Ok(new ResponseBody { Message = "confirmation email has been resent" }); + } + [AllowAnonymous] [HttpPost("refresh")] public async Task Refresh( diff --git a/src/Core/Infrastructure/Infrastructure.Repository.Tests/Auth/AuthRepository.test.cs b/src/Core/Infrastructure/Infrastructure.Repository.Tests/Auth/AuthRepository.test.cs index e30ceee..e067b4f 100644 --- a/src/Core/Infrastructure/Infrastructure.Repository.Tests/Auth/AuthRepository.test.cs +++ b/src/Core/Infrastructure/Infrastructure.Repository.Tests/Auth/AuthRepository.test.cs @@ -17,10 +17,34 @@ public class AuthRepositoryTest var conn = new MockDbConnection(); conn.Mocks.When(cmd => cmd.CommandText == "USP_RegisterUser") + .ReturnsScalar(expectedUserId); + + // Mock the subsequent read for the newly created user by id + conn.Mocks.When(cmd => cmd.CommandText == "usp_GetUserAccountById") .ReturnsTable( MockTable - .WithColumns(("UserAccountId", typeof(Guid))) - .AddRow(expectedUserId) + .WithColumns( + ("UserAccountId", typeof(Guid)), + ("Username", typeof(string)), + ("FirstName", typeof(string)), + ("LastName", typeof(string)), + ("Email", typeof(string)), + ("CreatedAt", typeof(DateTime)), + ("UpdatedAt", typeof(DateTime?)), + ("DateOfBirth", typeof(DateTime)), + ("Timer", typeof(byte[])) + ) + .AddRow( + expectedUserId, + "testuser", + "Test", + "User", + "test@example.com", + DateTime.UtcNow, + null, + new DateTime(1990, 1, 1), + null + ) ); var repo = CreateRepo(conn); diff --git a/src/Core/Infrastructure/Infrastructure.Repository/Auth/AuthRepository.cs b/src/Core/Infrastructure/Infrastructure.Repository/Auth/AuthRepository.cs index b878446..bb701b3 100644 --- a/src/Core/Infrastructure/Infrastructure.Repository/Auth/AuthRepository.cs +++ b/src/Core/Infrastructure/Infrastructure.Repository/Auth/AuthRepository.cs @@ -33,7 +33,37 @@ public class AuthRepository(ISqlConnectionFactory connectionFactory) AddParameter(command, "@Hash", passwordHash); var result = await command.ExecuteScalarAsync(); - var userAccountId = result != null ? (Guid)result : Guid.Empty; + + Guid userAccountId = Guid.Empty; + if (result != null && result != DBNull.Value) + { + if (result is Guid g) + { + userAccountId = g; + } + else if (result is string s && Guid.TryParse(s, out var parsed)) + { + userAccountId = parsed; + } + else if (result is byte[] bytes && bytes.Length == 16) + { + userAccountId = new Guid(bytes); + } + else + { + // Fallback: try to convert and parse string representation + try + { + var str = result.ToString(); + if (!string.IsNullOrEmpty(str) && Guid.TryParse(str, out var p)) + userAccountId = p; + } + catch + { + userAccountId = Guid.Empty; + } + } + } return await GetUserByIdAsync(userAccountId) ?? throw new Exception("Failed to retrieve newly registered user."); }