1
//! Shared fixtures for the end-to-end form suites (`list_accounts` and its siblings).
2

            
3
use sqlx::PgPool;
4
use uuid::Uuid;
5

            
6
/// The hook `local_db_sqlx_test` calls before each test body.
7
972
pub async fn setup() {}
8

            
9
/// A verified user: the SSH-key write commands refuse a disabled account.
10
972
pub async fn insert_test_user(pool: &PgPool, id: Uuid) -> sqlx::Result<()> {
11
972
    sqlx::query(
12
972
        "INSERT INTO users (
13
972
            id, user_name, email, photo, verified, user_password,
14
972
            user_role, database_name, created_at
15
972
        ) VALUES (
16
972
            $1, 'rpc-test-user', $1::text || '@example.com', 'default.png',
17
972
            TRUE, 'irrelevant', 'user', 'rpc-test', NOW()
18
972
        )",
19
972
    )
20
972
    .bind(id)
21
972
    .execute(pool)
22
972
    .await?;
23
972
    Ok(())
24
972
}
25

            
26
/// The uuid a single-record write returns as `:value "<uuid>"`.
27
#[must_use]
28
810
pub fn extract_id_field(response: &str, _key: &str) -> Option<String> {
29
810
    let needle = ":value \"";
30
810
    let start = response.find(needle)? + needle.len();
31
810
    let end = start + response[start..].find('"')?;
32
810
    Some(response[start..end].to_string())
33
810
}