feature: Draft Data Entry
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
|
||||
public static class AuthHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Logs in as the given user and returns an HttpClient with the JWT
|
||||
/// Authorization header pre-configured. Login also returns a refresh token;
|
||||
/// integration tests use the access token only.
|
||||
/// </summary>
|
||||
public static async Task<HttpClient> LoginAsync(
|
||||
ApiFixture fixture, string username = "entry1", string password = "password")
|
||||
{
|
||||
var client = fixture.CreateClient();
|
||||
|
||||
var loginResp = await client.PostAsJsonAsync("/api/v1/auth/login",
|
||||
new { username, password });
|
||||
|
||||
loginResp.EnsureSuccessStatusCode();
|
||||
|
||||
var body = await loginResp.Content.ReadFromJsonAsync<JsonDocument>();
|
||||
var token = body!.RootElement.GetProperty("data").GetProperty("token").GetString()!;
|
||||
|
||||
client.DefaultRequestHeaders.Authorization =
|
||||
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||
|
||||
return client;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
public static class DbResetHelper
|
||||
{
|
||||
// Truncate all data between tests — faster than dropping and re-creating
|
||||
// the database, and preserves the schema (migrations do not re-run).
|
||||
public static async Task ResetAsync(AppDbContext db)
|
||||
{
|
||||
await db.Database.ExecuteSqlRawAsync(@"
|
||||
TRUNCATE TABLE digitization_events, draft_observations,
|
||||
draft_encounters, draft_patients,
|
||||
scanned_documents, digitization_batches, users
|
||||
RESTART IDENTITY CASCADE;
|
||||
");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user