diff --git a/server/service/src/sync/test/mod.rs b/server/service/src/sync/test/mod.rs index 937d080da7..e67be0336c 100644 --- a/server/service/src/sync/test/mod.rs +++ b/server/service/src/sync/test/mod.rs @@ -177,6 +177,15 @@ pub(crate) async fn check_records_against_database( Sensor(record) => { check_record_by_id!(SensorRowRepository, con, record, "Sensor"); } + TemperatureLog(record) => { + check_record_by_id!(TemperatureLogRowRepository, con, record, "TemperatureLog"); + } + TemperatureBreach(record) => { + check_record_by_id!(TemperatureBreachRowRepository, con, record, "TemperatureBreach"); + } + TemperatureBreachConfig(record) => { + check_record_by_id!(TemperatureBreachConfigRowRepository, con, record, "TemperatureBreachConfig"); + } Location(record) => { check_record_by_id!(LocationRowRepository, con, record, "Location"); } diff --git a/server/service/src/sync/test/test_data/mod.rs b/server/service/src/sync/test/test_data/mod.rs index ecc30b79a6..782f3e97f7 100644 --- a/server/service/src/sync/test/test_data/mod.rs +++ b/server/service/src/sync/test/test_data/mod.rs @@ -30,6 +30,9 @@ pub(crate) mod stocktake; pub(crate) mod stocktake_line; pub(crate) mod store; pub(crate) mod store_preference; +pub(crate) mod temperature_breach; +pub(crate) mod temperature_breach_config; +pub(crate) mod temperature_log; pub(crate) mod unit; pub(crate) mod user_permission; @@ -60,6 +63,9 @@ pub(crate) fn get_all_pull_upsert_remote_test_records() -> Vec Vec { test_records.append(&mut name::test_push_records()); test_records.append(&mut location::test_push_records()); test_records.append(&mut sensor::test_push_records()); + test_records.append(&mut temperature_log::test_push_records()); + test_records.append(&mut temperature_breach::test_push_records()); + test_records.append(&mut temperature_breach_config::test_push_records()); test_records.append(&mut location_movement::test_push_records()); test_records.append(&mut requisition_line::test_push_records()); test_records.append(&mut requisition::test_push_records()); diff --git a/server/service/src/sync/test/test_data/temperature_breach.rs b/server/service/src/sync/test/test_data/temperature_breach.rs new file mode 100644 index 0000000000..1c7143c0e9 --- /dev/null +++ b/server/service/src/sync/test/test_data/temperature_breach.rs @@ -0,0 +1,79 @@ +use crate::sync::translations::{temperature_breach::{LegacyTemperatureBreachRow, LegacyTemperatureBreachType}, LegacyTableName, PullUpsertRecord}; + +use chrono::{Duration, NaiveDate, NaiveTime}; +use repository::{TemperatureBreachRow, TemperatureBreachRowType}; +use serde_json::json; + +use super::{TestSyncPullRecord, TestSyncPushRecord}; + +const TEMPERATURE_BREACH_1: (&'static str, &'static str) = ( + "996812e0c33911eb9757779d39ae2dbd", + r#"{ + "ID": "996812e0c33911eb9757779d39ae2dbd", + "sensor_ID": "cf5812e0c33911eb9757779d39ae2dbd", + "location_ID": "", + "type": "COLD_CONSECUTIVE", + "threshold_minimum_temperature": -273.0, + "threshold_maximum_temperature": 2.0, + "threshold_duration": 3600, + "duration": 86400, + "acknowledged": false, + "store_ID": "store_a", + "start_date": "2023-07-01", + "start_time": 47046, + "end_date": "2023-07-02", + "end_time": 47046 + }"#, +); + +pub(crate) fn test_pull_upsert_records() -> Vec { + vec![TestSyncPullRecord::new_pull_upsert( + LegacyTableName::TEMPERATURE_BREACH, + TEMPERATURE_BREACH_1, + PullUpsertRecord::TemperatureBreach(TemperatureBreachRow { + id: TEMPERATURE_BREACH_1.0.to_string(), + store_id: Some("store_a".to_string()), + location_id: None, + r#type: TemperatureBreachRowType::ColdConsecutive, + duration: 86400, + acknowledged: false, + sensor_id: "cf5812e0c33911eb9757779d39ae2dbd".to_string(), + threshold_minimum: -273.0, + threshold_maximum: 2.0, + threshold_duration: 3600, + start_timestamp: NaiveDate::from_ymd_opt(2023, 7, 1) + .unwrap() + .and_hms_opt(0, 0, 0) + .unwrap() + + Duration::seconds(47046), + end_timestamp: NaiveDate::from_ymd_opt(2023, 7, 2) + .unwrap() + .and_hms_opt(0, 0, 0) + .unwrap() + + Duration::seconds(47046), + }), + )] +} + +pub(crate) fn test_push_records() -> Vec { + vec![TestSyncPushRecord { + table_name: LegacyTableName::TEMPERATURE_BREACH.to_string(), + record_id: TEMPERATURE_BREACH_1.0.to_string(), + push_data: json!(LegacyTemperatureBreachRow { + id: TEMPERATURE_BREACH_1.0.to_string(), + r#type: LegacyTemperatureBreachType::ColdConsecutive, + duration: 86400, + acknowledged: false, + sensor_id: "cf5812e0c33911eb9757779d39ae2dbd".to_string(), + store_id: Some("store_a".to_string()), + location_id: None, + threshold_minimum: -273.0, + threshold_maximum: 2.0, + threshold_duration: 3600, + start_date: NaiveDate::from_ymd_opt(2023, 7, 1).unwrap(), + start_time: NaiveTime::from_hms_opt(13, 4, 6).unwrap(), + end_date: NaiveDate::from_ymd_opt(2023, 7, 2).unwrap(), + end_time: NaiveTime::from_hms_opt(13, 4, 6).unwrap(), + }), + }] +} diff --git a/server/service/src/sync/test/test_data/temperature_breach_config.rs b/server/service/src/sync/test/test_data/temperature_breach_config.rs new file mode 100644 index 0000000000..5d792e0ef5 --- /dev/null +++ b/server/service/src/sync/test/test_data/temperature_breach_config.rs @@ -0,0 +1,54 @@ +use crate::sync::translations::{temperature_breach::LegacyTemperatureBreachType, temperature_breach_config::LegacyTemperatureBreachConfigRow, LegacyTableName, PullUpsertRecord}; + +use repository::{TemperatureBreachConfigRow, TemperatureBreachRowType}; +use serde_json::json; + +use super::{TestSyncPullRecord, TestSyncPushRecord}; + +const TEMPERATURE_BREACH_CONFIG_1: (&'static str, &'static str) = ( + "997812e0c33911eb9757779d39ae2dbd", + r#"{ + "ID": "997812e0c33911eb9757779d39ae2dbd", + "type": "COLD_CONSECUTIVE", + "description": "Cold Consecutive below 2.0 for 1 hour", + "minimum_temperature": -273.0, + "maximum_temperature": 2.0, + "duration": 3600, + "is_active": true, + "store_ID": "store_a" + }"#, +); + +pub(crate) fn test_pull_upsert_records() -> Vec { + vec![TestSyncPullRecord::new_pull_upsert( + LegacyTableName::TEMPERATURE_BREACH_CONFIG, + TEMPERATURE_BREACH_CONFIG_1, + PullUpsertRecord::TemperatureBreachConfig(TemperatureBreachConfigRow { + id: TEMPERATURE_BREACH_CONFIG_1.0.to_string(), + store_id: Some("store_a".to_string()), + r#type: TemperatureBreachRowType::ColdConsecutive, + description: "Cold Consecutive below 2.0 for 1 hour".to_string(), + is_active: true, + minimum_temperature: -273.0, + maximum_temperature: 2.0, + duration: 3600, + }), + )] +} + +pub(crate) fn test_push_records() -> Vec { + vec![TestSyncPushRecord { + table_name: LegacyTableName::TEMPERATURE_BREACH_CONFIG.to_string(), + record_id: TEMPERATURE_BREACH_CONFIG_1.0.to_string(), + push_data: json!(LegacyTemperatureBreachConfigRow { + id: TEMPERATURE_BREACH_CONFIG_1.0.to_string(), + r#type: LegacyTemperatureBreachType::ColdConsecutive, + description: "Cold Consecutive below 2.0 for 1 hour".to_string(), + is_active: true, + store_id: Some("store_a".to_string()), + minimum_temperature: -273.0, + maximum_temperature: 2.0, + duration: 3600, + }), + }] +} diff --git a/server/service/src/sync/test/test_data/temperature_log.rs b/server/service/src/sync/test/test_data/temperature_log.rs new file mode 100644 index 0000000000..45c5b03ada --- /dev/null +++ b/server/service/src/sync/test/test_data/temperature_log.rs @@ -0,0 +1,55 @@ +use crate::sync::translations::{temperature_log::LegacyTemperatureLogRow, LegacyTableName, PullUpsertRecord}; + +use chrono::{Duration, NaiveDate, NaiveTime}; +use repository::TemperatureLogRow; +use serde_json::json; + +use super::{TestSyncPullRecord, TestSyncPushRecord}; + +const TEMPERATURE_LOG_1: (&'static str, &'static str) = ( + "995812e0c33911eb9757779d39ae2dbd", + r#"{ + "ID": "995812e0c33911eb9757779d39ae2dbd", + "sensor_ID": "cf5812e0c33911eb9757779d39ae2dbd", + "location_ID": "", + "temperature": 10.6, + "store_ID": "store_a", + "date": "2023-07-01", + "time": 47046 + }"#, +); + +pub(crate) fn test_pull_upsert_records() -> Vec { + vec![TestSyncPullRecord::new_pull_upsert( + LegacyTableName::TEMPERATURE_LOG, + TEMPERATURE_LOG_1, + PullUpsertRecord::TemperatureLog(TemperatureLogRow { + id: TEMPERATURE_LOG_1.0.to_string(), + store_id: Some("store_a".to_string()), + location_id: None, + temperature: 10.6, + sensor_id: "cf5812e0c33911eb9757779d39ae2dbd".to_string(), + timestamp: NaiveDate::from_ymd_opt(2023, 7, 1) + .unwrap() + .and_hms_opt(0, 0, 0) + .unwrap() + + Duration::seconds(47046), + }), + )] +} + +pub(crate) fn test_push_records() -> Vec { + vec![TestSyncPushRecord { + table_name: LegacyTableName::TEMPERATURE_LOG.to_string(), + record_id: TEMPERATURE_LOG_1.0.to_string(), + push_data: json!(LegacyTemperatureLogRow { + id: TEMPERATURE_LOG_1.0.to_string(), + temperature: 10.6, + sensor_id: "cf5812e0c33911eb9757779d39ae2dbd".to_string(), + store_id: Some("store_a".to_string()), + location_id: None, + date: NaiveDate::from_ymd_opt(2023, 7, 1).unwrap(), + time: NaiveTime::from_hms_opt(13, 4, 6).unwrap(), + }), + }] +} diff --git a/server/service/src/sync/translations/temperature_breach_config.rs b/server/service/src/sync/translations/temperature_breach_config.rs index 4c83d74d68..0f1830782c 100644 --- a/server/service/src/sync/translations/temperature_breach_config.rs +++ b/server/service/src/sync/translations/temperature_breach_config.rs @@ -2,7 +2,7 @@ use crate::sync::{api::RemoteSyncRecordV5, sync_serde::empty_str_as_option_strin use repository::{ ChangelogRow, ChangelogTableName, StorageConnection, SyncBufferRow, TemperatureBreachConfigRow, - TemperatureBreachConfigRowRepository, TemperatureBreachRowType, + TemperatureBreachConfigRowRepository, }; use serde::{Deserialize, Serialize};