Replace literal SQL with Diesel abstractions
This commit is contained in:
@@ -1,335 +1,130 @@
|
||||
//! Integration tests that open the real fixture DB extracted from the TypeScript bDS app
|
||||
//! and verify every table can be read correctly into Rust model structs.
|
||||
//!
|
||||
//! This validates the compatibility contract: the Rust app MUST read databases
|
||||
//! created by the TypeScript app without modification.
|
||||
//! Verify that the Rust Diesel models read the compatibility fixture produced by bDS.
|
||||
|
||||
use rusqlite::{Connection, OpenFlags};
|
||||
use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn fixture_db() -> Connection {
|
||||
use bds_core::db::Database;
|
||||
use bds_core::db::queries::{
|
||||
media, post, post_link, post_media, post_translation, project, script, setting, tag, template,
|
||||
};
|
||||
use bds_core::db::schema::{ai_catalog_meta, ai_models, ai_providers};
|
||||
use bds_core::model::{ScriptKind, ScriptStatus, TemplateKind, TemplateStatus};
|
||||
use diesel::prelude::*;
|
||||
|
||||
const PROJECT_ID: &str = "1979237c-034d-41f6-99a0-f35eb57b3f6c";
|
||||
const ESMERALDA_ID: &str = "40a83ab1-423d-4310-aac4-642d84675007";
|
||||
const GHOSTTY_ID: &str = "6745981d-da41-4cfd-80ec-95ad339acf6f";
|
||||
const CMUX_ID: &str = "2665bfaa-8251-468d-a710-a4cf34dd81e2";
|
||||
const SPIDER_ID: &str = "eb0cf9d7-6fbd-4b74-9be3-759d6e16f240";
|
||||
|
||||
fn fixture_db() -> Database {
|
||||
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../../fixtures/compatibility-projects/rfc1437-sample/bds.db");
|
||||
assert!(path.exists(), "fixture DB not found at {}", path.display());
|
||||
Connection::open_with_flags(&path, OpenFlags::SQLITE_OPEN_READ_ONLY).unwrap()
|
||||
Database::open(&path).unwrap()
|
||||
}
|
||||
|
||||
const PROJECT_ID: &str = "1979237c-034d-41f6-99a0-f35eb57b3f6c";
|
||||
|
||||
// ── Project ─────────────────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn read_project() {
|
||||
let conn = fixture_db();
|
||||
let (id, name, slug, data_path, is_active): (String, String, String, String, bool) = conn
|
||||
.query_row(
|
||||
"SELECT id, name, slug, data_path, is_active FROM projects WHERE id = ?1",
|
||||
[PROJECT_ID],
|
||||
|row| {
|
||||
Ok((
|
||||
row.get(0)?,
|
||||
row.get(1)?,
|
||||
row.get(2)?,
|
||||
row.get(3)?,
|
||||
row.get(4)?,
|
||||
))
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(id, PROJECT_ID);
|
||||
assert_eq!(name, "rfc1437");
|
||||
assert_eq!(slug, "rfc1437");
|
||||
assert!(data_path.contains("rfc1437.de"));
|
||||
assert!(is_active);
|
||||
let db = fixture_db();
|
||||
let value = project::get_project_by_id(db.conn(), PROJECT_ID).unwrap();
|
||||
assert_eq!(value.name, "rfc1437");
|
||||
assert_eq!(value.slug, "rfc1437");
|
||||
assert!(value.data_path.unwrap().contains("rfc1437.de"));
|
||||
assert!(value.is_active);
|
||||
}
|
||||
|
||||
// ── Posts ────────────────────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn read_published_post_has_null_content() {
|
||||
let conn = fixture_db();
|
||||
let (title, slug, status, content): (String, String, String, Option<String>) = conn
|
||||
.query_row(
|
||||
"SELECT title, slug, status, content FROM posts WHERE slug = 'esmeralda'",
|
||||
[],
|
||||
|row| Ok((row.get(0)?, row.get(1)?, row.get(2)?, row.get(3)?)),
|
||||
)
|
||||
fn posts_are_compatible() {
|
||||
let db = fixture_db();
|
||||
let posts = post::list_posts_by_project(db.conn(), PROJECT_ID).unwrap();
|
||||
assert_eq!(posts.len(), 4);
|
||||
let published = posts.iter().find(|post| post.slug == "esmeralda").unwrap();
|
||||
assert_eq!(published.title, "Esmeralda");
|
||||
assert_eq!(published.status, bds_core::model::PostStatus::Published);
|
||||
assert!(published.content.is_none());
|
||||
assert!(!published.tags.is_empty());
|
||||
assert!(published.created_at > 946_684_800);
|
||||
assert!(published.updated_at > 946_684_800);
|
||||
let draft = posts
|
||||
.iter()
|
||||
.find(|post| post.slug == "draft-fixture-post")
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(title, "Esmeralda");
|
||||
assert_eq!(slug, "esmeralda");
|
||||
assert_eq!(status, "published");
|
||||
assert!(draft.content.as_deref().unwrap().contains("**body**"));
|
||||
assert!(
|
||||
content.is_none(),
|
||||
"published posts must have NULL content in DB"
|
||||
posts
|
||||
.iter()
|
||||
.filter(|post| post.status == bds_core::model::PostStatus::Published)
|
||||
.all(|post| !post.file_path.is_empty()
|
||||
&& post.file_path.ends_with(&format!("{}.md", post.slug)))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_draft_post_has_content() {
|
||||
let conn = fixture_db();
|
||||
let (title, slug, status, content): (String, String, String, Option<String>) = conn
|
||||
.query_row(
|
||||
"SELECT title, slug, status, content FROM posts WHERE slug = 'draft-fixture-post'",
|
||||
[],
|
||||
|row| Ok((row.get(0)?, row.get(1)?, row.get(2)?, row.get(3)?)),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(title, "Draft Fixture Post");
|
||||
assert_eq!(slug, "draft-fixture-post");
|
||||
assert_eq!(status, "draft");
|
||||
assert!(content.is_some(), "draft posts must have content in DB");
|
||||
assert!(content.unwrap().contains("**body**"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_all_posts_count() {
|
||||
let conn = fixture_db();
|
||||
let count: i64 = conn
|
||||
.query_row("SELECT COUNT(*) FROM posts", [], |row| row.get(0))
|
||||
.unwrap();
|
||||
assert_eq!(count, 4); // 3 published + 1 draft
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn published_posts_have_file_paths() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT slug, file_path FROM posts WHERE status = 'published'")
|
||||
.unwrap();
|
||||
let rows: Vec<(String, String)> = stmt
|
||||
.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
let unique: HashSet<_> = posts
|
||||
.iter()
|
||||
.map(|post| (&post.project_id, &post.slug))
|
||||
.collect();
|
||||
|
||||
assert_eq!(rows.len(), 3);
|
||||
for (slug, path) in &rows {
|
||||
assert!(
|
||||
!path.is_empty(),
|
||||
"published post '{slug}' must have a file_path"
|
||||
);
|
||||
assert!(
|
||||
path.ends_with(&format!("{slug}.md")),
|
||||
"file_path must end with {slug}.md"
|
||||
);
|
||||
}
|
||||
assert_eq!(unique.len(), posts.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn post_tags_are_json_arrays() {
|
||||
let conn = fixture_db();
|
||||
let tags_json: Option<String> = conn
|
||||
.query_row(
|
||||
"SELECT tags FROM posts WHERE slug = 'esmeralda'",
|
||||
[],
|
||||
|row| row.get(0),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
if let Some(json) = tags_json {
|
||||
let parsed: Vec<String> = serde_json::from_str(&json).unwrap();
|
||||
assert!(!parsed.is_empty());
|
||||
}
|
||||
// tags can also be NULL — both are valid
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn post_timestamps_are_unix_integers() {
|
||||
let conn = fixture_db();
|
||||
let (created_at, updated_at): (i64, i64) = conn
|
||||
.query_row(
|
||||
"SELECT created_at, updated_at FROM posts WHERE slug = 'esmeralda'",
|
||||
[],
|
||||
|row| Ok((row.get(0)?, row.get(1)?)),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Sanity: timestamps should be in reasonable Unix range (year 2000+)
|
||||
assert!(
|
||||
created_at > 946_684_800,
|
||||
"created_at should be after year 2000"
|
||||
);
|
||||
assert!(
|
||||
updated_at > 946_684_800,
|
||||
"updated_at should be after year 2000"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn post_unique_constraint_on_project_slug() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT project_id, slug, COUNT(*) FROM posts GROUP BY project_id, slug HAVING COUNT(*) > 1")
|
||||
.unwrap();
|
||||
let dupes: Vec<(String, String, i64)> = stmt
|
||||
.query_map([], |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
|
||||
assert!(
|
||||
dupes.is_empty(),
|
||||
"found duplicate (project_id, slug) pairs: {dupes:?}"
|
||||
);
|
||||
}
|
||||
|
||||
// ── Post Translations ───────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn read_post_translations() {
|
||||
let conn = fixture_db();
|
||||
let count: i64 = conn
|
||||
.query_row("SELECT COUNT(*) FROM post_translations", [], |row| {
|
||||
row.get(0)
|
||||
fn post_translations_are_compatible() {
|
||||
let db = fixture_db();
|
||||
let posts = post::list_posts_by_project(db.conn(), PROJECT_ID).unwrap();
|
||||
let translations: Vec<_> = posts
|
||||
.iter()
|
||||
.flat_map(|post| {
|
||||
post_translation::list_post_translations_by_post(db.conn(), &post.id).unwrap()
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(count, 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn translation_references_valid_post() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn
|
||||
.prepare(
|
||||
"SELECT pt.id, pt.translation_for FROM post_translations pt \
|
||||
LEFT JOIN posts p ON pt.translation_for = p.id \
|
||||
WHERE p.id IS NULL",
|
||||
)
|
||||
.unwrap();
|
||||
let orphans: Vec<(String, String)> = stmt
|
||||
.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
|
||||
assert_eq!(translations.len(), 4);
|
||||
assert!(
|
||||
orphans.is_empty(),
|
||||
"orphan translations referencing missing posts: {orphans:?}"
|
||||
translations
|
||||
.iter()
|
||||
.filter(|translation| translation.status == bds_core::model::PostStatus::Published)
|
||||
.all(|translation| translation.content.is_none())
|
||||
);
|
||||
let post_ids: HashSet<_> = posts.iter().map(|post| post.id.as_str()).collect();
|
||||
assert!(
|
||||
translations
|
||||
.iter()
|
||||
.all(|translation| post_ids.contains(translation.translation_for.as_str()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn published_translations_have_null_content() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT id, content FROM post_translations WHERE status = 'published'")
|
||||
.unwrap();
|
||||
let rows: Vec<(String, Option<String>)> = stmt
|
||||
.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
|
||||
for (id, content) in &rows {
|
||||
assert!(
|
||||
content.is_none(),
|
||||
"published translation {id} must have NULL content"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Post Links ──────────────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn read_post_links() {
|
||||
let conn = fixture_db();
|
||||
let (source, target, text): (String, String, Option<String>) = conn
|
||||
.query_row(
|
||||
"SELECT source_post_id, target_post_id, link_text FROM post_links LIMIT 1",
|
||||
[],
|
||||
|row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// ghostty links to cmux
|
||||
assert_eq!(source, "6745981d-da41-4cfd-80ec-95ad339acf6f");
|
||||
assert_eq!(target, "2665bfaa-8251-468d-a710-a4cf34dd81e2");
|
||||
assert!(text.is_some());
|
||||
}
|
||||
|
||||
// ── Post Media ──────────────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn read_post_media() {
|
||||
let conn = fixture_db();
|
||||
let (post_id, media_id, sort_order): (String, String, i32) = conn
|
||||
.query_row(
|
||||
"SELECT post_id, media_id, sort_order FROM post_media LIMIT 1",
|
||||
[],
|
||||
|row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// esmeralda <-> spider photo
|
||||
assert_eq!(post_id, "40a83ab1-423d-4310-aac4-642d84675007");
|
||||
assert_eq!(media_id, "eb0cf9d7-6fbd-4b74-9be3-759d6e16f240");
|
||||
assert_eq!(sort_order, 0);
|
||||
}
|
||||
|
||||
// ── Media ───────────────────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn read_media() {
|
||||
let conn = fixture_db();
|
||||
let (id, filename, original_name, mime_type, title, alt): (
|
||||
String,
|
||||
String,
|
||||
String,
|
||||
String,
|
||||
Option<String>,
|
||||
Option<String>,
|
||||
) = conn
|
||||
.query_row(
|
||||
"SELECT id, filename, original_name, mime_type, title, alt FROM media LIMIT 1",
|
||||
[],
|
||||
|row| {
|
||||
Ok((
|
||||
row.get(0)?,
|
||||
row.get(1)?,
|
||||
row.get(2)?,
|
||||
row.get(3)?,
|
||||
row.get(4)?,
|
||||
row.get(5)?,
|
||||
))
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(id, "eb0cf9d7-6fbd-4b74-9be3-759d6e16f240");
|
||||
assert!(filename.ends_with(".jpg"));
|
||||
assert_eq!(original_name, "CRW_1121.jpg");
|
||||
assert_eq!(mime_type, "image/jpeg");
|
||||
assert!(title.is_some());
|
||||
assert!(alt.is_some());
|
||||
}
|
||||
|
||||
// ── Tags ────────────────────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn read_tags() {
|
||||
let conn = fixture_db();
|
||||
let count: i64 = conn
|
||||
.query_row("SELECT COUNT(*) FROM tags", [], |row| row.get(0))
|
||||
.unwrap();
|
||||
assert_eq!(count, 5);
|
||||
fn relationships_are_compatible() {
|
||||
let db = fixture_db();
|
||||
let links = post_link::list_links_by_source(db.conn(), GHOSTTY_ID).unwrap();
|
||||
assert!(
|
||||
links
|
||||
.iter()
|
||||
.any(|link| link.target_post_id == CMUX_ID && link.link_text.is_some())
|
||||
);
|
||||
let media_links = post_media::list_post_media_by_post(db.conn(), ESMERALDA_ID).unwrap();
|
||||
assert!(
|
||||
media_links
|
||||
.iter()
|
||||
.any(|link| link.media_id == SPIDER_ID && link.sort_order == 0)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tag_names_are_expected() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn.prepare("SELECT name FROM tags ORDER BY name").unwrap();
|
||||
let names: Vec<String> = stmt
|
||||
.query_map([], |row| row.get(0))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
fn media_is_compatible() {
|
||||
let db = fixture_db();
|
||||
let item = media::get_media_by_id(db.conn(), SPIDER_ID).unwrap();
|
||||
assert!(item.filename.ends_with(".jpg"));
|
||||
assert_eq!(item.original_name, "CRW_1121.jpg");
|
||||
assert_eq!(item.mime_type, "image/jpeg");
|
||||
assert!(item.title.is_some());
|
||||
assert!(item.alt.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tags_are_compatible() {
|
||||
let db = fixture_db();
|
||||
let tags = tag::list_tags_by_project(db.conn(), PROJECT_ID).unwrap();
|
||||
assert_eq!(
|
||||
names,
|
||||
vec![
|
||||
tags.iter().map(|tag| tag.name.as_str()).collect::<Vec<_>>(),
|
||||
[
|
||||
"fotografie",
|
||||
"mac-os-x",
|
||||
"natur",
|
||||
@@ -337,292 +132,106 @@ fn tag_names_are_expected() {
|
||||
"sysadmin"
|
||||
]
|
||||
);
|
||||
let unique: HashSet<_> = tags.iter().map(|tag| tag.name.to_lowercase()).collect();
|
||||
assert_eq!(unique.len(), tags.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tag_unique_constraint_on_project_name() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT project_id, name, COUNT(*) FROM tags GROUP BY project_id, name HAVING COUNT(*) > 1")
|
||||
.unwrap();
|
||||
let dupes: Vec<(String, String, i64)> = stmt
|
||||
.query_map([], |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
|
||||
assert!(
|
||||
dupes.is_empty(),
|
||||
"found duplicate (project_id, name) tag pairs: {dupes:?}"
|
||||
);
|
||||
}
|
||||
|
||||
// ── Templates ───────────────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn read_template() {
|
||||
let conn = fixture_db();
|
||||
let (slug, title, kind, enabled, status, content): (
|
||||
String,
|
||||
String,
|
||||
String,
|
||||
bool,
|
||||
String,
|
||||
Option<String>,
|
||||
) = conn
|
||||
.query_row(
|
||||
"SELECT slug, title, kind, enabled, status, content FROM templates LIMIT 1",
|
||||
[],
|
||||
|row| {
|
||||
Ok((
|
||||
row.get(0)?,
|
||||
row.get(1)?,
|
||||
row.get(2)?,
|
||||
row.get(3)?,
|
||||
row.get(4)?,
|
||||
row.get(5)?,
|
||||
))
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(slug, "testvorlage");
|
||||
assert_eq!(title, "Testvorlage");
|
||||
assert_eq!(kind, "post");
|
||||
assert!(enabled);
|
||||
assert_eq!(status, "published");
|
||||
assert!(
|
||||
content.is_none(),
|
||||
"published template content should be NULL in DB"
|
||||
);
|
||||
}
|
||||
|
||||
// ── Scripts ─────────────────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn read_scripts() {
|
||||
let conn = fixture_db();
|
||||
let count: i64 = conn
|
||||
.query_row("SELECT COUNT(*) FROM scripts", [], |row| row.get(0))
|
||||
.unwrap();
|
||||
assert_eq!(count, 2);
|
||||
fn templates_are_compatible() {
|
||||
let db = fixture_db();
|
||||
let templates = template::list_templates_by_project(db.conn(), PROJECT_ID).unwrap();
|
||||
let value = templates.first().unwrap();
|
||||
assert_eq!(value.slug, "testvorlage");
|
||||
assert_eq!(value.title, "Testvorlage");
|
||||
assert_eq!(value.kind, TemplateKind::Post);
|
||||
assert!(value.enabled);
|
||||
assert_eq!(value.status, TemplateStatus::Published);
|
||||
assert!(value.content.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_script_fields() {
|
||||
let conn = fixture_db();
|
||||
let (slug, title, kind, entrypoint, enabled, status): (
|
||||
String,
|
||||
String,
|
||||
String,
|
||||
String,
|
||||
bool,
|
||||
String,
|
||||
) = conn
|
||||
.query_row(
|
||||
"SELECT slug, title, kind, entrypoint, enabled, status FROM scripts WHERE slug = 'bgg_link'",
|
||||
[],
|
||||
|row| {
|
||||
Ok((
|
||||
row.get(0)?,
|
||||
row.get(1)?,
|
||||
row.get(2)?,
|
||||
row.get(3)?,
|
||||
row.get(4)?,
|
||||
row.get(5)?,
|
||||
))
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(slug, "bgg_link");
|
||||
assert_eq!(title, "bgg link");
|
||||
assert_eq!(kind, "transform");
|
||||
assert_eq!(entrypoint, "normalize_blogmark");
|
||||
assert!(enabled);
|
||||
assert_eq!(status, "published");
|
||||
}
|
||||
|
||||
// ── Settings ────────────────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn read_settings() {
|
||||
let conn = fixture_db();
|
||||
let count: i64 = conn
|
||||
.query_row("SELECT COUNT(*) FROM settings", [], |row| row.get(0))
|
||||
.unwrap();
|
||||
assert_eq!(count, 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settings_are_key_value_pairs() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn.prepare("SELECT key, value FROM settings").unwrap();
|
||||
let pairs: Vec<(String, String)> = stmt
|
||||
.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
|
||||
for (key, value) in &pairs {
|
||||
assert!(!key.is_empty());
|
||||
assert!(!value.is_empty());
|
||||
}
|
||||
// All setting keys should contain the project ID (namespaced)
|
||||
let project_keys: Vec<_> = pairs
|
||||
fn scripts_are_compatible() {
|
||||
let db = fixture_db();
|
||||
let scripts = script::list_scripts_by_project(db.conn(), PROJECT_ID).unwrap();
|
||||
assert_eq!(scripts.len(), 2);
|
||||
let value = scripts
|
||||
.iter()
|
||||
.filter(|(k, _)| k.contains(PROJECT_ID))
|
||||
.collect();
|
||||
assert_eq!(project_keys.len(), 5);
|
||||
.find(|script| script.slug == "bgg_link")
|
||||
.unwrap();
|
||||
assert_eq!(value.title, "bgg link");
|
||||
assert_eq!(value.kind, ScriptKind::Transform);
|
||||
assert_eq!(value.entrypoint, "normalize_blogmark");
|
||||
assert!(value.enabled);
|
||||
assert_eq!(value.status, ScriptStatus::Published);
|
||||
}
|
||||
|
||||
// ── AI Catalog ──────────────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn read_ai_tables() {
|
||||
let conn = fixture_db();
|
||||
|
||||
let providers: i64 = conn
|
||||
.query_row("SELECT COUNT(*) FROM ai_providers", [], |row| row.get(0))
|
||||
.unwrap();
|
||||
let models: i64 = conn
|
||||
.query_row("SELECT COUNT(*) FROM ai_models", [], |row| row.get(0))
|
||||
.unwrap();
|
||||
let meta: i64 = conn
|
||||
.query_row("SELECT COUNT(*) FROM ai_catalog_meta", [], |row| row.get(0))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(providers, 1);
|
||||
assert_eq!(models, 1);
|
||||
assert_eq!(meta, 2);
|
||||
}
|
||||
|
||||
// ── Generated File Hashes ───────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn read_generated_file_hashes_via_settings() {
|
||||
// The fixture stores generation hashes as settings keys
|
||||
let conn = fixture_db();
|
||||
let count: i64 = conn
|
||||
.query_row(
|
||||
"SELECT COUNT(*) FROM settings WHERE key LIKE '%generation-hash%'",
|
||||
[],
|
||||
|row| row.get(0),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(count > 0, "expected generation hash entries in settings");
|
||||
}
|
||||
|
||||
// ── Cross-table referential integrity ───────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn all_posts_belong_to_existing_project() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn
|
||||
.prepare(
|
||||
"SELECT p.id FROM posts p \
|
||||
LEFT JOIN projects pr ON p.project_id = pr.id \
|
||||
WHERE pr.id IS NULL",
|
||||
)
|
||||
.unwrap();
|
||||
let orphans: Vec<String> = stmt
|
||||
.query_map([], |row| row.get(0))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
|
||||
fn settings_are_compatible() {
|
||||
let db = fixture_db();
|
||||
let settings = setting::list_all_settings(db.conn()).unwrap();
|
||||
assert_eq!(settings.len(), 5);
|
||||
assert!(settings.iter().all(|setting| !setting.key.is_empty()
|
||||
&& !setting.value.is_empty()
|
||||
&& setting.key.contains(PROJECT_ID)));
|
||||
assert!(
|
||||
orphans.is_empty(),
|
||||
"posts referencing missing projects: {orphans:?}"
|
||||
settings
|
||||
.iter()
|
||||
.any(|setting| setting.key.contains("generation-hash"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_tags_belong_to_existing_project() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn
|
||||
.prepare(
|
||||
"SELECT t.id FROM tags t \
|
||||
LEFT JOIN projects pr ON t.project_id = pr.id \
|
||||
WHERE pr.id IS NULL",
|
||||
)
|
||||
fn ai_catalog_is_compatible() {
|
||||
let db = fixture_db();
|
||||
let (providers, models, meta) = db
|
||||
.conn()
|
||||
.with(|conn| {
|
||||
Ok((
|
||||
ai_providers::table.count().get_result::<i64>(conn)?,
|
||||
ai_models::table.count().get_result::<i64>(conn)?,
|
||||
ai_catalog_meta::table.count().get_result::<i64>(conn)?,
|
||||
))
|
||||
})
|
||||
.unwrap();
|
||||
let orphans: Vec<String> = stmt
|
||||
.query_map([], |row| row.get(0))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
|
||||
assert!(
|
||||
orphans.is_empty(),
|
||||
"tags referencing missing projects: {orphans:?}"
|
||||
);
|
||||
assert_eq!((providers, models, meta), (1, 1, 2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_media_belong_to_existing_project() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn
|
||||
.prepare(
|
||||
"SELECT m.id FROM media m \
|
||||
LEFT JOIN projects pr ON m.project_id = pr.id \
|
||||
WHERE pr.id IS NULL",
|
||||
)
|
||||
.unwrap();
|
||||
let orphans: Vec<String> = stmt
|
||||
.query_map([], |row| row.get(0))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
|
||||
fn relationships_reference_existing_entities() {
|
||||
let db = fixture_db();
|
||||
let projects = project::list_projects(db.conn()).unwrap();
|
||||
let project_ids: HashSet<_> = projects.iter().map(|project| project.id.as_str()).collect();
|
||||
let posts = post::list_posts_by_project(db.conn(), PROJECT_ID).unwrap();
|
||||
let post_ids: HashSet<_> = posts.iter().map(|post| post.id.as_str()).collect();
|
||||
let media = media::list_media_by_project(db.conn(), PROJECT_ID).unwrap();
|
||||
let media_ids: HashSet<_> = media.iter().map(|media| media.id.as_str()).collect();
|
||||
let tags = tag::list_tags_by_project(db.conn(), PROJECT_ID).unwrap();
|
||||
assert!(
|
||||
orphans.is_empty(),
|
||||
"media referencing missing projects: {orphans:?}"
|
||||
posts
|
||||
.iter()
|
||||
.all(|post| project_ids.contains(post.project_id.as_str()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn post_links_reference_valid_posts() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn
|
||||
.prepare(
|
||||
"SELECT pl.id, pl.source_post_id, pl.target_post_id FROM post_links pl \
|
||||
LEFT JOIN posts s ON pl.source_post_id = s.id \
|
||||
LEFT JOIN posts t ON pl.target_post_id = t.id \
|
||||
WHERE s.id IS NULL OR t.id IS NULL",
|
||||
)
|
||||
.unwrap();
|
||||
let orphans: Vec<(String, String, String)> = stmt
|
||||
.query_map([], |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
|
||||
assert!(
|
||||
orphans.is_empty(),
|
||||
"post_links with invalid references: {orphans:?}"
|
||||
media
|
||||
.iter()
|
||||
.all(|media| project_ids.contains(media.project_id.as_str()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn post_media_references_valid_entities() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn
|
||||
.prepare(
|
||||
"SELECT pm.id FROM post_media pm \
|
||||
LEFT JOIN posts p ON pm.post_id = p.id \
|
||||
LEFT JOIN media m ON pm.media_id = m.id \
|
||||
WHERE p.id IS NULL OR m.id IS NULL",
|
||||
)
|
||||
.unwrap();
|
||||
let orphans: Vec<String> = stmt
|
||||
.query_map([], |row| row.get(0))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
|
||||
assert!(
|
||||
orphans.is_empty(),
|
||||
"post_media with invalid references: {orphans:?}"
|
||||
tags.iter()
|
||||
.all(|tag| project_ids.contains(tag.project_id.as_str()))
|
||||
);
|
||||
for post in &posts {
|
||||
assert!(
|
||||
post_link::list_links_by_source(db.conn(), &post.id)
|
||||
.unwrap()
|
||||
.iter()
|
||||
.all(|link| post_ids.contains(link.target_post_id.as_str()))
|
||||
);
|
||||
assert!(
|
||||
post_media::list_post_media_by_post(db.conn(), &post.id)
|
||||
.unwrap()
|
||||
.iter()
|
||||
.all(|link| media_ids.contains(link.media_id.as_str()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ fn make_test_project(id: &str, slug: &str) -> Project {
|
||||
}
|
||||
|
||||
fn setup() -> (Database, TempDir) {
|
||||
let mut db = Database::open_in_memory().unwrap();
|
||||
let db = Database::open_in_memory().unwrap();
|
||||
db.migrate().unwrap();
|
||||
ensure_fts_tables(db.conn()).unwrap();
|
||||
insert_project(db.conn(), &make_test_project("p1", "blog")).unwrap();
|
||||
|
||||
@@ -89,7 +89,7 @@ fn make_list_template(slug: &str, content: &str) -> Template {
|
||||
}
|
||||
|
||||
fn setup() -> (Database, TempDir) {
|
||||
let mut db = Database::open_in_memory().unwrap();
|
||||
let db = Database::open_in_memory().unwrap();
|
||||
db.migrate().unwrap();
|
||||
insert_project(db.conn(), &make_project()).unwrap();
|
||||
let dir = TempDir::new().unwrap();
|
||||
|
||||
@@ -51,7 +51,7 @@ fn make_post(slug: &str, published_at: i64) -> Post {
|
||||
}
|
||||
|
||||
fn setup() -> (Database, TempDir) {
|
||||
let mut db = Database::open_in_memory().unwrap();
|
||||
let db = Database::open_in_memory().unwrap();
|
||||
db.migrate().unwrap();
|
||||
insert_project(db.conn(), &make_project()).unwrap();
|
||||
(db, TempDir::new().unwrap())
|
||||
|
||||
60
crates/bds-core/tests/orm_boundary.rs
Normal file
60
crates/bds-core/tests/orm_boundary.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
const SQL_PREFIXES: &[&str] = &[
|
||||
"\"SELECT ",
|
||||
"\"INSERT ",
|
||||
"\"UPDATE ",
|
||||
"\"DELETE ",
|
||||
"\"CREATE ",
|
||||
"\"DROP ",
|
||||
"\"ALTER ",
|
||||
"\"SAVEPOINT ",
|
||||
"\"RELEASE ",
|
||||
"\"ROLLBACK ",
|
||||
];
|
||||
|
||||
#[test]
|
||||
fn application_queries_use_the_diesel_abstraction() {
|
||||
let source_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
|
||||
let mut rust_files = Vec::new();
|
||||
collect_rust_files(&source_root, &mut rust_files);
|
||||
|
||||
let mut violations = Vec::new();
|
||||
for path in rust_files {
|
||||
// SQLite connection configuration and FTS5 virtual tables/MATCH have no
|
||||
// representation in Diesel's typed query builder.
|
||||
if path.ends_with("db/connection.rs") || path.ends_with("db/fts.rs") {
|
||||
continue;
|
||||
}
|
||||
|
||||
let source = fs::read_to_string(&path).unwrap();
|
||||
for (line_index, line) in source.lines().enumerate() {
|
||||
if SQL_PREFIXES.iter().any(|prefix| line.contains(prefix)) {
|
||||
violations.push(format!(
|
||||
"{}:{}: {}",
|
||||
path.display(),
|
||||
line_index + 1,
|
||||
line.trim()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert!(
|
||||
violations.is_empty(),
|
||||
"literal SQL escaped the backend boundary:\n{}",
|
||||
violations.join("\n")
|
||||
);
|
||||
}
|
||||
|
||||
fn collect_rust_files(directory: &Path, files: &mut Vec<PathBuf>) {
|
||||
for entry in fs::read_dir(directory).unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
if path.is_dir() {
|
||||
collect_rust_files(&path, files);
|
||||
} else if path.extension().is_some_and(|extension| extension == "rs") {
|
||||
files.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,75 @@
|
||||
//! Tests that verify allium spec claims against the Rust model and DB code.
|
||||
//!
|
||||
//! Each test is annotated with the spec invariant or rule it validates.
|
||||
//! Executable checks for storage-related Allium claims.
|
||||
|
||||
use rusqlite::{Connection, OpenFlags};
|
||||
use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn fixture_db() -> Connection {
|
||||
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../../fixtures/compatibility-projects/rfc1437-sample/bds.db");
|
||||
Connection::open_with_flags(&path, OpenFlags::SQLITE_OPEN_READ_ONLY).unwrap()
|
||||
use bds_core::db::Database;
|
||||
use bds_core::db::queries::{
|
||||
post as post_queries, post_translation, project as project_queries, script, tag, template,
|
||||
};
|
||||
use bds_core::db::schema::{posts, scripts, templates};
|
||||
use bds_core::model::{
|
||||
Post, PostStatus, Project, ScriptKind, ScriptStatus, Tag, TemplateKind, TemplateStatus,
|
||||
};
|
||||
use diesel::prelude::*;
|
||||
|
||||
fn fixture_db() -> Database {
|
||||
Database::open(
|
||||
&PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../../fixtures/compatibility-projects/rfc1437-sample/bds.db"),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn memory_db() -> Connection {
|
||||
let mut conn = Connection::open_in_memory().unwrap();
|
||||
conn.execute_batch("PRAGMA foreign_keys=ON;").unwrap();
|
||||
bds_core::db::run_migrations(&mut conn).unwrap();
|
||||
conn
|
||||
fn memory_db() -> Database {
|
||||
let db = Database::open_in_memory().unwrap();
|
||||
db.migrate().unwrap();
|
||||
db
|
||||
}
|
||||
|
||||
// ── spec: post.allium — PostStatus serde matches DB string values ────
|
||||
fn project(id: &str, slug: &str) -> Project {
|
||||
Project {
|
||||
id: id.into(),
|
||||
name: id.into(),
|
||||
slug: slug.into(),
|
||||
description: None,
|
||||
data_path: None,
|
||||
is_active: true,
|
||||
created_at: 1000,
|
||||
updated_at: 1000,
|
||||
}
|
||||
}
|
||||
|
||||
fn post(id: &str, status: PostStatus, published_at: Option<i64>) -> Post {
|
||||
Post {
|
||||
id: id.into(),
|
||||
project_id: "p1".into(),
|
||||
title: id.into(),
|
||||
slug: id.into(),
|
||||
excerpt: None,
|
||||
content: Some("body".into()),
|
||||
status,
|
||||
author: None,
|
||||
language: None,
|
||||
do_not_translate: false,
|
||||
template_slug: None,
|
||||
file_path: String::new(),
|
||||
checksum: None,
|
||||
tags: Vec::new(),
|
||||
categories: Vec::new(),
|
||||
published_title: None,
|
||||
published_content: None,
|
||||
published_tags: None,
|
||||
published_categories: None,
|
||||
published_excerpt: None,
|
||||
created_at: 1000,
|
||||
updated_at: 1000,
|
||||
published_at,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn post_status_serde_matches_db_values() {
|
||||
// spec: status: draft | published | archived
|
||||
use bds_core::model::PostStatus;
|
||||
|
||||
fn enum_serde_matches_database_values() {
|
||||
assert_eq!(
|
||||
serde_json::to_string(&PostStatus::Draft).unwrap(),
|
||||
"\"draft\""
|
||||
@@ -37,584 +82,271 @@ fn post_status_serde_matches_db_values() {
|
||||
serde_json::to_string(&PostStatus::Archived).unwrap(),
|
||||
"\"archived\""
|
||||
);
|
||||
|
||||
// round-trip
|
||||
let d: PostStatus = serde_json::from_str("\"draft\"").unwrap();
|
||||
assert_eq!(d, PostStatus::Draft);
|
||||
let p: PostStatus = serde_json::from_str("\"published\"").unwrap();
|
||||
assert_eq!(p, PostStatus::Published);
|
||||
let a: PostStatus = serde_json::from_str("\"archived\"").unwrap();
|
||||
assert_eq!(a, PostStatus::Archived);
|
||||
}
|
||||
|
||||
// ── spec: schema.allium — Template kind: post | list | not_found | partial ──
|
||||
|
||||
#[test]
|
||||
fn template_kind_serde_matches_db_values() {
|
||||
use bds_core::model::TemplateKind;
|
||||
|
||||
assert_eq!(
|
||||
serde_json::to_string(&TemplateKind::Post).unwrap(),
|
||||
"\"post\""
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&TemplateKind::List).unwrap(),
|
||||
"\"list\""
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&TemplateKind::NotFound).unwrap(),
|
||||
"\"not_found\""
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&TemplateKind::Partial).unwrap(),
|
||||
"\"partial\""
|
||||
);
|
||||
|
||||
let nf: TemplateKind = serde_json::from_str("\"not_found\"").unwrap();
|
||||
assert_eq!(nf, TemplateKind::NotFound);
|
||||
}
|
||||
|
||||
// ── spec: schema.allium — Template status: draft | published ──
|
||||
|
||||
#[test]
|
||||
fn template_status_serde_matches_db_values() {
|
||||
use bds_core::model::TemplateStatus;
|
||||
|
||||
assert_eq!(
|
||||
serde_json::to_string(&TemplateStatus::Draft).unwrap(),
|
||||
"\"draft\""
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&TemplateStatus::Published).unwrap(),
|
||||
"\"published\""
|
||||
);
|
||||
}
|
||||
|
||||
// ── spec: schema.allium — Script kind: macro | utility | transform ──
|
||||
|
||||
#[test]
|
||||
fn script_kind_serde_matches_db_values() {
|
||||
use bds_core::model::ScriptKind;
|
||||
|
||||
assert_eq!(
|
||||
serde_json::to_string(&ScriptKind::Macro).unwrap(),
|
||||
"\"macro\""
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&ScriptKind::Utility).unwrap(),
|
||||
"\"utility\""
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&ScriptKind::Transform).unwrap(),
|
||||
"\"transform\""
|
||||
);
|
||||
|
||||
let t: ScriptKind = serde_json::from_str("\"transform\"").unwrap();
|
||||
assert_eq!(t, ScriptKind::Transform);
|
||||
}
|
||||
|
||||
// ── spec: schema.allium — Script status: draft | published ──
|
||||
|
||||
#[test]
|
||||
fn script_status_serde_matches_db_values() {
|
||||
use bds_core::model::ScriptStatus;
|
||||
|
||||
assert_eq!(
|
||||
serde_json::to_string(&ScriptStatus::Draft).unwrap(),
|
||||
"\"draft\""
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&ScriptStatus::Published).unwrap(),
|
||||
"\"published\""
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fixture_content_location_matches_spec() {
|
||||
let db = fixture_db();
|
||||
let active = project_queries::get_active_project(db.conn()).unwrap();
|
||||
let posts = post_queries::list_posts_by_project(db.conn(), &active.id).unwrap();
|
||||
assert!(
|
||||
posts
|
||||
.iter()
|
||||
.filter(|post| post.status == PostStatus::Published)
|
||||
.all(|post| post.content.is_none())
|
||||
);
|
||||
assert!(
|
||||
posts
|
||||
.iter()
|
||||
.filter(|post| post.status == PostStatus::Draft)
|
||||
.all(|post| post.content.is_some())
|
||||
);
|
||||
}
|
||||
|
||||
// ── spec: post.allium — content_location invariant ──
|
||||
// "if status = published: file_path else: content"
|
||||
// Published posts have NULL content in DB; draft posts have content in DB.
|
||||
|
||||
#[test]
|
||||
fn content_location_published_posts_null_content_in_fixture() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT slug, content FROM posts WHERE status = 'published'")
|
||||
.unwrap();
|
||||
let rows: Vec<(String, Option<String>)> = stmt
|
||||
.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
|
||||
assert!(!rows.is_empty());
|
||||
for (slug, content) in &rows {
|
||||
assert!(
|
||||
content.is_none(),
|
||||
"spec: published post '{slug}' must have NULL content in DB"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn content_location_draft_posts_have_content_in_fixture() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT slug, content FROM posts WHERE status = 'draft'")
|
||||
.unwrap();
|
||||
let rows: Vec<(String, Option<String>)> = stmt
|
||||
.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
|
||||
assert!(!rows.is_empty());
|
||||
for (slug, content) in &rows {
|
||||
assert!(
|
||||
content.is_some(),
|
||||
"spec: draft post '{slug}' must have content in DB"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── spec: post.allium — all status transitions allowed ──
|
||||
// draft -> published, draft -> archived, published -> draft,
|
||||
// published -> archived, archived -> draft, archived -> published
|
||||
|
||||
#[test]
|
||||
fn post_status_transitions_all_valid() {
|
||||
let conn = memory_db();
|
||||
conn.execute(
|
||||
"INSERT INTO projects (id, name, slug, created_at, updated_at, is_active) \
|
||||
VALUES ('p1', 'test', 'test', 1000, 1000, 1)",
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
conn.execute(
|
||||
"INSERT INTO posts (id, project_id, title, slug, status, file_path, created_at, updated_at) \
|
||||
VALUES ('post1', 'p1', 'Test', 'test', 'draft', '', 1000, 1000)",
|
||||
[],
|
||||
).unwrap();
|
||||
|
||||
let transitions = [
|
||||
("draft", "published"),
|
||||
("published", "draft"),
|
||||
("draft", "archived"),
|
||||
("archived", "draft"),
|
||||
("draft", "published"),
|
||||
("published", "archived"),
|
||||
("archived", "published"),
|
||||
];
|
||||
|
||||
for (from, to) in transitions {
|
||||
// Set to 'from' state first
|
||||
conn.execute("UPDATE posts SET status = ?1 WHERE id = 'post1'", [from])
|
||||
.unwrap();
|
||||
// Transition to 'to' state
|
||||
conn.execute("UPDATE posts SET status = ?1 WHERE id = 'post1'", [to])
|
||||
.unwrap();
|
||||
let status: String = conn
|
||||
.query_row("SELECT status FROM posts WHERE id = 'post1'", [], |r| {
|
||||
r.get(0)
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(status, to, "transition {from} -> {to} failed");
|
||||
let db = memory_db();
|
||||
project_queries::insert_project(db.conn(), &project("p1", "test")).unwrap();
|
||||
post_queries::insert_post(db.conn(), &post("post1", PostStatus::Draft, None)).unwrap();
|
||||
for status in [
|
||||
PostStatus::Published,
|
||||
PostStatus::Draft,
|
||||
PostStatus::Archived,
|
||||
PostStatus::Draft,
|
||||
PostStatus::Published,
|
||||
PostStatus::Archived,
|
||||
PostStatus::Published,
|
||||
] {
|
||||
post_queries::update_post_status(db.conn(), "post1", &status, 1000).unwrap();
|
||||
assert_eq!(
|
||||
post_queries::get_post_by_id(db.conn(), "post1")
|
||||
.unwrap()
|
||||
.status,
|
||||
status
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── spec: post.allium — is_slug_frozen: published_at != null ──
|
||||
// Slug changes only allowed before first publish
|
||||
|
||||
#[test]
|
||||
fn slug_frozen_after_publish_semantics() {
|
||||
let conn = memory_db();
|
||||
conn.execute(
|
||||
"INSERT INTO projects (id, name, slug, created_at, updated_at, is_active) \
|
||||
VALUES ('p1', 'test', 'test', 1000, 1000, 1)",
|
||||
[],
|
||||
let db = memory_db();
|
||||
project_queries::insert_project(db.conn(), &project("p1", "test")).unwrap();
|
||||
post_queries::insert_post(
|
||||
db.conn(),
|
||||
&post("published", PostStatus::Published, Some(1000)),
|
||||
)
|
||||
.unwrap();
|
||||
conn.execute(
|
||||
"INSERT INTO posts (id, project_id, title, slug, status, file_path, created_at, updated_at, published_at) \
|
||||
VALUES ('post1', 'p1', 'Test', 'test', 'published', 'posts/2024/01/test.md', 1000, 1000, 1000)",
|
||||
[],
|
||||
).unwrap();
|
||||
|
||||
// published_at is set — slug should be considered frozen
|
||||
let published_at: Option<i64> = conn
|
||||
.query_row(
|
||||
"SELECT published_at FROM posts WHERE id = 'post1'",
|
||||
[],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.unwrap();
|
||||
post_queries::insert_post(db.conn(), &post("draft", PostStatus::Draft, None)).unwrap();
|
||||
assert!(
|
||||
published_at.is_some(),
|
||||
"spec: is_slug_frozen = published_at != null"
|
||||
);
|
||||
|
||||
// A never-published draft has no published_at — slug is mutable
|
||||
conn.execute(
|
||||
"INSERT INTO posts (id, project_id, title, slug, status, file_path, created_at, updated_at) \
|
||||
VALUES ('post2', 'p1', 'Draft', 'draft-post', 'draft', '', 1000, 1000)",
|
||||
[],
|
||||
).unwrap();
|
||||
let draft_published_at: Option<i64> = conn
|
||||
.query_row(
|
||||
"SELECT published_at FROM posts WHERE id = 'post2'",
|
||||
[],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(
|
||||
draft_published_at.is_none(),
|
||||
"spec: unpublished draft has no published_at"
|
||||
);
|
||||
}
|
||||
|
||||
// ── spec: project.allium — SingleActiveProject invariant ──
|
||||
// "Exactly one project is active at any time"
|
||||
|
||||
#[test]
|
||||
fn single_active_project_in_fixture() {
|
||||
let conn = fixture_db();
|
||||
let active_count: i64 = conn
|
||||
.query_row(
|
||||
"SELECT COUNT(*) FROM projects WHERE is_active = 1",
|
||||
[],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(active_count, 1, "spec: exactly one project is active");
|
||||
}
|
||||
|
||||
// ── spec: project.allium — UniqueProjectSlug invariant ──
|
||||
|
||||
#[test]
|
||||
fn unique_project_slug_in_fixture() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT slug, COUNT(*) FROM projects GROUP BY slug HAVING COUNT(*) > 1")
|
||||
.unwrap();
|
||||
let dupes: Vec<(String, i64)> = stmt
|
||||
.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
assert!(dupes.is_empty(), "spec: project slug must be unique");
|
||||
}
|
||||
|
||||
// ── spec: translation.allium — UniqueTranslationPerLanguage ──
|
||||
// "post_translations must have unique (translation_for, language)"
|
||||
|
||||
#[test]
|
||||
fn unique_translation_per_post_language_in_fixture() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn
|
||||
.prepare(
|
||||
"SELECT translation_for, language, COUNT(*) FROM post_translations \
|
||||
GROUP BY translation_for, language HAVING COUNT(*) > 1",
|
||||
)
|
||||
.unwrap();
|
||||
let dupes: Vec<(String, String, i64)> = stmt
|
||||
.query_map([], |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
assert!(
|
||||
dupes.is_empty(),
|
||||
"spec: translation unique per (post, language)"
|
||||
);
|
||||
}
|
||||
|
||||
// ── spec: schema.allium — Post defaults ──
|
||||
// status default 'draft', do_not_translate default false, file_path default ''
|
||||
|
||||
#[test]
|
||||
fn post_defaults_match_spec() {
|
||||
let conn = memory_db();
|
||||
conn.execute(
|
||||
"INSERT INTO projects (id, name, slug, created_at, updated_at, is_active) \
|
||||
VALUES ('p1', 'test', 'test', 1000, 1000, 1)",
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
// Insert with minimal columns to test defaults
|
||||
conn.execute(
|
||||
"INSERT INTO posts (id, project_id, title, slug, created_at, updated_at) \
|
||||
VALUES ('min1', 'p1', 'Minimal', 'minimal', 1000, 1000)",
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (status, do_not_translate, file_path): (String, bool, String) = conn
|
||||
.query_row(
|
||||
"SELECT status, do_not_translate, file_path FROM posts WHERE id = 'min1'",
|
||||
[],
|
||||
|r| Ok((r.get(0)?, r.get(1)?, r.get(2)?)),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(status, "draft", "spec: default status is draft");
|
||||
assert!(!do_not_translate, "spec: default do_not_translate is false");
|
||||
assert_eq!(file_path, "", "spec: default file_path is empty string");
|
||||
}
|
||||
|
||||
// ── spec: schema.allium — Script defaults ──
|
||||
// kind default 'utility', entrypoint default 'render', enabled default true,
|
||||
// version default 1, status default 'published'
|
||||
|
||||
#[test]
|
||||
fn script_defaults_match_spec() {
|
||||
let conn = memory_db();
|
||||
conn.execute(
|
||||
"INSERT INTO projects (id, name, slug, created_at, updated_at, is_active) \
|
||||
VALUES ('p1', 'test', 'test', 1000, 1000, 1)",
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
conn.execute(
|
||||
"INSERT INTO scripts (id, project_id, slug, title, file_path, created_at, updated_at) \
|
||||
VALUES ('s1', 'p1', 'test', 'Test', 'scripts/test.lua', 1000, 1000)",
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (kind, entrypoint, enabled, version, status): (String, String, bool, i32, String) = conn
|
||||
.query_row(
|
||||
"SELECT kind, entrypoint, enabled, version, status FROM scripts WHERE id = 's1'",
|
||||
[],
|
||||
|r| Ok((r.get(0)?, r.get(1)?, r.get(2)?, r.get(3)?, r.get(4)?)),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(kind, "utility", "spec: default kind is utility");
|
||||
assert_eq!(entrypoint, "render", "spec: default entrypoint is 'render'");
|
||||
assert!(enabled, "spec: default enabled is true");
|
||||
assert_eq!(version, 1, "spec: default version is 1");
|
||||
assert_eq!(status, "draft", "spec: default status is draft");
|
||||
}
|
||||
|
||||
// ── spec: schema.allium — Template defaults ──
|
||||
// kind default 'post', enabled default true, version default 1, status default 'draft'
|
||||
|
||||
#[test]
|
||||
fn template_defaults_match_spec() {
|
||||
let conn = memory_db();
|
||||
conn.execute(
|
||||
"INSERT INTO projects (id, name, slug, created_at, updated_at, is_active) \
|
||||
VALUES ('p1', 'test', 'test', 1000, 1000, 1)",
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
conn.execute(
|
||||
"INSERT INTO templates (id, project_id, slug, title, file_path, created_at, updated_at) \
|
||||
VALUES ('t1', 'p1', 'test', 'Test', 'templates/test.liquid', 1000, 1000)",
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (kind, enabled, version, status): (String, bool, i32, String) = conn
|
||||
.query_row(
|
||||
"SELECT kind, enabled, version, status FROM templates WHERE id = 't1'",
|
||||
[],
|
||||
|r| Ok((r.get(0)?, r.get(1)?, r.get(2)?, r.get(3)?)),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(kind, "post", "spec: default kind is post");
|
||||
assert!(enabled, "spec: default enabled is true");
|
||||
assert_eq!(version, 1, "spec: default version is 1");
|
||||
assert_eq!(status, "draft", "spec: default status is draft");
|
||||
}
|
||||
|
||||
// ── spec: tag.allium — UniqueTagNamePerProject (case-insensitive) ──
|
||||
|
||||
#[test]
|
||||
fn tag_unique_name_per_project_enforced() {
|
||||
let conn = memory_db();
|
||||
conn.execute(
|
||||
"INSERT INTO projects (id, name, slug, created_at, updated_at, is_active) \
|
||||
VALUES ('p1', 'test', 'test', 1000, 1000, 1)",
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
conn.execute(
|
||||
"INSERT INTO tags (id, project_id, name, created_at, updated_at) \
|
||||
VALUES ('t1', 'p1', 'rust', 1000, 1000)",
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Same name, same project — must fail
|
||||
let result = conn.execute(
|
||||
"INSERT INTO tags (id, project_id, name, created_at, updated_at) \
|
||||
VALUES ('t2', 'p1', 'rust', 1000, 1000)",
|
||||
[],
|
||||
post_queries::get_post_by_id(db.conn(), "published")
|
||||
.unwrap()
|
||||
.published_at
|
||||
.is_some()
|
||||
);
|
||||
assert!(
|
||||
result.is_err(),
|
||||
"spec: duplicate tag name in same project must fail"
|
||||
post_queries::get_post_by_id(db.conn(), "draft")
|
||||
.unwrap()
|
||||
.published_at
|
||||
.is_none()
|
||||
);
|
||||
}
|
||||
|
||||
// ── spec: post.allium — Slug generation algorithm ──
|
||||
// "transliterate unicode to ASCII, lowercase, replace [^a-z0-9]+ with hyphens,
|
||||
// strip leading/trailing hyphens"
|
||||
|
||||
#[test]
|
||||
fn slug_generation_matches_spec_algorithm() {
|
||||
use bds_core::util::slugify;
|
||||
|
||||
// Basic: lowercase + hyphen separation
|
||||
assert_eq!(slugify("Hello World"), "hello-world");
|
||||
|
||||
// Non-alphanumeric replaced with single hyphen
|
||||
assert_eq!(slugify("a --- b"), "a-b");
|
||||
|
||||
// Leading/trailing hyphens stripped
|
||||
assert_eq!(slugify("---hello---"), "hello");
|
||||
|
||||
// Unicode transliteration
|
||||
assert_eq!(slugify("café"), "cafe");
|
||||
|
||||
// German umlauts (spec: "only German and English letters used")
|
||||
assert_eq!(slugify("über"), "ueber");
|
||||
assert_eq!(slugify("Ärger"), "aerger");
|
||||
assert_eq!(slugify("Öffnung"), "oeffnung");
|
||||
assert_eq!(slugify("Straße"), "strasse");
|
||||
}
|
||||
|
||||
// ── spec: post.allium — Slug uniqueness algorithm ──
|
||||
// "tries base, then {slug}-2 .. {slug}-999, then {slug}-{timestamp}"
|
||||
|
||||
#[test]
|
||||
fn slug_uniqueness_matches_spec() {
|
||||
use bds_core::util::ensure_unique;
|
||||
|
||||
// Base available
|
||||
assert_eq!(ensure_unique("test", |_| false), "test");
|
||||
|
||||
// Base taken → -2
|
||||
assert_eq!(ensure_unique("test", |s| s == "test"), "test-2");
|
||||
|
||||
// -2 and -3 taken → -4
|
||||
fn project_and_translation_uniqueness_in_fixture() {
|
||||
let db = fixture_db();
|
||||
let projects = project_queries::list_projects(db.conn()).unwrap();
|
||||
assert_eq!(
|
||||
ensure_unique("test", |s| s == "test" || s == "test-2" || s == "test-3"),
|
||||
"test-4"
|
||||
projects.iter().filter(|project| project.is_active).count(),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
// ── spec: frontmatter.allium — PostFileLayout ──
|
||||
// "posts/{YYYY}/{MM}/{slug}.md"
|
||||
|
||||
#[test]
|
||||
fn published_post_file_paths_follow_date_layout() {
|
||||
let conn = fixture_db();
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT slug, file_path, created_at FROM posts WHERE status = 'published' AND file_path != ''")
|
||||
.unwrap();
|
||||
let rows: Vec<(String, String, i64)> = stmt
|
||||
.query_map([], |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
|
||||
for (slug, path, _created_at) in &rows {
|
||||
// Path should end with {slug}.md
|
||||
assert!(
|
||||
path.ends_with(&format!("{slug}.md")),
|
||||
"spec: file_path must end with {{slug}}.md, got: {path}"
|
||||
);
|
||||
// Path should contain posts/YYYY/MM/ pattern
|
||||
assert!(
|
||||
path.contains("/posts/"),
|
||||
"spec: file_path must contain /posts/, got: {path}"
|
||||
assert_eq!(
|
||||
projects
|
||||
.iter()
|
||||
.map(|project| &project.slug)
|
||||
.collect::<HashSet<_>>()
|
||||
.len(),
|
||||
projects.len()
|
||||
);
|
||||
let active = project_queries::get_active_project(db.conn()).unwrap();
|
||||
let posts = post_queries::list_posts_by_project(db.conn(), &active.id).unwrap();
|
||||
for post in posts {
|
||||
let translations =
|
||||
post_translation::list_post_translations_by_post(db.conn(), &post.id).unwrap();
|
||||
assert_eq!(
|
||||
translations
|
||||
.iter()
|
||||
.map(|translation| &translation.language)
|
||||
.collect::<HashSet<_>>()
|
||||
.len(),
|
||||
translations.len()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── spec: cli_sync.allium — DbNotification entity_type values ──
|
||||
#[test]
|
||||
fn post_defaults_match_spec() {
|
||||
let db = memory_db();
|
||||
project_queries::insert_project(db.conn(), &project("p1", "test")).unwrap();
|
||||
db.conn()
|
||||
.with(|conn| {
|
||||
diesel::insert_into(posts::table)
|
||||
.values((
|
||||
posts::id.eq("min1"),
|
||||
posts::project_id.eq("p1"),
|
||||
posts::title.eq("Minimal"),
|
||||
posts::slug.eq("minimal"),
|
||||
posts::created_at.eq(1000_i64),
|
||||
posts::updated_at.eq(1000_i64),
|
||||
))
|
||||
.execute(conn)
|
||||
.map(|_| ())
|
||||
})
|
||||
.unwrap();
|
||||
let (status, do_not_translate, file_path) = db
|
||||
.conn()
|
||||
.with(|conn| {
|
||||
posts::table
|
||||
.filter(posts::id.eq("min1"))
|
||||
.select((posts::status, posts::do_not_translate, posts::file_path))
|
||||
.first::<(String, i32, String)>(conn)
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(status, "draft");
|
||||
assert_eq!(do_not_translate, 0);
|
||||
assert!(file_path.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn notification_entity_serde_matches_db_values() {
|
||||
use bds_core::model::{NotificationAction, NotificationEntity};
|
||||
fn script_defaults_match_spec() {
|
||||
let db = memory_db();
|
||||
project_queries::insert_project(db.conn(), &project("p1", "test")).unwrap();
|
||||
db.conn()
|
||||
.with(|conn| {
|
||||
diesel::insert_into(scripts::table)
|
||||
.values((
|
||||
scripts::id.eq("s1"),
|
||||
scripts::project_id.eq("p1"),
|
||||
scripts::slug.eq("test"),
|
||||
scripts::title.eq("Test"),
|
||||
scripts::file_path.eq("scripts/test.lua"),
|
||||
scripts::created_at.eq(1000_i64),
|
||||
scripts::updated_at.eq(1000_i64),
|
||||
))
|
||||
.execute(conn)
|
||||
.map(|_| ())
|
||||
})
|
||||
.unwrap();
|
||||
let value = script::get_script_by_id(db.conn(), "s1").unwrap();
|
||||
assert_eq!(value.kind, ScriptKind::Utility);
|
||||
assert_eq!(value.entrypoint, "render");
|
||||
assert!(value.enabled);
|
||||
assert_eq!(value.version, 1);
|
||||
assert_eq!(value.status, ScriptStatus::Draft);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn template_defaults_match_spec() {
|
||||
let db = memory_db();
|
||||
project_queries::insert_project(db.conn(), &project("p1", "test")).unwrap();
|
||||
db.conn()
|
||||
.with(|conn| {
|
||||
diesel::insert_into(templates::table)
|
||||
.values((
|
||||
templates::id.eq("t1"),
|
||||
templates::project_id.eq("p1"),
|
||||
templates::slug.eq("test"),
|
||||
templates::title.eq("Test"),
|
||||
templates::file_path.eq("templates/test.liquid"),
|
||||
templates::created_at.eq(1000_i64),
|
||||
templates::updated_at.eq(1000_i64),
|
||||
))
|
||||
.execute(conn)
|
||||
.map(|_| ())
|
||||
})
|
||||
.unwrap();
|
||||
let value = template::get_template_by_id(db.conn(), "t1").unwrap();
|
||||
assert_eq!(value.kind, TemplateKind::Post);
|
||||
assert!(value.enabled);
|
||||
assert_eq!(value.version, 1);
|
||||
assert_eq!(value.status, TemplateStatus::Draft);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tag_unique_name_per_project_enforced_case_insensitively() {
|
||||
let db = memory_db();
|
||||
project_queries::insert_project(db.conn(), &project("p1", "test")).unwrap();
|
||||
let make_tag = |id: &str, name: &str| Tag {
|
||||
id: id.into(),
|
||||
project_id: "p1".into(),
|
||||
name: name.into(),
|
||||
color: None,
|
||||
post_template_slug: None,
|
||||
created_at: 1000,
|
||||
updated_at: 1000,
|
||||
};
|
||||
tag::insert_tag(db.conn(), &make_tag("t1", "rust")).unwrap();
|
||||
assert!(tag::insert_tag(db.conn(), &make_tag("t2", "RUST")).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slug_generation_matches_spec() {
|
||||
use bds_core::util::{ensure_unique, slugify};
|
||||
assert_eq!(slugify("Hello World"), "hello-world");
|
||||
assert_eq!(slugify("a --- b"), "a-b");
|
||||
assert_eq!(slugify("---hello---"), "hello");
|
||||
assert_eq!(slugify("café"), "cafe");
|
||||
assert_eq!(slugify("über"), "ueber");
|
||||
assert_eq!(slugify("Straße"), "strasse");
|
||||
assert_eq!(ensure_unique("test", |value| value == "test"), "test-2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn published_paths_follow_layout() {
|
||||
let db = fixture_db();
|
||||
let active = project_queries::get_active_project(db.conn()).unwrap();
|
||||
for post in post_queries::list_posts_by_project(db.conn(), &active.id)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.filter(|post| post.status == PostStatus::Published)
|
||||
{
|
||||
assert!(post.file_path.ends_with(&format!("{}.md", post.slug)));
|
||||
assert!(post.file_path.contains("/posts/"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remaining_value_specs_match() {
|
||||
use bds_core::model::{NotificationAction, NotificationEntity, SshMode};
|
||||
assert_eq!(
|
||||
serde_json::to_string(&NotificationEntity::Post).unwrap(),
|
||||
"\"post\""
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&NotificationEntity::Media).unwrap(),
|
||||
"\"media\""
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&NotificationEntity::Script).unwrap(),
|
||||
"\"script\""
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&NotificationEntity::Template).unwrap(),
|
||||
"\"template\""
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
serde_json::to_string(&NotificationAction::Created).unwrap(),
|
||||
"\"created\""
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&NotificationAction::Updated).unwrap(),
|
||||
"\"updated\""
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&NotificationAction::Deleted).unwrap(),
|
||||
"\"deleted\""
|
||||
);
|
||||
}
|
||||
|
||||
// ── spec: generation.allium / publishing.allium — SshMode values ──
|
||||
|
||||
#[test]
|
||||
fn ssh_mode_serde_matches_spec() {
|
||||
use bds_core::model::SshMode;
|
||||
|
||||
assert_eq!(serde_json::to_string(&SshMode::Scp).unwrap(), "\"scp\"");
|
||||
assert_eq!(serde_json::to_string(&SshMode::Rsync).unwrap(), "\"rsync\"");
|
||||
assert_eq!(["en", "de", "fr", "it", "es"].len(), 5);
|
||||
}
|
||||
|
||||
// ── spec: i18n.allium — SplitLocalization ──
|
||||
// Verify that the 5 supported UI languages exist as config
|
||||
|
||||
#[test]
|
||||
fn supported_languages_match_spec() {
|
||||
// spec: en, de, fr, it, es — the 5 supported UI languages
|
||||
let supported = ["en", "de", "fr", "it", "es"];
|
||||
assert_eq!(supported.len(), 5);
|
||||
// This test documents the spec constraint; actual locale loading
|
||||
// will be tested when i18n module is implemented in M2+
|
||||
}
|
||||
|
||||
// ── spec: schema.allium — FTS5 virtual tables exist in fixture ──
|
||||
|
||||
#[test]
|
||||
fn fts5_tables_exist_in_fixture() {
|
||||
let conn = fixture_db();
|
||||
|
||||
// posts_fts
|
||||
let result = conn.query_row(
|
||||
"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='posts_fts'",
|
||||
[],
|
||||
|r| r.get::<_, i64>(0),
|
||||
);
|
||||
assert_eq!(
|
||||
result.unwrap(),
|
||||
1,
|
||||
"spec: posts_fts virtual table must exist"
|
||||
);
|
||||
|
||||
// media_fts
|
||||
let result = conn.query_row(
|
||||
"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='media_fts'",
|
||||
[],
|
||||
|r| r.get::<_, i64>(0),
|
||||
);
|
||||
assert_eq!(
|
||||
result.unwrap(),
|
||||
1,
|
||||
"spec: media_fts virtual table must exist"
|
||||
);
|
||||
let db = fixture_db();
|
||||
assert!(bds_core::db::fts::tables_exist(db.conn()).unwrap());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user