| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
use synckit_config::{ConfigSpec, Posture}; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
pub const CONFIG: ConfigSpec = ConfigSpec::new( |
| 34 |
"user_config", |
| 35 |
&[ |
| 36 |
|
| 37 |
("theme", Posture::Synced), |
| 38 |
("event_lead_minutes", Posture::Synced), |
| 39 |
("plan_nudges", Posture::Synced), |
| 40 |
("review_nudges", Posture::Synced), |
| 41 |
("work_start_hour", Posture::Synced), |
| 42 |
("work_end_hour", Posture::Synced), |
| 43 |
|
| 44 |
("ui_mode", Posture::Local), |
| 45 |
("welcomed", Posture::Local), |
| 46 |
("hint_shortcuts", Posture::Local), |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
("wam_url", Posture::Local), |
| 51 |
], |
| 52 |
); |
| 53 |
|
| 54 |
#[cfg(test)] |
| 55 |
mod tests { |
| 56 |
use super::*; |
| 57 |
|
| 58 |
#[test] |
| 59 |
fn only_preferences_sync() { |
| 60 |
for key in [ |
| 61 |
"theme", |
| 62 |
"event_lead_minutes", |
| 63 |
"plan_nudges", |
| 64 |
"review_nudges", |
| 65 |
"work_start_hour", |
| 66 |
"work_end_hour", |
| 67 |
] { |
| 68 |
assert!( |
| 69 |
CONFIG.is_synced(key), |
| 70 |
"{key} is a preference and should sync" |
| 71 |
); |
| 72 |
} |
| 73 |
for key in ["ui_mode", "welcomed", "hint_shortcuts"] { |
| 74 |
assert!( |
| 75 |
!CONFIG.is_synced(key), |
| 76 |
"{key} is per-device and must not sync" |
| 77 |
); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
#[test] |
| 82 |
fn an_undeclared_key_is_local() { |
| 83 |
assert!(!CONFIG.is_synced("something_new"), "fail closed"); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
#[test] |
| 90 |
fn policy_rows_mark_only_synced_keys_replicated() { |
| 91 |
let replicated: std::collections::BTreeSet<&str> = CONFIG |
| 92 |
.policy_rows() |
| 93 |
.filter(|r| r.replicated) |
| 94 |
.map(|r| r.key) |
| 95 |
.collect(); |
| 96 |
let expected: std::collections::BTreeSet<&str> = [ |
| 97 |
"theme", |
| 98 |
"event_lead_minutes", |
| 99 |
"plan_nudges", |
| 100 |
"review_nudges", |
| 101 |
"work_start_hour", |
| 102 |
"work_end_hour", |
| 103 |
] |
| 104 |
.into_iter() |
| 105 |
.collect(); |
| 106 |
assert_eq!(replicated, expected); |
| 107 |
} |
| 108 |
} |
| 109 |
|