Skip to content

Commit

Permalink
Add temperature log/breach/config tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianwb committed Aug 29, 2023
1 parent 09d41b8 commit bf2b501
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 1 deletion.
9 changes: 9 additions & 0 deletions server/service/src/sync/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
9 changes: 9 additions & 0 deletions server/service/src/sync/test/test_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -60,6 +63,9 @@ pub(crate) fn get_all_pull_upsert_remote_test_records() -> Vec<TestSyncPullRecor
let mut test_records = Vec::new();
test_records.append(&mut location::test_pull_upsert_records());
test_records.append(&mut sensor::test_pull_upsert_records());
test_records.append(&mut temperature_log::test_pull_upsert_records());
test_records.append(&mut temperature_breach::test_pull_upsert_records());
test_records.append(&mut temperature_breach_config::test_pull_upsert_records());
test_records.append(&mut location_movement::test_pull_upsert_records());
test_records.append(&mut requisition_line::test_pull_upsert_records());
test_records.append(&mut requisition::test_pull_upsert_records());
Expand Down Expand Up @@ -107,6 +113,9 @@ pub(crate) fn get_all_push_test_records() -> Vec<TestSyncPushRecord> {
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());
Expand Down
79 changes: 79 additions & 0 deletions server/service/src/sync/test/test_data/temperature_breach.rs
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(),
}),
}]
}
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,
}),
}]
}
55 changes: 55 additions & 0 deletions server/service/src/sync/test/test_data/temperature_log.rs
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(),
}),
}]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down

0 comments on commit bf2b501

Please sign in to comment.