Skip to content

Commit

Permalink
Some(changes) as suggested by Andrei + ran cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianwb committed Aug 30, 2023
1 parent bf2b501 commit bf73a5c
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 200 deletions.
7 changes: 2 additions & 5 deletions server/repository/src/migrations/v1_02_00/sensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ pub(crate) fn migrate(connection: &StorageConnection) -> anyhow::Result<()> {
"#
)?;

#[cfg(feature = "postgres")]
{
if cfg!(feature = "postgres") {
sql!(
connection,
r#"
Expand All @@ -76,9 +75,7 @@ pub(crate) fn migrate(connection: &StorageConnection) -> anyhow::Result<()> {
FOR EACH ROW EXECUTE PROCEDURE update_changelog();
"#
)?;
}
#[cfg(not(feature = "postgres"))]
{
} else {
sql!(
connection,
r#"
Expand Down
14 changes: 12 additions & 2 deletions server/service/src/sync/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,20 @@ pub(crate) async fn check_records_against_database(
check_record_by_id!(TemperatureLogRowRepository, con, record, "TemperatureLog");
}
TemperatureBreach(record) => {
check_record_by_id!(TemperatureBreachRowRepository, con, record, "TemperatureBreach");
check_record_by_id!(
TemperatureBreachRowRepository,
con,
record,
"TemperatureBreach"
);
}
TemperatureBreachConfig(record) => {
check_record_by_id!(TemperatureBreachConfigRowRepository, con, record, "TemperatureBreachConfig");
check_record_by_id!(
TemperatureBreachConfigRowRepository,
con,
record,
"TemperatureBreachConfig"
);
}
Location(record) => {
check_record_by_id!(LocationRowRepository, con, record, "Location");
Expand Down
161 changes: 82 additions & 79 deletions server/service/src/sync/test/test_data/temperature_breach.rs
Original file line number Diff line number Diff line change
@@ -1,79 +1,82 @@
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(),
}),
}]
}
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(),
}),
}]
}
111 changes: 57 additions & 54 deletions server/service/src/sync/test/test_data/temperature_breach_config.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
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,
}),
}]
}
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,
}),
}]
}
Loading

0 comments on commit bf73a5c

Please sign in to comment.