-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add temperature log/breach/config tests
- Loading branch information
Showing
6 changed files
with
207 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
server/service/src/sync/test/test_data/temperature_breach.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TestSyncPullRecord> { | ||
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<TestSyncPushRecord> { | ||
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(), | ||
}), | ||
}] | ||
} |
54 changes: 54 additions & 0 deletions
54
server/service/src/sync/test/test_data/temperature_breach_config.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TestSyncPullRecord> { | ||
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<TestSyncPushRecord> { | ||
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, | ||
}), | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TestSyncPullRecord> { | ||
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<TestSyncPushRecord> { | ||
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(), | ||
}), | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters