mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-04-05 10:09:03 +00:00
Test updates
This commit is contained in:
@@ -86,6 +86,13 @@ namespace API.Core.Controllers
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("confirm/resend")]
|
||||||
|
public async Task<ActionResult> ResendConfirmation([FromQuery] Guid userId)
|
||||||
|
{
|
||||||
|
await confirmationService.ResendConfirmationEmailAsync(userId);
|
||||||
|
return Ok(new ResponseBody { Message = "confirmation email has been resent" });
|
||||||
|
}
|
||||||
|
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[HttpPost("refresh")]
|
[HttpPost("refresh")]
|
||||||
public async Task<ActionResult> Refresh(
|
public async Task<ActionResult> Refresh(
|
||||||
|
|||||||
@@ -17,10 +17,34 @@ public class AuthRepositoryTest
|
|||||||
var conn = new MockDbConnection();
|
var conn = new MockDbConnection();
|
||||||
|
|
||||||
conn.Mocks.When(cmd => cmd.CommandText == "USP_RegisterUser")
|
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(
|
.ReturnsTable(
|
||||||
MockTable
|
MockTable
|
||||||
.WithColumns(("UserAccountId", typeof(Guid)))
|
.WithColumns(
|
||||||
.AddRow(expectedUserId)
|
("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);
|
var repo = CreateRepo(conn);
|
||||||
|
|||||||
@@ -33,7 +33,37 @@ public class AuthRepository(ISqlConnectionFactory connectionFactory)
|
|||||||
AddParameter(command, "@Hash", passwordHash);
|
AddParameter(command, "@Hash", passwordHash);
|
||||||
|
|
||||||
var result = await command.ExecuteScalarAsync();
|
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.");
|
return await GetUserByIdAsync(userAccountId) ?? throw new Exception("Failed to retrieve newly registered user.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user