coven/
readable_objects.rs1pub fn make_readable_objects(
11 connection: &coven_database::test_utils::Connection,
12 device: coven_foundation::id_source::DeviceId,
13) -> coven_database::SqliteResult<()> {
14 coven_database::test_utils::make_readable_objects(
15 connection,
16 device,
17 &coven_sync::sync_functions(),
18 )
19}
20
21pub fn record_invite(
25 connection: &coven_database::test_utils::Connection,
26 invite: coven_sync::RecordedInvite,
27) -> Result<coven_database::OperationId, crate::CovenError> {
28 let new = coven_sync::invite_operation(invite)?;
29 Ok(coven_database::test_utils::journal_outside_store(connection, &new, None)?)
30}
31
32pub fn refuse_invite(
37 connection: &coven_database::test_utils::Connection,
38 invite: coven_database::OperationId,
39 account: &str,
40 refusal: coven_foundation::sharing::SharingRefusal,
41) -> Result<(), crate::CovenError> {
42 let outcome =
43 coven_database::ListedOutcome::Invite(coven_database::InviteOutcome::SharingRefused {
44 account: account.to_owned(),
45 refusal,
46 });
47 let kind = coven_sync::OperationKind::Invite.listed();
48 Ok(coven_database::test_utils::finish_outside_store(
49 connection,
50 invite,
51 coven_database::test_utils::OutcomeListing::Unlisted { kind: &kind, outcome: &outcome },
52 )?)
53}
54
55pub fn record_change(
59 connection: &coven_database::test_utils::Connection,
60 change: coven_format::admin::StoreChange,
61) -> Result<coven_database::OperationId, crate::CovenError> {
62 let (new, kind) = coven_sync::change_operation(change)?;
63 Ok(coven_database::test_utils::journal_outside_store(connection, &new, Some(&kind))?)
64}
65
66pub fn finish_operation(
71 connection: &coven_database::test_utils::Connection,
72 id: coven_database::OperationId,
73 outcome: impl Into<coven_database::ListedOutcome>,
74) -> Result<(), crate::CovenError> {
75 let outcome = outcome.into();
76 let kind: Option<coven_sync::OperationKind> = connection
77 .query_row("SELECT (SELECT kind FROM coven_operations WHERE operation=?1)", [id.0], |row| {
78 row.get(0)
79 })
80 .map_err(coven_database::DbError::from)?;
81 if kind.is_some_and(|kind| !kind.lists(&outcome)) {
82 return Err(coven_database::DbError::Invariant {
83 what: "an operation ends in the outcome type of its kind",
84 }
85 .into());
86 }
87 Ok(coven_database::test_utils::finish_outside_store(
88 connection,
89 id,
90 coven_database::test_utils::OutcomeListing::Listed(&outcome),
91 )?)
92}
93
94pub fn record_pending(
98 connection: &coven_database::test_utils::Connection,
99 record: &coven_sync::PendingRecord,
100) -> Result<(), crate::CovenError> {
101 Ok(coven_database::test_utils::save_outside_store(connection, record)?)
102}
103
104pub fn record_connected_storage(
110 connection: &coven_database::test_utils::Connection,
111 location: coven_storage::StorageConfig,
112) -> Result<(), crate::CovenError> {
113 Ok(coven_sync::record_connected_outside_store(connection, location)?)
114}
115
116pub fn record_last_pass(
122 connection: &coven_database::test_utils::Connection,
123 pass: &coven_sync::LastPass,
124) -> Result<(), crate::CovenError> {
125 Ok(pass.record_outside_store(connection)?)
126}
127
128#[cfg(test)]
129#[path = "readable_objects_tests.rs"]
130mod tests;