2026-08-30 23:55:09 +01:00
|
|
|
using System.Net.Http;
|
|
|
|
|
using PostIt.ViewModels;
|
|
|
|
|
using Yavsc.Abstract.Workflow;
|
|
|
|
|
using Yavsc.Api.Client;
|
|
|
|
|
|
|
|
|
|
namespace PostIt.Tests;
|
|
|
|
|
|
|
|
|
|
public class ActivitiesPageViewModelTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task ActivityApiClient_uses_business_absolute_paths()
|
|
|
|
|
{
|
|
|
|
|
var api = new StubActivityApi();
|
|
|
|
|
var client = new ActivityApiClient(api, "https://business.example/api/v1/");
|
2026-08-31 03:37:09 +01:00
|
|
|
var billingClient = new BillingApiClient(api, "https://business.example/api/v1/");
|
2026-08-30 23:55:09 +01:00
|
|
|
|
|
|
|
|
await client.GetCatalogAsync("brush", TestContext.Current.CancellationToken);
|
2026-08-31 02:14:04 +01:00
|
|
|
await client.GetUsersAsync("brush-pro", TestContext.Current.CancellationToken);
|
2026-08-31 03:37:09 +01:00
|
|
|
await billingClient.CreateAsync("Rdv", new { Foo = "Bar" }, TestContext.Current.CancellationToken);
|
2026-08-31 04:15:10 +01:00
|
|
|
await billingClient.GetQuerySummariesAsync("Rdv", TestContext.Current.CancellationToken);
|
2026-08-30 23:55:09 +01:00
|
|
|
|
|
|
|
|
Assert.Equal("https://business.example/api/v1/activity/catalog?parentCode=brush", api.Paths[0]);
|
2026-08-31 02:14:04 +01:00
|
|
|
Assert.Equal("https://business.example/api/v1/activity/brush-pro/users", api.Paths[1]);
|
2026-08-31 03:37:09 +01:00
|
|
|
Assert.Equal("https://business.example/api/v1/billing/Rdv", api.Paths[2]);
|
2026-08-31 04:15:10 +01:00
|
|
|
Assert.Equal("https://business.example/api/v1/billing/Rdv", api.Paths[3]);
|
2026-08-30 23:55:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task RefreshAsync_loads_first_activity_then_specialization_performers()
|
|
|
|
|
{
|
|
|
|
|
var api = new StubActivityApi();
|
|
|
|
|
var client = new ActivityApiClient(api, "https://business.example/api/v1/");
|
2026-08-31 03:37:09 +01:00
|
|
|
var billingClient = new BillingApiClient(api, "https://business.example/api/v1/");
|
|
|
|
|
var vm = new ActivitiesPageViewModel(client, billingClient);
|
2026-08-30 23:55:09 +01:00
|
|
|
|
|
|
|
|
await vm.RefreshAsync();
|
|
|
|
|
|
|
|
|
|
Assert.Equal("brush", vm.SelectedActivity?.Code);
|
|
|
|
|
Assert.Single(vm.Specializations);
|
|
|
|
|
Assert.Equal("brush", vm.CurrentActivity?.Code);
|
|
|
|
|
Assert.Single(vm.Performers);
|
|
|
|
|
Assert.Equal("Alice", vm.Performers[0].UserName);
|
2026-08-31 02:14:04 +01:00
|
|
|
Assert.True(vm.Performers[0].HasPerformerProfile);
|
|
|
|
|
Assert.True(vm.Performers[0].IsPerformerActive);
|
|
|
|
|
Assert.Equal("Actif", vm.Performers[0].PerformerStatusBadgeLabel);
|
|
|
|
|
Assert.Equal("Pas d'autre activité", vm.Performers[0].ExtraActivityLabel);
|
2026-08-30 23:55:09 +01:00
|
|
|
|
|
|
|
|
await vm.ShowSpecializationAsync(vm.Specializations[0]);
|
|
|
|
|
|
|
|
|
|
Assert.Equal("brush-pro", vm.CurrentActivity?.Code);
|
|
|
|
|
Assert.Single(vm.Performers);
|
|
|
|
|
Assert.Equal("Bob", vm.Performers[0].UserName);
|
2026-08-31 02:14:04 +01:00
|
|
|
Assert.True(vm.Performers[0].HasPerformerProfile);
|
|
|
|
|
Assert.False(vm.Performers[0].IsPerformerActive);
|
|
|
|
|
Assert.Equal("Inactif", vm.Performers[0].PerformerStatusBadgeLabel);
|
|
|
|
|
Assert.Equal("Autres spécialisations: 2", vm.Performers[0].ExtraActivityLabel);
|
2026-08-30 23:55:09 +01:00
|
|
|
Assert.Contains("brush pro", vm.StatusMessage, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
await vm.ShowSpecializationAsync(null);
|
|
|
|
|
|
|
|
|
|
Assert.Equal("brush", vm.CurrentActivity?.Code);
|
|
|
|
|
Assert.Single(vm.Performers);
|
|
|
|
|
Assert.Equal("Alice", vm.Performers[0].UserName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private sealed class StubActivityApi : IYavscApiClient
|
|
|
|
|
{
|
|
|
|
|
public HttpClient Http { get; } = new();
|
|
|
|
|
public List<string> Paths { get; } = new();
|
|
|
|
|
|
|
|
|
|
public Task<T> CallAsync<T>(HttpMethod method, string path, object? body = null, CancellationToken ct = default)
|
|
|
|
|
{
|
|
|
|
|
Paths.Add(path);
|
|
|
|
|
|
2026-09-02 14:52:17 +01:00
|
|
|
if (typeof(T) == typeof(List<ActivityInfo>))
|
2026-08-30 23:55:09 +01:00
|
|
|
{
|
2026-09-02 14:52:17 +01:00
|
|
|
var activities = new List<ActivityInfo>
|
2026-08-30 23:55:09 +01:00
|
|
|
{
|
|
|
|
|
new()
|
|
|
|
|
{
|
|
|
|
|
Code = "brush",
|
|
|
|
|
Name = "Brush",
|
|
|
|
|
Description = "Coiffure à domicile",
|
|
|
|
|
PerformerCount = 1,
|
2026-09-02 14:52:17 +01:00
|
|
|
Forms = new List<CommandFormSummary>
|
2026-08-31 03:37:09 +01:00
|
|
|
{
|
|
|
|
|
new() { Id = 1, ActionName = "Rdv", Title = "Rendez-vous" }
|
|
|
|
|
},
|
2026-09-02 14:52:17 +01:00
|
|
|
Children = new List<ActivityInfo>
|
2026-08-30 23:55:09 +01:00
|
|
|
{
|
|
|
|
|
new()
|
|
|
|
|
{
|
|
|
|
|
Code = "brush-pro",
|
|
|
|
|
Name = "Brush Pro",
|
|
|
|
|
Description = "Spécialisation premium",
|
|
|
|
|
ParentCode = "brush",
|
|
|
|
|
PerformerCount = 1,
|
2026-09-02 14:52:17 +01:00
|
|
|
Forms = new List<CommandFormSummary>
|
2026-08-31 03:37:09 +01:00
|
|
|
{
|
|
|
|
|
new() { Id = 2, ActionName = "Rdv", Title = "Rendez-vous premium" }
|
|
|
|
|
}
|
2026-08-30 23:55:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return Task.FromResult((T)(object)activities);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-02 14:52:17 +01:00
|
|
|
if (typeof(T) == typeof(List<PerformerActivity>))
|
2026-08-30 23:55:09 +01:00
|
|
|
{
|
2026-08-31 02:14:04 +01:00
|
|
|
var performers = path.EndsWith("brush-pro/users", StringComparison.Ordinal)
|
2026-09-02 14:52:17 +01:00
|
|
|
? new List<PerformerActivity>
|
2026-08-30 23:55:09 +01:00
|
|
|
{
|
2026-08-31 02:14:04 +01:00
|
|
|
new() { PerformerId = "pro-2", HasPerformerProfile = true, Active = false, UserName = "Bob", ActivityCode = "brush-pro", ActivityName = "Brush Pro", ExtraActivityCount = 2 }
|
2026-08-30 23:55:09 +01:00
|
|
|
}
|
2026-09-02 14:52:17 +01:00
|
|
|
: new List<PerformerActivity>
|
2026-08-30 23:55:09 +01:00
|
|
|
{
|
2026-08-31 02:14:04 +01:00
|
|
|
new() { PerformerId = "pro-1", HasPerformerProfile = true, Active = true, UserName = "Alice", ActivityCode = "brush", ActivityName = "Brush", ExtraActivityCount = 0 }
|
2026-08-30 23:55:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return Task.FromResult((T)(object)performers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.FromResult(default(T)!);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task CallAsync(HttpMethod method, string path, object? body = null, CancellationToken ct = default)
|
|
|
|
|
{
|
|
|
|
|
Paths.Add(path);
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|