61 lines
2.1 KiB
C#
61 lines
2.1 KiB
C#
// Probe pour vérifier le status API de l'opération E2E.
|
|
// Génère un token via ITokenService (même mécanisme que le test E2E),
|
|
// puis appelle GET /api/sync/status/{operationId}.
|
|
using System.Net.Http.Headers;
|
|
using System.Text.Json;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Omika.Core.Configuration;
|
|
using Omika.Core.Interfaces.Mobile;
|
|
using Omika.Core.Services.Mobile;
|
|
|
|
const string operationId = "5b915439-d9d9-44b5-9552-1f8f90db96c3";
|
|
const string apiBaseUrl = "http://localhost:5097";
|
|
|
|
// Construire la configuration avec la clé de signature.
|
|
var config = new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["MobileAuth:SigningKey"] = "test-signing-key-for-integration-tests-only"
|
|
})
|
|
.Build();
|
|
|
|
var services = new ServiceCollection();
|
|
services.AddSingleton<IConfiguration>(config);
|
|
services.AddOptions<MobileAuthOptions>()
|
|
.Configure<IConfiguration>((options, configuration) =>
|
|
configuration.GetSection(MobileAuthOptions.SectionName).Bind(options));
|
|
services.AddSingleton<ITokenService, TokenService>();
|
|
var provider = services.BuildServiceProvider();
|
|
|
|
var tokenService = provider.GetRequiredService<ITokenService>();
|
|
string token = tokenService.GenerateToken(new MobileTokenIdentity
|
|
{
|
|
CodeClient = "E2E_TEST",
|
|
DeviceId = "e2e-device-001",
|
|
UserId = "e2e-user-001",
|
|
CollaborateurId = "1",
|
|
NumeroLicence = "e2e-licence-test"
|
|
});
|
|
|
|
Console.WriteLine($"Token généré: {token[..Math.Min(40, token.Length)]}...");
|
|
|
|
using var client = new HttpClient();
|
|
client.BaseAddress = new Uri(apiBaseUrl);
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
|
|
Console.WriteLine($"\n=== GET /api/sync/status/{operationId} ===");
|
|
try
|
|
{
|
|
var response = await client.GetAsync($"/api/sync/status/{operationId}");
|
|
Console.WriteLine($"HTTP {(int)response.StatusCode} {response.StatusCode}");
|
|
string body = await response.Content.ReadAsStringAsync();
|
|
Console.WriteLine($"Body: {body}");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"ERREUR: {ex.Message}");
|
|
}
|
|
|
|
Console.WriteLine("\nProbe status terminé.");
|