Skip to content

Commit ef6fefc

Browse files
Merge pull request #6259 from msupply-foundation/6015-sync-pull-and-push-tests-failing
6015 sync pull and push tests failing
2 parents eff076d + b7933f3 commit ef6fefc

File tree

3 files changed

+57
-13
lines changed

3 files changed

+57
-13
lines changed

server/service/src/sync/test/test_data/invoice_line.rs

+36-7
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ fn trans_line_om_fields_unset_tax_push_record() -> TestSyncOutgoingRecord {
486486
}
487487
}
488488

489-
/// When invoice line was cancelled
489+
// When invoice line was cancelled
490490
const TRANS_LINE_NEGATIVE: (&str, &str) = (
491491
"1CC10911C7F64369B965181D78696837",
492492
r#"{
@@ -535,20 +535,19 @@ const TRANS_LINE_NEGATIVE: (&str, &str) = (
535535
"sentQuantity": 0,
536536
"optionID": "",
537537
"isVVMPassed": "",
538-
"program_ID": "",
539538
"prescribedQuantity": 0,
540539
"vaccine_vial_monitor_status_ID": "",
541540
"sent_pack_size": 0,
542541
"custom_data": null,
543542
"medicine_administrator_ID": "",
544-
"om_item_code": null,
543+
"om_item_code": "item_a_code",
545544
"om_tax": null,
546-
"om_total_before_tax": null,
547-
"om_total_after_tax": null,
545+
"om_total_before_tax": 4000.0,
546+
"om_total_after_tax": 4000.0,
548547
"om_item_variant_id": null
549548
}"#,
550549
);
551-
fn trans_line_negative() -> TestSyncIncomingRecord {
550+
fn trans_line_negative_pull_record() -> TestSyncIncomingRecord {
552551
TestSyncIncomingRecord::new_pull_upsert(
553552
TABLE_NAME,
554553
TRANS_LINE_NEGATIVE,
@@ -578,14 +577,43 @@ fn trans_line_negative() -> TestSyncIncomingRecord {
578577
},
579578
)
580579
}
580+
fn trans_line_negative_push_record() -> TestSyncOutgoingRecord {
581+
TestSyncOutgoingRecord {
582+
table_name: TABLE_NAME.to_string(),
583+
record_id: TRANS_LINE_NEGATIVE.0.to_string(),
584+
push_data: json!(LegacyTransLineRow {
585+
id: TRANS_LINE_NEGATIVE.0.to_string(),
586+
invoice_id: "outbound_shipment_a".to_string(),
587+
item_id: mock_item_a().id,
588+
item_name: mock_item_a().name,
589+
item_code: Some(mock_item_a().code),
590+
stock_line_id: Some(mock_stock_line_a().id),
591+
location_id: None,
592+
batch: None,
593+
expiry_date: None,
594+
pack_size: 1.0,
595+
cost_price_per_pack: 200.0,
596+
sell_price_per_pack: 200.0,
597+
total_before_tax: Some(4000.0),
598+
total_after_tax: Some(4000.0),
599+
tax_percentage: None,
600+
r#type: LegacyTransLineType::StockIn,
601+
number_of_packs: 20.0,
602+
note: None,
603+
option_id: None,
604+
foreign_currency_price_before_tax: Some(200.0),
605+
item_variant_id: None,
606+
}),
607+
}
608+
}
581609

582610
pub(crate) fn test_pull_upsert_records() -> Vec<TestSyncIncomingRecord> {
583611
vec![
584612
trans_line_1_pull_record(),
585613
trans_line_2_pull_record(),
586614
trans_line_om_fields_pull_record(),
587615
trans_line_om_fields_unset_tax_pull_record(),
588-
trans_line_negative(),
616+
trans_line_negative_pull_record(),
589617
]
590618
}
591619

@@ -603,5 +631,6 @@ pub(crate) fn test_push_records() -> Vec<TestSyncOutgoingRecord> {
603631
trans_line_2_push_record(),
604632
trans_line_om_fields_push_record(),
605633
trans_line_om_fields_unset_tax_push_record(),
634+
trans_line_negative_push_record(),
606635
]
607636
}

