From 3c4b1066dfd2a294bfed131920ced3c1be89ac07 Mon Sep 17 00:00:00 2001 From: Alex Groleau Date: Mon, 23 Mar 2026 12:25:55 -0400 Subject: [PATCH] fixed merger with anchor test issue --- fixtures/merger.json | 110 +++++++++++++++++++++++++++++++++++++++++- fixtures/t1.json | 38 --------------- src/tests/fixtures.rs | 6 +++ 3 files changed, 115 insertions(+), 39 deletions(-) delete mode 100644 fixtures/t1.json diff --git a/fixtures/merger.json b/fixtures/merger.json index fb08267..925aada 100644 --- a/fixtures/merger.json +++ b/fixtures/merger.json @@ -2403,7 +2403,7 @@ } }, { - "description": "Anchor order and insert new line", + "description": "Anchor order and insert new line (no line id)", "action": "merge", "data": { "id": "abc", @@ -2502,6 +2502,114 @@ ] ] } + }, + { + "description": "Anchor order and insert new line (with line id)", + "action": "merge", + "data": { + "id": "abc", + "type": "order", + "lines": [ + { + "id": "11111111-2222-3333-4444-555555555555", + "type": "order_line", + "product": "Widget", + "price": 99.0 + } + ] + }, + "schema_id": "order", + "expect": { + "success": true, + "sql": [ + [ + "SELECT to_jsonb(t1.*) || to_jsonb(t2.*)", + "FROM agreego.\"order_line\" t1", + "LEFT JOIN agreego.\"entity\" t2 ON t2.id = t1.id", + "WHERE t1.id = '11111111-2222-3333-4444-555555555555'" + ], + [ + "INSERT INTO agreego.\"entity\" (", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", + ")", + "VALUES (", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '11111111-2222-3333-4444-555555555555',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'order_line'", + ")" + ], + [ + "INSERT INTO agreego.\"order_line\" (", + " \"id\",", + " \"order_id\",", + " \"price\",", + " \"product\",", + " \"type\"", + ")", + "VALUES (", + " '11111111-2222-3333-4444-555555555555',", + " 'abc',", + " 99,", + " 'Widget',", + " 'order_line'", + ")" + ], + [ + "INSERT INTO agreego.change (", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", + ")", + "VALUES (", + " NULL,", + " '{", + " \"order_id\":\"abc\",", + " \"price\":99.0,", + " \"product\":\"Widget\",", + " \"type\":\"order_line\"", + " }',", + " '11111111-2222-3333-4444-555555555555',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", + ")" + ], + [ + "SELECT pg_notify('entity', '{", + " \"complete\":{", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"id\":\"11111111-2222-3333-4444-555555555555\",", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"order_id\":\"abc\",", + " \"price\":99.0,", + " \"product\":\"Widget\",", + " \"type\":\"order_line\"", + " },", + " \"new\":{", + " \"order_id\":\"abc\",", + " \"price\":99.0,", + " \"product\":\"Widget\",", + " \"type\":\"order_line\"", + " }", + " }')" + ] + ] + } } ] } diff --git a/fixtures/t1.json b/fixtures/t1.json deleted file mode 100644 index 5c24c38..0000000 --- a/fixtures/t1.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "description": "Person ad-hoc email addresses select", - "action": "query", - "schema_id": "full.person/email_addresses", - "expect": { - "success": true, - "sql": [ - [ - "(SELECT jsonb_build_object(", - " 'archived', entity_3.archived,", - " 'created_at', entity_3.created_at,", - " 'id', entity_3.id,", - " 'is_primary', contact_1.is_primary,", - " 'name', entity_3.name,", - " 'target',", - " (SELECT jsonb_build_object(", - " 'address', email_address_4.address,", - " 'archived', entity_5.archived,", - " 'created_at', entity_5.created_at,", - " 'id', entity_5.id,", - " 'name', entity_5.name,", - " 'type', entity_5.type", - " )", - " FROM agreego.email_address email_address_4", - " JOIN agreego.entity entity_5 ON entity_5.id = email_address_4.id", - " WHERE", - " NOT entity_5.archived", - " AND relationship_2.target_id = entity_5.id),", - " 'type', entity_3.type", - ")", - "FROM agreego.contact contact_1", - "JOIN agreego.relationship relationship_2 ON relationship_2.id = contact_1.id", - "JOIN agreego.entity entity_3 ON entity_3.id = relationship_2.id", - "WHERE NOT entity_3.archived)" - ] - ] - } -} diff --git a/src/tests/fixtures.rs b/src/tests/fixtures.rs index b541eef..1d9a396 100644 --- a/src/tests/fixtures.rs +++ b/src/tests/fixtures.rs @@ -8554,3 +8554,9 @@ fn test_merger_0_9() { let path = format!("{}/fixtures/merger.json", env!("CARGO_MANIFEST_DIR")); crate::tests::runner::run_test_case(&path, 0, 9).unwrap(); } + +#[test] +fn test_merger_0_10() { + let path = format!("{}/fixtures/merger.json", env!("CARGO_MANIFEST_DIR")); + crate::tests::runner::run_test_case(&path, 0, 10).unwrap(); +}