[tests] Added transient task scenarii
This commit is contained in:
parent
aa02fa182d
commit
9f7c2805ca
2 changed files with 83 additions and 10 deletions
|
@ -505,6 +505,53 @@ pub fn scenarii_first_sync_to_server() -> Vec<ItemScenario> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// This scenario tests a task added and deleted before a sync happens
|
||||||
|
pub fn scenarii_transient_task() -> Vec<ItemScenario> {
|
||||||
|
let mut tasks = Vec::new();
|
||||||
|
|
||||||
|
let cal = CalendarId::from("https://some.calend.ar/transient/".parse().unwrap());
|
||||||
|
|
||||||
|
tasks.push(
|
||||||
|
ItemScenario {
|
||||||
|
id: ItemId::random(),
|
||||||
|
initial_state: LocatedState::Local( ItemState{
|
||||||
|
calendar: cal.clone(),
|
||||||
|
name: String::from("A task, so that the calendar actually exists"),
|
||||||
|
completed: false,
|
||||||
|
}),
|
||||||
|
local_changes_to_apply: Vec::new(),
|
||||||
|
remote_changes_to_apply: Vec::new(),
|
||||||
|
after_sync: LocatedState::BothSynced( ItemState{
|
||||||
|
calendar: cal.clone(),
|
||||||
|
name: String::from("A task, so that the calendar actually exists"),
|
||||||
|
completed: false,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
let id_transient = ItemId::random();
|
||||||
|
tasks.push(
|
||||||
|
ItemScenario {
|
||||||
|
id: id_transient.clone(),
|
||||||
|
initial_state: LocatedState::None,
|
||||||
|
local_changes_to_apply: vec![
|
||||||
|
ChangeToApply::Create(cal, Item::Task(
|
||||||
|
Task::new(String::from("A transient task that will be deleted before the sync"), id_transient, SyncStatus::NotSynced, false )
|
||||||
|
)),
|
||||||
|
|
||||||
|
ChangeToApply::Rename(String::from("A new name")),
|
||||||
|
ChangeToApply::SetCompletion(true),
|
||||||
|
ChangeToApply::Remove,
|
||||||
|
],
|
||||||
|
remote_changes_to_apply: Vec::new(),
|
||||||
|
after_sync: LocatedState::None,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
tasks
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Build a `Provider` that contains the data (defined in the given scenarii) before sync
|
/// Build a `Provider` that contains the data (defined in the given scenarii) before sync
|
||||||
pub async fn populate_test_provider_before_sync(scenarii: &[ItemScenario]) -> Provider<Cache, CachedCalendar, Cache, CachedCalendar> {
|
pub async fn populate_test_provider_before_sync(scenarii: &[ItemScenario]) -> Provider<Cache, CachedCalendar, Cache, CachedCalendar> {
|
||||||
let mut provider = populate_test_provider(scenarii, false).await;
|
let mut provider = populate_test_provider(scenarii, false).await;
|
||||||
|
@ -569,17 +616,19 @@ async fn apply_changes_on_provider(provider: &mut Provider<Cache, CachedCalendar
|
||||||
for item in scenarii {
|
for item in scenarii {
|
||||||
let initial_calendar_id = match &item.initial_state {
|
let initial_calendar_id = match &item.initial_state {
|
||||||
LocatedState::None => None,
|
LocatedState::None => None,
|
||||||
LocatedState::Local(state) => Some(&state.calendar),
|
LocatedState::Local(state) => Some(state.calendar.clone()),
|
||||||
LocatedState::Remote(state) => Some(&state.calendar),
|
LocatedState::Remote(state) => Some(state.calendar.clone()),
|
||||||
LocatedState::BothSynced(state) => Some(&state.calendar),
|
LocatedState::BothSynced(state) => Some(state.calendar.clone()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut calendar_id = initial_calendar_id.clone();
|
||||||
for local_change in &item.local_changes_to_apply {
|
for local_change in &item.local_changes_to_apply {
|
||||||
apply_change(provider.local(), initial_calendar_id, &item.id, local_change, false).await;
|
calendar_id = Some(apply_change(provider.local(), calendar_id, &item.id, local_change, false).await);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut calendar_id = initial_calendar_id;
|
||||||
for remote_change in &item.remote_changes_to_apply {
|
for remote_change in &item.remote_changes_to_apply {
|
||||||
apply_change(provider.remote(), initial_calendar_id, &item.id, remote_change, true).await;
|
calendar_id = Some(apply_change(provider.remote(), calendar_id, &item.id, remote_change, true).await);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -602,15 +651,20 @@ async fn get_or_insert_calendar(source: &mut Cache, id: &CalendarId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply a single change on a given source
|
/// Apply a single change on a given source, and returns the calendar ID that was modified
|
||||||
async fn apply_change<S, C>(source: &S, calendar_id: Option<&CalendarId>, item_id: &ItemId, change: &ChangeToApply, is_remote: bool)
|
async fn apply_change<S, C>(source: &S, calendar_id: Option<CalendarId>, item_id: &ItemId, change: &ChangeToApply, is_remote: bool) -> CalendarId
|
||||||
where
|
where
|
||||||
S: CalDavSource<C>,
|
S: CalDavSource<C>,
|
||||||
C: CompleteCalendar + DavCalendar, // in this test, we're using a calendar that mocks both kinds
|
C: CompleteCalendar + DavCalendar, // in this test, we're using a calendar that mocks both kinds
|
||||||
{
|
{
|
||||||
match calendar_id {
|
match calendar_id {
|
||||||
Some(cal) => apply_changes_on_an_existing_item(source, cal, item_id, change, is_remote).await,
|
Some(cal) => {
|
||||||
None => create_test_item(source, change).await,
|
apply_changes_on_an_existing_item(source, &cal, item_id, change, is_remote).await;
|
||||||
|
cal
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
create_test_item(source, change).await
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -653,7 +707,8 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_test_item<S, C>(source: &S, change: &ChangeToApply)
|
/// Create an item, and returns the calendar ID it was inserted in
|
||||||
|
async fn create_test_item<S, C>(source: &S, change: &ChangeToApply) -> CalendarId
|
||||||
where
|
where
|
||||||
S: CalDavSource<C>,
|
S: CalDavSource<C>,
|
||||||
C: CompleteCalendar + DavCalendar, // in this test, we're using a calendar that mocks both kinds
|
C: CompleteCalendar + DavCalendar, // in this test, we're using a calendar that mocks both kinds
|
||||||
|
@ -668,6 +723,7 @@ where
|
||||||
ChangeToApply::Create(calendar_id, item) => {
|
ChangeToApply::Create(calendar_id, item) => {
|
||||||
let cal = source.get_calendar(calendar_id).await.unwrap();
|
let cal = source.get_calendar(calendar_id).await.unwrap();
|
||||||
cal.lock().unwrap().add_item(item.clone()).await.unwrap();
|
cal.lock().unwrap().add_item(item.clone()).await.unwrap();
|
||||||
|
calendar_id.clone()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ impl TestFlavour {
|
||||||
pub fn first_sync_to_local() -> Self { Self{} }
|
pub fn first_sync_to_local() -> Self { Self{} }
|
||||||
#[cfg(not(feature = "local_calendar_mocks_remote_calendars"))]
|
#[cfg(not(feature = "local_calendar_mocks_remote_calendars"))]
|
||||||
pub fn first_sync_to_server() -> Self { Self{} }
|
pub fn first_sync_to_server() -> Self { Self{} }
|
||||||
|
#[cfg(not(feature = "local_calendar_mocks_remote_calendars"))]
|
||||||
|
pub fn transient_task() -> Self { Self{} }
|
||||||
|
|
||||||
#[cfg(feature = "local_calendar_mocks_remote_calendars")]
|
#[cfg(feature = "local_calendar_mocks_remote_calendars")]
|
||||||
pub fn normal() -> Self {
|
pub fn normal() -> Self {
|
||||||
|
@ -39,6 +41,13 @@ impl TestFlavour {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "local_calendar_mocks_remote_calendars")]
|
||||||
|
pub fn transient_task() -> Self {
|
||||||
|
Self {
|
||||||
|
scenarii: scenarii::scenarii_transient_task(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(not(feature = "local_calendar_mocks_remote_calendars"))]
|
#[cfg(not(feature = "local_calendar_mocks_remote_calendars"))]
|
||||||
pub async fn run(&self) {
|
pub async fn run(&self) {
|
||||||
|
@ -96,6 +105,14 @@ async fn test_sync_empty_initial_server() {
|
||||||
flavour.run().await;
|
flavour.run().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_sync_transient_task() {
|
||||||
|
let _ = env_logger::builder().is_test(true).try_init();
|
||||||
|
|
||||||
|
let flavour = TestFlavour::transient_task();
|
||||||
|
flavour.run().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(feature = "integration_tests")]
|
#[cfg(feature = "integration_tests")]
|
||||||
use my_tasks::{traits::CalDavSource,
|
use my_tasks::{traits::CalDavSource,
|
||||||
|
|
Loading…
Add table
Reference in a new issue