test(core): the adapter maps bookspec's setting keys to the engine's
Bookspec now closes its setting keys (fiscal_year_start); the engine's key is company.fiscal_year_start. The event and the query both go through one map (BS-ledger-9). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bab7ac72ca
commit
e49b6d3427
2 files changed
+18
-4
No files matched your search
@@ -833,7 +833,7 @@ impl Books<'_> {
|
||||
// The books' own journaled command: the fact and who decided
|
||||
// it are kept in the journal (BS-ledger-9).
|
||||
let change = Change {
|
||||
key: s.key.clone(),
|
||||
key: engine_setting_key(&s.key).to_string(),
|
||||
value: Some(Value::String(s.value.clone())),
|
||||
};
|
||||
let source = Source {
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
use crate::*;
|
||||
|
||||
/// The engine's key for a bookspec setting key (`SETTING_KEYS`): the
|
||||
/// engine's own settings carry the `company.` prefix. A key the schema
|
||||
/// admits and this map lacks is a gap in the adapter, so it panics.
|
||||
pub(crate) fn engine_setting_key(bookspec_key: &str) -> &'static str {
|
||||
match bookspec_key {
|
||||
"fiscal_year_start" => "company.fiscal_year_start",
|
||||
other => panic!("the adapter maps no engine key for the bookspec setting {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
impl Books<'_> {
|
||||
/// A `setting` query (BS-ledger-9): the value the books keep, with who
|
||||
/// decided it and when. The books hold their settings in the journal
|
||||
@@ -7,9 +17,13 @@ impl Books<'_> {
|
||||
pub(crate) fn answer_setting(&self, q: &Query) -> Result<Value, Refusal> {
|
||||
let rule = RuleId::new(Area::Ledger, 9);
|
||||
let key = q.key.as_deref().ok_or_else(|| self.missing("key"))?;
|
||||
let recorded = self.l().settings().get(key).ok_or_else(|| {
|
||||
Refusal::new(rule.clone(), format!("no setting {key:?} in the books"))
|
||||
})?;
|
||||
let recorded = self
|
||||
.l()
|
||||
.settings()
|
||||
.get(engine_setting_key(key))
|
||||
.ok_or_else(|| {
|
||||
Refusal::new(rule.clone(), format!("no setting {key:?} in the books"))
|
||||
})?;
|
||||
let value = match &recorded.value {
|
||||
Value::String(s) => s.clone(),
|
||||
other => other.to_string(),
|
||||
|
||||
Reference in new issue
Block a user