server/service/src/sync/test/test_data/requisition.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn requisition_request_push_record() -> TestSyncOutgoingRecord {
120120
.unwrap()
121121
),
122122
finalised_datetime: None,
123-
max_months_of_stock: Some(5.0),
123+
max_months_of_stock: Some(4.9281314168377826),
124124
om_status: Some(RequisitionStatus::Sent),
125125
om_colour: None,
126126
expected_delivery_date: None,
@@ -282,7 +282,7 @@ const REQUISITION_OM_FIELDS: (&str, &str) = (
282282
"om_sent_datetime": "2022-03-24T14:48:00",
283283
"om_finalised_datetime": "2022-03-25T14:48:00",
284284
"om_expected_delivery_date": "2022-03-26",
285-
"om_max_months_of_stock": 10.0,
285+
"om_max_months_of_stock": 9.85626283367557,
286286
"om_status": "NEW",
287287
"om_colour": "Colour"
288288
}"#,
@@ -319,7 +319,7 @@ fn requisition_om_fields_pull_record() -> TestSyncIncomingRecord {
319319
colour: Some("Colour".to_string()),
320320
comment: Some("From request requisition 3".to_string()),
321321
their_reference: Some("From request requisition 3".to_string()),
322-
max_months_of_stock: 10.0,
322+
max_months_of_stock: 9.85626283367557,
323323
min_months_of_stock: 3.0,
324324
linked_requisition_id: Some("mock_request_draft_requisition2".to_string()),
325325
approval_status: Some(ApprovalStatusType::Approved),
@@ -368,7 +368,7 @@ fn requisition_om_fields_push_record() -> TestSyncOutgoingRecord {
368368
.unwrap()
369369
),
370370
expected_delivery_date: Some(NaiveDate::from_ymd_opt(2022, 3, 26).unwrap()),
371-
max_months_of_stock: Some(10.0),
371+
max_months_of_stock: Some(9.85626283367557),
372372
om_status: Some(RequisitionStatus::New),
373373
om_colour: Some("Colour".to_string()),
374374
approval_status: Some(LegacyAuthorisationStatus::Authorised),

server/service/src/sync/translations/program_requisition_settings.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use repository::{
22
ContextRow, NameTagRowRepository, PeriodScheduleRowRepository, ProgramRequisitionOrderTypeRow,
33
ProgramRequisitionOrderTypeRowDelete, ProgramRequisitionOrderTypeRowRepository,
44
ProgramRequisitionSettingsRow, ProgramRequisitionSettingsRowDelete,
5-
ProgramRequisitionSettingsRowRepository, ProgramRow, StorageConnection, SyncBufferRow,
5+
ProgramRequisitionSettingsRowRepository, ProgramRow, ProgramRowRepository, StorageConnection,
6+
SyncBufferRow,
67
};
78

89
use serde::Deserialize;
@@ -89,7 +90,22 @@ impl SyncTranslation for ProgramRequisitionSettingsTranslation {
8990
) -> Result<PullTranslateResult, anyhow::Error> {
9091
let data = serde_json::from_str::<LegacyListMasterRow>(&sync_record.data)?;
9192

93+
let program_repo = ProgramRowRepository::new(connection);
94+
95+
// If the master list we are translating is not a program
96+
if !data.is_program {
97+
// Check if we already have a program with the same id (is_program could have just been unchecked)
98+
match program_repo.find_one_by_id(&data.id)? {
99+
// Should translate to soft delete
100+
Some(_) => {}
101+
// This is a non-program master list, don't translate
102+
None => {
103+
return Ok(PullTranslateResult::NotMatched);
104+
}
105+
}
106+
}
92107
let upserts = generate_requisition_program(connection, data.clone())?;
108+
93109
let deletes = delete_requisition_program(connection, data)?;
94110

95111
let mut integration_operations = Vec::new();
@@ -124,7 +140,6 @@ impl SyncTranslation for ProgramRequisitionSettingsTranslation {
124140
.program_requisition_order_type_rows
125141
.into_iter()
126142
.for_each(|u| integration_operations.push(IntegrationOperation::upsert(u)));
127-
128143
Ok(PullTranslateResult::IntegrationOperations(
129144
integration_operations,
130145
))

0 commit comments

Comments
 (0)