fix(postit): normalize profile calendar and bank clear state
This commit is contained in:
parent
6b75ae7682
commit
008295c8f6
3 changed files with 108 additions and 28 deletions
|
|
@ -106,4 +106,41 @@ public class HomePageProviderFlowTests
|
|||
Assert.NotNull(vm.SaveProfileCommand);
|
||||
Assert.True(vm.SaveProfileCommand.CanExecute(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UserProfilePage_builds_profile_payload_for_calendar_and_bank_values()
|
||||
{
|
||||
var vm = new UserProfilePageViewModel
|
||||
{
|
||||
UserName = "alice.new",
|
||||
FullName = "Alice Example",
|
||||
Address = "14 rue de l’Érable",
|
||||
DedicatedGoogleCalendar = "calendar-123",
|
||||
BankInfoSummary = "FR14 2004 1010 0505 0001 3M02 606"
|
||||
};
|
||||
|
||||
var payload = vm.BuildProfileUpdateRequest();
|
||||
|
||||
Assert.Equal("alice.new", payload.UserName);
|
||||
Assert.Equal("calendar-123", payload.GoogleCalendarId);
|
||||
Assert.Equal("FR14 2004 1010 0505 0001 3M02 606", payload.BankInfoSummary);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UserProfilePage_turns_placeholder_values_into_empty_payload_fields()
|
||||
{
|
||||
var vm = new UserProfilePageViewModel
|
||||
{
|
||||
UserName = "alice.new",
|
||||
FullName = "Alice Example",
|
||||
Address = "14 rue de l’Érable",
|
||||
DedicatedGoogleCalendar = "Non configuré",
|
||||
BankInfoSummary = "Aucune information bancaire"
|
||||
};
|
||||
|
||||
var payload = vm.BuildProfileUpdateRequest();
|
||||
|
||||
Assert.Equal(string.Empty, payload.GoogleCalendarId);
|
||||
Assert.Equal(string.Empty, payload.BankInfoSummary);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,6 +95,31 @@ public partial class UserProfilePageViewModel : ViewModelBase
|
|||
}
|
||||
}
|
||||
|
||||
public ProfileUpdateRequest BuildProfileUpdateRequest()
|
||||
{
|
||||
static string NormalizeField(string? value, string placeholder)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var trimmed = value.Trim();
|
||||
return string.Equals(trimmed, placeholder, StringComparison.OrdinalIgnoreCase)
|
||||
? string.Empty
|
||||
: trimmed;
|
||||
}
|
||||
|
||||
return new ProfileUpdateRequest
|
||||
{
|
||||
UserName = NormalizeField(UserName, "—"),
|
||||
FullName = NormalizeField(FullName, "—"),
|
||||
Address = NormalizeField(Address, "—"),
|
||||
GoogleCalendarId = NormalizeField(DedicatedGoogleCalendar, "Non configuré"),
|
||||
BankInfoSummary = NormalizeField(BankInfoSummary, "Aucune information bancaire")
|
||||
};
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public async Task SaveProfileAsync()
|
||||
{
|
||||
|
|
@ -107,14 +132,7 @@ public partial class UserProfilePageViewModel : ViewModelBase
|
|||
IsBusy = true;
|
||||
try
|
||||
{
|
||||
var payload = new ProfileUpdateRequest
|
||||
{
|
||||
UserName = string.IsNullOrWhiteSpace(UserName) ? string.Empty : UserName.Trim(),
|
||||
FullName = string.IsNullOrWhiteSpace(FullName) ? string.Empty : FullName.Trim(),
|
||||
Address = string.IsNullOrWhiteSpace(Address) ? string.Empty : Address.Trim(),
|
||||
GoogleCalendarId = DedicatedGoogleCalendar == "Non configuré" ? string.Empty : DedicatedGoogleCalendar.Trim(),
|
||||
BankInfoSummary = BankInfoSummary == "Aucune information bancaire" ? string.Empty : BankInfoSummary.Trim()
|
||||
};
|
||||
var payload = BuildProfileUpdateRequest();
|
||||
|
||||
var endpoint = new Uri(new Uri(_api.Settings.ApiUrl.TrimEnd('/') + "/", UriKind.Absolute), "account/me").ToString();
|
||||
await _api.CallAsync(HttpMethod.Put, endpoint, payload).ConfigureAwait(true);
|
||||
|
|
|
|||
|
|
@ -116,35 +116,50 @@ namespace Yavsc.WebApi.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.FullName))
|
||||
if (request.FullName is not null)
|
||||
{
|
||||
user.FullName = request.FullName.Trim();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.Address))
|
||||
if (request.Address is not null)
|
||||
{
|
||||
if (user.PostalAddress is null)
|
||||
var trimmedAddress = request.Address.Trim();
|
||||
if (string.IsNullOrWhiteSpace(trimmedAddress))
|
||||
{
|
||||
user.PostalAddress = new Yavsc.Models.Relationship.Location { Address = request.Address.Trim() };
|
||||
user.PostalAddress = null;
|
||||
}
|
||||
else if (user.PostalAddress is null)
|
||||
{
|
||||
user.PostalAddress = new Yavsc.Models.Relationship.Location { Address = trimmedAddress };
|
||||
}
|
||||
else
|
||||
{
|
||||
user.PostalAddress.Address = request.Address.Trim();
|
||||
user.PostalAddress.Address = trimmedAddress;
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.GoogleCalendarId))
|
||||
if (request.GoogleCalendarId is not null)
|
||||
{
|
||||
user.DedicatedGoogleCalendar = request.GoogleCalendarId.Trim();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.BankInfoSummary) && (user.BankInfo is null || user.BankInfo.Count == 0))
|
||||
if (request.BankInfoSummary is not null)
|
||||
{
|
||||
var bankSummary = request.BankInfoSummary.Trim();
|
||||
if (string.IsNullOrWhiteSpace(bankSummary))
|
||||
{
|
||||
if (user.BankInfo is not null)
|
||||
{
|
||||
user.BankInfo.Clear();
|
||||
}
|
||||
}
|
||||
else if (user.BankInfo is null || user.BankInfo.Count == 0)
|
||||
{
|
||||
var bank = new Yavsc.Models.Bank.BankIdentity
|
||||
{
|
||||
UserId = uid,
|
||||
User = user,
|
||||
IBAN = request.BankInfoSummary,
|
||||
IBAN = bankSummary,
|
||||
BIC = string.Empty,
|
||||
AccountNumber = string.Empty,
|
||||
BankCode = string.Empty,
|
||||
|
|
@ -155,6 +170,16 @@ namespace Yavsc.WebApi.Controllers
|
|||
user.BankInfo ??= [];
|
||||
user.BankInfo.Add(bank);
|
||||
}
|
||||
else
|
||||
{
|
||||
var firstBank = user.BankInfo.First();
|
||||
firstBank.IBAN = bankSummary;
|
||||
firstBank.BIC = string.Empty;
|
||||
firstBank.AccountNumber = string.Empty;
|
||||
firstBank.BankCode = string.Empty;
|
||||
firstBank.WicketCode = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
await _dbContext.SaveChangesAsync(uid);
|
||||
return Ok(new { status = "saved", fullName = user.FullName, address = user.PostalAddress?.Address, googleCalendarId = user.DedicatedGoogleCalendar });
|
||||
|
|
|
|||
Loading…
Reference in a new issue