diff --git a/fixtures/merger.json b/fixtures/merger.json index 5e3e14e..93aa953 100644 --- a/fixtures/merger.json +++ b/fixtures/merger.json @@ -1,597 +1,11 @@ [ { - "description": "Basic Merger Execution", - "database": { - "puncs": [], - "enums": [], - "relations": [], - "types": [ - { - "name": "entity", - "schemas": [ - { - "$id": "entity", - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "type": { - "type": "string" - }, - "archived": { - "type": "boolean" - }, - "created_by": { - "type": "string" - }, - "modified_by": { - "type": "string" - }, - "created_at": { - "type": "string", - "format": "date-time" - }, - "modified_at": { - "type": "string", - "format": "date-time" - } - }, - "required": [ - "id", - "type", - "created_by", - "created_at", - "modified_by", - "modified_at" - ] - } - ], - "hierarchy": [ - "entity" - ], - "fields": [ - "id", - "type", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ], - "grouped_fields": { - "entity": [ - "id", - "type", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ] - }, - "lookup_fields": [], - "historical": false, - "relationship": false - }, - { - "name": "simple_entity", - "schemas": [ - { - "$id": "simple_entity", - "$ref": "entity", - "properties": { - "name": { - "type": "string" - } - }, - "required": [ - "name" - ] - } - ], - "hierarchy": [ - "simple_entity", - "entity" - ], - "fields": [ - "id", - "type", - "name", - "created_at", - "created_by", - "modified_at", - "modified_by" - ], - "grouped_fields": { - "simple_entity": [ - "id", - "type", - "name" - ], - "entity": [ - "id", - "type", - "created_at", - "created_by", - "modified_at", - "modified_by" - ] - }, - "lookup_fields": [], - "historical": false, - "relationship": false - } - ] - }, - "tests": [ - { - "description": "Should execute a standard UPSERT via the mock database", - "action": "merge", - "data": { - "id": "123", - "type": "simple_entity", - "name": "Jane" - }, - "expect": { - "success": true, - "sql": [ - "SELECT to_jsonb(t1.*) || to_jsonb(t2.*) FROM agreego.\"simple_entity\" t1 LEFT JOIN agreego.\"entity\" t2 ON t2.id = t1.id WHERE t1.id = '123'", - "INSERT INTO agreego.\"entity\" (\"created_at\", \"created_by\", \"id\", \"modified_at\", \"modified_by\", \"type\") VALUES ('{{timestamp}}', '00000000-0000-0000-0000-000000000000', '123', '{{timestamp}}', '00000000-0000-0000-0000-000000000000', 'simple_entity')", - "INSERT INTO agreego.\"simple_entity\" (\"id\", \"name\", \"type\") VALUES ('123', 'Jane', 'simple_entity')", - "INSERT INTO agreego.change (changes, entity_id, id, kind, modified_at, modified_by) VALUES ('{\"name\":\"Jane\",\"type\":\"simple_entity\"}', '123', '{{uuid}}', 'create', '{{timestamp}}', '00000000-0000-0000-0000-000000000000')", - "SELECT pg_notify('entity', '{\"complete\":{\"created_at\":\"{{timestamp}}\",\"created_by\":\"00000000-0000-0000-0000-000000000000\",\"id\":\"123\",\"modified_at\":\"{{timestamp}}\",\"modified_by\":\"00000000-0000-0000-0000-000000000000\",\"name\":\"Jane\",\"type\":\"simple_entity\"}}')" - ] - } - } - ] - }, - { - "description": "Hierarchical Lookups and Inserts", - "database": { - "puncs": [], - "enums": [], - "relations": [], - "types": [ - { - "name": "entity", - "schemas": [ - { - "$id": "entity", - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "type": { - "type": "string" - }, - "archived": { - "type": "boolean" - }, - "created_by": { - "type": "string" - }, - "modified_by": { - "type": "string" - }, - "created_at": { - "type": "string", - "format": "date-time" - }, - "modified_at": { - "type": "string", - "format": "date-time" - } - }, - "required": [ - "id", - "type", - "created_by", - "created_at", - "modified_by", - "modified_at" - ] - } - ], - "hierarchy": [ - "entity" - ], - "fields": [ - "id", - "type", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ], - "grouped_fields": { - "entity": [ - "id", - "type", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ] - }, - "lookup_fields": [], - "historical": false, - "relationship": false - }, - { - "name": "organization", - "schemas": [ - { - "$id": "organization", - "$ref": "entity", - "properties": { - "name": { - "type": "string" - } - } - } - ], - "hierarchy": [ - "organization", - "entity" - ], - "fields": [ - "id", - "type", - "name", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ], - "grouped_fields": { - "organization": [ - "id", - "type", - "name" - ], - "entity": [ - "id", - "type", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ] - }, - "lookup_fields": [], - "historical": true, - "relationship": false - }, - { - "name": "user", - "schemas": [ - { - "$id": "user", - "$ref": "organization", - "properties": {} - } - ], - "hierarchy": [ - "user", - "organization", - "entity" - ], - "fields": [ - "id", - "type", - "name", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ], - "grouped_fields": { - "user": [ - "id", - "type" - ], - "organization": [ - "id", - "type", - "name" - ], - "entity": [ - "id", - "type", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ] - }, - "lookup_fields": [], - "historical": true, - "relationship": false - }, - { - "name": "person", - "schemas": [ - { - "$id": "person", - "$ref": "user", - "properties": { - "first_name": { - "type": "string" - }, - "last_name": { - "type": "string" - }, - "date_of_birth": { - "type": "string" - }, - "pronouns": { - "type": "string" - }, - "contact_id": { - "type": "string" - } - } - } - ], - "hierarchy": [ - "person", - "user", - "organization", - "entity" - ], - "fields": [ - "id", - "type", - "first_name", - "last_name", - "date_of_birth", - "pronouns", - "contact_id", - "name", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ], - "grouped_fields": { - "person": [ - "id", - "type", - "first_name", - "last_name", - "date_of_birth", - "pronouns", - "contact_id" - ], - "user": [ - "id", - "type" - ], - "organization": [ - "id", - "type", - "name" - ], - "entity": [ - "id", - "type", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ] - }, - "lookup_fields": [ - "first_name", - "last_name", - "date_of_birth", - "pronouns" - ], - "historical": true, - "relationship": false - }, - { - "name": "order", - "schemas": [ - { - "$id": "order", - "$ref": "entity", - "properties": { - "total": { - "type": "number" - }, - "customer_id": { - "type": "string" - } - } - } - ], - "hierarchy": [ - "order", - "entity" - ], - "fields": [ - "id", - "type", - "total", - "customer_id", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ], - "grouped_fields": { - "order": [ - "id", - "type", - "total", - "customer_id" - ], - "entity": [ - "id", - "type", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ] - }, - "lookup_fields": [ - "id" - ], - "historical": true, - "relationship": false - }, - { - "name": "order_line", - "schemas": [ - { - "$id": "order_line", - "$ref": "entity", - "properties": { - "order_id": { - "type": "string" - }, - "product": { - "type": "string" - }, - "price": { - "type": "number" - } - } - } - ], - "hierarchy": [ - "order_line", - "entity" - ], - "fields": [ - "id", - "type", - "order_id", - "product", - "price", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ], - "grouped_fields": { - "order_line": [ - "id", - "type", - "order_id", - "product", - "price" - ], - "entity": [ - "id", - "type", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ] - }, - "lookup_fields": [], - "historical": true, - "relationship": false - } - ] - }, - "tests": [ - { - "description": "Should query by ID if provided, rather than looking up by fields", - "action": "merge", - "data": { - "id": "123", - "type": "person", - "first_name": "John", - "last_name": "Doe", - "date_of_birth": "1990-01-01T00:00:00Z" - }, - "expect": { - "success": true, - "sql": [ - "SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"person\" t1 LEFT JOIN agreego.\"user\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"organization\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"entity\" t4 ON t4.id = t1.id WHERE t1.id = '123'", - "INSERT INTO agreego.\"entity\" (\"created_at\", \"created_by\", \"id\", \"modified_at\", \"modified_by\", \"type\") VALUES ('{{timestamp}}', '00000000-0000-0000-0000-000000000000', '123', '{{timestamp}}', '00000000-0000-0000-0000-000000000000', 'person')", - "INSERT INTO agreego.\"organization\" (\"id\", \"type\") VALUES ('123', 'person')", - "INSERT INTO agreego.\"user\" (\"id\", \"type\") VALUES ('123', 'person')", - "INSERT INTO agreego.\"person\" (\"date_of_birth\", \"first_name\", \"id\", \"last_name\", \"type\") VALUES ('1990-01-01T00:00:00Z', 'John', '123', 'Doe', 'person')", - "INSERT INTO agreego.change (changes, entity_id, id, kind, modified_at, modified_by) VALUES ('{\"date_of_birth\":\"1990-01-01T00:00:00Z\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"type\":\"person\"}', '123', '{{uuid}}', 'create', '{{timestamp}}', '00000000-0000-0000-0000-000000000000')", - "SELECT pg_notify('entity', '{\"complete\":{\"created_at\":\"{{timestamp}}\",\"created_by\":\"00000000-0000-0000-0000-000000000000\",\"date_of_birth\":\"1990-01-01T00:00:00Z\",\"first_name\":\"John\",\"id\":\"123\",\"last_name\":\"Doe\",\"modified_at\":\"{{timestamp}}\",\"modified_by\":\"00000000-0000-0000-0000-000000000000\",\"type\":\"person\"}}')" - ] - } - }, - { - "description": "Should execute a lookup based on defined lookup_fields because no ID is provided", - "action": "merge", - "data": { - "type": "person", - "first_name": "John", - "last_name": "Doe", - "date_of_birth": "1990-01-01T00:00:00Z" - }, - "expect": { - "success": true, - "sql": [ - "SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"person\" t1 LEFT JOIN agreego.\"user\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"organization\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"entity\" t4 ON t4.id = t1.id WHERE \"first_name\" = 'John' AND \"last_name\" = 'Doe' AND \"date_of_birth\" = '1990-01-01T00:00:00Z' AND \"pronouns\" IS NULL", - "INSERT INTO agreego.\"entity\" (\"created_at\", \"created_by\", \"id\", \"modified_at\", \"modified_by\", \"type\") VALUES ('{{timestamp}}', '00000000-0000-0000-0000-000000000000', '{{uuid:person_1}}', '{{timestamp}}', '00000000-0000-0000-0000-000000000000', 'person')", - "INSERT INTO agreego.\"organization\" (\"id\", \"type\") VALUES ('{{uuid:person_1}}', 'person')", - "INSERT INTO agreego.\"user\" (\"id\", \"type\") VALUES ('{{uuid:person_1}}', 'person')", - "INSERT INTO agreego.\"person\" (\"date_of_birth\", \"first_name\", \"id\", \"last_name\", \"type\") VALUES ('1990-01-01T00:00:00Z', 'John', '{{uuid:person_1}}', 'Doe', 'person')", - "INSERT INTO agreego.change (changes, entity_id, id, kind, modified_at, modified_by) VALUES ('{\"date_of_birth\":\"1990-01-01T00:00:00Z\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"type\":\"person\"}', '{{uuid:person_1}}', '{{uuid}}', 'create', '{{timestamp}}', '00000000-0000-0000-0000-000000000000')", - "SELECT pg_notify('entity', '{\"complete\":{\"created_at\":\"{{timestamp}}\",\"created_by\":\"00000000-0000-0000-0000-000000000000\",\"date_of_birth\":\"1990-01-01T00:00:00Z\",\"first_name\":\"John\",\"id\":\"{{uuid:person_1}}\",\"last_name\":\"Doe\",\"modified_at\":\"{{timestamp}}\",\"modified_by\":\"00000000-0000-0000-0000-000000000000\",\"type\":\"person\"}}')" - ] - } - }, - { - "description": "Should explicitly null out fields provided as empty strings", - "action": "merge", - "data": { - "id": "123", - "type": "person", - "first_name": "John", - "last_name": "Doe", - "date_of_birth": "1990-01-01T00:00:00Z", - "pronouns": "" - }, - "expect": { - "success": true, - "sql": [ - "SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"person\" t1 LEFT JOIN agreego.\"user\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"organization\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"entity\" t4 ON t4.id = t1.id WHERE t1.id = '123'", - "INSERT INTO agreego.\"entity\" (\"created_at\", \"created_by\", \"id\", \"modified_at\", \"modified_by\", \"type\") VALUES ('{{timestamp}}', '00000000-0000-0000-0000-000000000000', '123', '{{timestamp}}', '00000000-0000-0000-0000-000000000000', 'person')", - "INSERT INTO agreego.\"organization\" (\"id\", \"type\") VALUES ('123', 'person')", - "INSERT INTO agreego.\"user\" (\"id\", \"type\") VALUES ('123', 'person')", - "INSERT INTO agreego.\"person\" (\"date_of_birth\", \"first_name\", \"id\", \"last_name\", \"pronouns\", \"type\") VALUES ('1990-01-01T00:00:00Z', 'John', '123', 'Doe', NULL, 'person')", - "INSERT INTO agreego.change (changes, entity_id, id, kind, modified_at, modified_by) VALUES ('{\"date_of_birth\":\"1990-01-01T00:00:00Z\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"pronouns\":\"\",\"type\":\"person\"}', '123', '{{uuid}}', 'create', '{{timestamp}}', '00000000-0000-0000-0000-000000000000')", - "SELECT pg_notify('entity', '{\"complete\":{\"created_at\":\"{{timestamp}}\",\"created_by\":\"00000000-0000-0000-0000-000000000000\",\"date_of_birth\":\"1990-01-01T00:00:00Z\",\"first_name\":\"John\",\"id\":\"123\",\"last_name\":\"Doe\",\"modified_at\":\"{{timestamp}}\",\"modified_by\":\"00000000-0000-0000-0000-000000000000\",\"pronouns\":\"\",\"type\":\"person\"}}')" - ] - } - } - ] - }, - { - "description": "Nested Relationship Mapping", + "description": "Merger Execution", "database": { "puncs": [], "enums": [ { - "id": "e-type-1", + "id": "11111111-1111-1111-1111-111111111111", "type": "relation_type", "enum": "relation_type", "values": [ @@ -603,7 +17,7 @@ ], "relations": [ { - "id": "r-order-customer", + "id": "22222222-2222-2222-2222-222222222222", "type": "relation", "constraint": "fk_order_customer", "source_type": "order", @@ -617,7 +31,7 @@ "prefix": "customer" }, { - "id": "r-order-lines", + "id": "33333333-3333-3333-3333-333333333333", "type": "relation", "constraint": "fk_order_line_order", "source_type": "order_line", @@ -994,7 +408,76 @@ }, "tests": [ { - "description": "Should execute a 1:1 nested relation and cascade child IDs to parent", + "description": "Person insert with id (no lookup)", + "action": "merge", + "data": { + "id": "123", + "type": "person", + "first_name": "John", + "last_name": "Doe", + "date_of_birth": "1990-01-01T00:00:00Z" + }, + "expect": { + "success": true, + "sql": [ + "SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"person\" t1 LEFT JOIN agreego.\"user\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"organization\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"entity\" t4 ON t4.id = t1.id WHERE t1.id = '123'", + "INSERT INTO agreego.\"entity\" (\"created_at\", \"created_by\", \"id\", \"modified_at\", \"modified_by\", \"type\") VALUES ('{{timestamp}}', '00000000-0000-0000-0000-000000000000', '123', '{{timestamp}}', '00000000-0000-0000-0000-000000000000', 'person')", + "INSERT INTO agreego.\"organization\" (\"id\", \"type\") VALUES ('123', 'person')", + "INSERT INTO agreego.\"user\" (\"id\", \"type\") VALUES ('123', 'person')", + "INSERT INTO agreego.\"person\" (\"date_of_birth\", \"first_name\", \"id\", \"last_name\", \"type\") VALUES ('1990-01-01T00:00:00Z', 'John', '123', 'Doe', 'person')", + "INSERT INTO agreego.change (changes, entity_id, id, kind, modified_at, modified_by) VALUES ('{\"date_of_birth\":\"1990-01-01T00:00:00Z\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"type\":\"person\"}', '123', '{{uuid}}', 'create', '{{timestamp}}', '00000000-0000-0000-0000-000000000000')", + "SELECT pg_notify('entity', '{\"complete\":{\"created_at\":\"{{timestamp}}\",\"created_by\":\"00000000-0000-0000-0000-000000000000\",\"date_of_birth\":\"1990-01-01T00:00:00Z\",\"first_name\":\"John\",\"id\":\"123\",\"last_name\":\"Doe\",\"modified_at\":\"{{timestamp}}\",\"modified_by\":\"00000000-0000-0000-0000-000000000000\",\"type\":\"person\"}}')" + ] + } + }, + { + "description": "Person insert with no id (lookup)", + "action": "merge", + "data": { + "type": "person", + "first_name": "John", + "last_name": "Doe", + "date_of_birth": "1990-01-01T00:00:00Z" + }, + "expect": { + "success": true, + "sql": [ + "SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"person\" t1 LEFT JOIN agreego.\"user\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"organization\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"entity\" t4 ON t4.id = t1.id WHERE \"first_name\" = 'John' AND \"last_name\" = 'Doe' AND \"date_of_birth\" = '1990-01-01T00:00:00Z' AND \"pronouns\" IS NULL", + "INSERT INTO agreego.\"entity\" (\"created_at\", \"created_by\", \"id\", \"modified_at\", \"modified_by\", \"type\") VALUES ('{{timestamp}}', '00000000-0000-0000-0000-000000000000', '{{uuid:person_1}}', '{{timestamp}}', '00000000-0000-0000-0000-000000000000', 'person')", + "INSERT INTO agreego.\"organization\" (\"id\", \"type\") VALUES ('{{uuid:person_1}}', 'person')", + "INSERT INTO agreego.\"user\" (\"id\", \"type\") VALUES ('{{uuid:person_1}}', 'person')", + "INSERT INTO agreego.\"person\" (\"date_of_birth\", \"first_name\", \"id\", \"last_name\", \"type\") VALUES ('1990-01-01T00:00:00Z', 'John', '{{uuid:person_1}}', 'Doe', 'person')", + "INSERT INTO agreego.change (changes, entity_id, id, kind, modified_at, modified_by) VALUES ('{\"date_of_birth\":\"1990-01-01T00:00:00Z\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"type\":\"person\"}', '{{uuid:person_1}}', '{{uuid}}', 'create', '{{timestamp}}', '00000000-0000-0000-0000-000000000000')", + "SELECT pg_notify('entity', '{\"complete\":{\"created_at\":\"{{timestamp}}\",\"created_by\":\"00000000-0000-0000-0000-000000000000\",\"date_of_birth\":\"1990-01-01T00:00:00Z\",\"first_name\":\"John\",\"id\":\"{{uuid:person_1}}\",\"last_name\":\"Doe\",\"modified_at\":\"{{timestamp}}\",\"modified_by\":\"00000000-0000-0000-0000-000000000000\",\"type\":\"person\"}}')" + ] + } + }, + { + "description": "Should explicitly null out fields provided as empty strings", + "action": "merge", + "data": { + "id": "123", + "type": "person", + "first_name": "John", + "last_name": "Doe", + "date_of_birth": "1990-01-01T00:00:00Z", + "pronouns": "" + }, + "expect": { + "success": true, + "sql": [ + "SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"person\" t1 LEFT JOIN agreego.\"user\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"organization\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"entity\" t4 ON t4.id = t1.id WHERE t1.id = '123'", + "INSERT INTO agreego.\"entity\" (\"created_at\", \"created_by\", \"id\", \"modified_at\", \"modified_by\", \"type\") VALUES ('{{timestamp}}', '00000000-0000-0000-0000-000000000000', '123', '{{timestamp}}', '00000000-0000-0000-0000-000000000000', 'person')", + "INSERT INTO agreego.\"organization\" (\"id\", \"type\") VALUES ('123', 'person')", + "INSERT INTO agreego.\"user\" (\"id\", \"type\") VALUES ('123', 'person')", + "INSERT INTO agreego.\"person\" (\"date_of_birth\", \"first_name\", \"id\", \"last_name\", \"pronouns\", \"type\") VALUES ('1990-01-01T00:00:00Z', 'John', '123', 'Doe', NULL, 'person')", + "INSERT INTO agreego.change (changes, entity_id, id, kind, modified_at, modified_by) VALUES ('{\"date_of_birth\":\"1990-01-01T00:00:00Z\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"pronouns\":\"\",\"type\":\"person\"}', '123', '{{uuid}}', 'create', '{{timestamp}}', '00000000-0000-0000-0000-000000000000')", + "SELECT pg_notify('entity', '{\"complete\":{\"created_at\":\"{{timestamp}}\",\"created_by\":\"00000000-0000-0000-0000-000000000000\",\"date_of_birth\":\"1990-01-01T00:00:00Z\",\"first_name\":\"John\",\"id\":\"123\",\"last_name\":\"Doe\",\"modified_at\":\"{{timestamp}}\",\"modified_by\":\"00000000-0000-0000-0000-000000000000\",\"pronouns\":\"\",\"type\":\"person\"}}')" + ] + } + }, + { + "description": "Order with a nested customer person", "action": "merge", "data": { "type": "order", diff --git a/fixtures/queryer.json b/fixtures/queryer.json index 6308f66..d9c4875 100644 --- a/fixtures/queryer.json +++ b/fixtures/queryer.json @@ -1,10 +1,37 @@ [ { - "description": "Basic Queryer Execution", + "description": "Queryer Execution", "database": { "puncs": [], "enums": [], - "relations": [], + "relations": [ + { + "type": "relation", + "id": "00000000-0000-0000-0000-000000000001", + "constraint": "fk_contact_person", + "source_type": "contact", + "source_columns": [ + "source_id" + ], + "destination_type": "person", + "destination_columns": [ + "id" + ] + }, + { + "type": "relation", + "id": "00000000-0000-0000-0000-000000000002", + "constraint": "fk_contact_phone", + "source_type": "contact", + "source_columns": [ + "target_id" + ], + "destination_type": "phone_number", + "destination_columns": [ + "id" + ] + } + ], "types": [ { "name": "entity", @@ -52,142 +79,6 @@ } } ] - } - ] - }, - "tests": [ - { - "description": "Should execute a blanket SELECT query when no filters are present", - "action": "query", - "schema_id": "entity", - "expect": { - "success": true, - "sql": [ - "(SELECT jsonb_build_object('amount', t1_obj_t1.amount, 'archived', t1_obj_t1.archived, 'created_at', t1_obj_t1.created_at, 'id', t1_obj_t1.id, 'name', t1_obj_t1.name) FROM agreego.entity t1_obj_t1 WHERE NOT t1_obj_t1.archived)" - ] - } - }, - { - "description": "Should execute a blanket SELECT query isolating root stems directly", - "action": "query", - "schema_id": "entity", - "stem": "", - "expect": { - "success": true, - "sql": [ - "(SELECT jsonb_build_object('amount', t1_obj_t1.amount, 'archived', t1_obj_t1.archived, 'created_at', t1_obj_t1.created_at, 'id', t1_obj_t1.id, 'name', t1_obj_t1.name) FROM agreego.entity t1_obj_t1 WHERE NOT t1_obj_t1.archived)" - ] - } - }, - { - "description": "Should bind parameters with proper casting and ILIKE for generated generic SELECT string when using some filters", - "action": "query", - "schema_id": "entity", - "filters": { - "name": "Jane%", - "archived": false - }, - "expect": { - "success": true, - "sql": [ - "(SELECT jsonb_build_object('amount', t1_obj_t1.amount, 'archived', t1_obj_t1.archived, 'created_at', t1_obj_t1.created_at, 'id', t1_obj_t1.id, 'name', t1_obj_t1.name) FROM agreego.entity t1_obj_t1 WHERE NOT t1_obj_t1.archived AND t1_obj_t1.archived = ($1#>>'{}')::boolean AND t1_obj_t1.name ILIKE $2#>>'{}')" - ] - } - }, - { - "description": "Should bind all parameters with proper casting for complex generic SELECT string", - "action": "query", - "schema_id": "entity", - "filters": { - "id": "123e4567-e89b-12d3-a456-426614174000", - "name": "Jane%", - "amount": 100, - "created_at": "2023-01-01T00:00:00Z", - "archived": false - }, - "expect": { - "success": true, - "sql": [ - "(SELECT jsonb_build_object('amount', t1_obj_t1.amount, 'archived', t1_obj_t1.archived, 'created_at', t1_obj_t1.created_at, 'id', t1_obj_t1.id, 'name', t1_obj_t1.name) FROM agreego.entity t1_obj_t1 WHERE NOT t1_obj_t1.archived AND t1_obj_t1.amount = ($1#>>'{}')::numeric AND t1_obj_t1.archived = ($2#>>'{}')::boolean AND t1_obj_t1.created_at = ($3#>>'{}')::timestamptz AND t1_obj_t1.id = ($4#>>'{}')::uuid AND t1_obj_t1.name ILIKE $5#>>'{}')" - ] - } - } - ] - }, - { - "description": "Complex Nested Queryer Execution", - "database": { - "puncs": [], - "enums": [], - "relations": [ - { - "type": "relation", - "id": "00000000-0000-0000-0000-000000000001", - "constraint": "fk_contact_person", - "source_type": "contact", - "source_columns": [ - "source_id" - ], - "destination_type": "person", - "destination_columns": [ - "id" - ] - }, - { - "type": "relation", - "id": "00000000-0000-0000-0000-000000000002", - "constraint": "fk_contact_phone", - "source_type": "contact", - "source_columns": [ - "target_id" - ], - "destination_type": "phone_number", - "destination_columns": [ - "id" - ] - } - ], - "types": [ - { - "name": "entity", - "hierarchy": [ - "entity" - ], - "fields": [ - "id", - "type", - "archived" - ], - "grouped_fields": { - "entity": [ - "id", - "type", - "archived" - ] - }, - "field_types": { - "id": "uuid", - "type": "text", - "archived": "boolean" - }, - "schemas": [ - { - "$id": "entity", - "type": "object", - "properties": { - "id": { - "type": "string", - "format": "uuid" - }, - "type": { - "type": "string" - }, - "archived": { - "type": "boolean" - } - } - } - ] }, { "name": "person", @@ -520,6 +411,62 @@ ] }, "tests": [ + { + "description": "Should execute a blanket SELECT query when no filters are present", + "action": "query", + "schema_id": "entity", + "expect": { + "success": true, + "sql": [ + "(SELECT jsonb_build_object('amount', t1_obj_t1.amount, 'archived', t1_obj_t1.archived, 'created_at', t1_obj_t1.created_at, 'id', t1_obj_t1.id, 'name', t1_obj_t1.name) FROM agreego.entity t1_obj_t1 WHERE NOT t1_obj_t1.archived)" + ] + } + }, + { + "description": "Should execute a blanket SELECT query isolating root stems directly", + "action": "query", + "schema_id": "entity", + "stem": "", + "expect": { + "success": true, + "sql": [ + "(SELECT jsonb_build_object('amount', t1_obj_t1.amount, 'archived', t1_obj_t1.archived, 'created_at', t1_obj_t1.created_at, 'id', t1_obj_t1.id, 'name', t1_obj_t1.name) FROM agreego.entity t1_obj_t1 WHERE NOT t1_obj_t1.archived)" + ] + } + }, + { + "description": "Should bind parameters with proper casting and ILIKE for generated generic SELECT string when using some filters", + "action": "query", + "schema_id": "entity", + "filters": { + "name": "Jane%", + "archived": false + }, + "expect": { + "success": true, + "sql": [ + "(SELECT jsonb_build_object('amount', t1_obj_t1.amount, 'archived', t1_obj_t1.archived, 'created_at', t1_obj_t1.created_at, 'id', t1_obj_t1.id, 'name', t1_obj_t1.name) FROM agreego.entity t1_obj_t1 WHERE NOT t1_obj_t1.archived AND t1_obj_t1.archived = ($1#>>'{}')::boolean AND t1_obj_t1.name ILIKE $2#>>'{}')" + ] + } + }, + { + "description": "Should bind all parameters with proper casting for complex generic SELECT string", + "action": "query", + "schema_id": "entity", + "filters": { + "id": "123e4567-e89b-12d3-a456-426614174000", + "name": "Jane%", + "amount": 100, + "created_at": "2023-01-01T00:00:00Z", + "archived": false + }, + "expect": { + "success": true, + "sql": [ + "(SELECT jsonb_build_object('amount', t1_obj_t1.amount, 'archived', t1_obj_t1.archived, 'created_at', t1_obj_t1.created_at, 'id', t1_obj_t1.id, 'name', t1_obj_t1.name) FROM agreego.entity t1_obj_t1 WHERE NOT t1_obj_t1.archived AND t1_obj_t1.amount = ($1#>>'{}')::numeric AND t1_obj_t1.archived = ($2#>>'{}')::boolean AND t1_obj_t1.created_at = ($3#>>'{}')::timestamptz AND t1_obj_t1.id = ($4#>>'{}')::uuid AND t1_obj_t1.name ILIKE $5#>>'{}')" + ] + } + }, { "description": "Should execute table multi-joins on inheritance for basic schema", "action": "query", diff --git a/src/tests/fixtures.rs b/src/tests/fixtures.rs index d8cc4d3..bedb714 100644 --- a/src/tests/fixtures.rs +++ b/src/tests/fixtures.rs @@ -1434,39 +1434,39 @@ fn test_queryer_0_3() { } #[test] -fn test_queryer_1_0() { +fn test_queryer_0_4() { let path = format!("{}/fixtures/queryer.json", env!("CARGO_MANIFEST_DIR")); - crate::tests::runner::run_test_case(&path, 1, 0).unwrap(); + crate::tests::runner::run_test_case(&path, 0, 4).unwrap(); } #[test] -fn test_queryer_1_1() { +fn test_queryer_0_5() { let path = format!("{}/fixtures/queryer.json", env!("CARGO_MANIFEST_DIR")); - crate::tests::runner::run_test_case(&path, 1, 1).unwrap(); + crate::tests::runner::run_test_case(&path, 0, 5).unwrap(); } #[test] -fn test_queryer_1_2() { +fn test_queryer_0_6() { let path = format!("{}/fixtures/queryer.json", env!("CARGO_MANIFEST_DIR")); - crate::tests::runner::run_test_case(&path, 1, 2).unwrap(); + crate::tests::runner::run_test_case(&path, 0, 6).unwrap(); } #[test] -fn test_queryer_1_3() { +fn test_queryer_0_7() { let path = format!("{}/fixtures/queryer.json", env!("CARGO_MANIFEST_DIR")); - crate::tests::runner::run_test_case(&path, 1, 3).unwrap(); + crate::tests::runner::run_test_case(&path, 0, 7).unwrap(); } #[test] -fn test_queryer_1_4() { +fn test_queryer_0_8() { let path = format!("{}/fixtures/queryer.json", env!("CARGO_MANIFEST_DIR")); - crate::tests::runner::run_test_case(&path, 1, 4).unwrap(); + crate::tests::runner::run_test_case(&path, 0, 8).unwrap(); } #[test] -fn test_queryer_1_5() { +fn test_queryer_0_9() { let path = format!("{}/fixtures/queryer.json", env!("CARGO_MANIFEST_DIR")); - crate::tests::runner::run_test_case(&path, 1, 5).unwrap(); + crate::tests::runner::run_test_case(&path, 0, 9).unwrap(); } #[test] @@ -8514,31 +8514,25 @@ fn test_merger_0_0() { } #[test] -fn test_merger_1_0() { +fn test_merger_0_1() { let path = format!("{}/fixtures/merger.json", env!("CARGO_MANIFEST_DIR")); - crate::tests::runner::run_test_case(&path, 1, 0).unwrap(); + crate::tests::runner::run_test_case(&path, 0, 1).unwrap(); } #[test] -fn test_merger_1_1() { +fn test_merger_0_2() { let path = format!("{}/fixtures/merger.json", env!("CARGO_MANIFEST_DIR")); - crate::tests::runner::run_test_case(&path, 1, 1).unwrap(); + crate::tests::runner::run_test_case(&path, 0, 2).unwrap(); } #[test] -fn test_merger_1_2() { +fn test_merger_0_3() { let path = format!("{}/fixtures/merger.json", env!("CARGO_MANIFEST_DIR")); - crate::tests::runner::run_test_case(&path, 1, 2).unwrap(); + crate::tests::runner::run_test_case(&path, 0, 3).unwrap(); } #[test] -fn test_merger_2_0() { +fn test_merger_0_4() { let path = format!("{}/fixtures/merger.json", env!("CARGO_MANIFEST_DIR")); - crate::tests::runner::run_test_case(&path, 2, 0).unwrap(); -} - -#[test] -fn test_merger_2_1() { - let path = format!("{}/fixtures/merger.json", env!("CARGO_MANIFEST_DIR")); - crate::tests::runner::run_test_case(&path, 2, 1).unwrap(); + crate::tests::runner::run_test_case(&path, 0, 4).unwrap(); }