Select Git revision
test_entity_versioning.sql
-
Timm Fitschen authoredTimm Fitschen authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
test_entity_versioning.sql 7.49 KiB
USE _caosdb_schema_unit_tests;
BEGIN;
CALL tap.no_plan();
-- #####################################################################
-- TEST insert_single_child_version, get_primary_parent_version and
-- delete_all_entity_versions in isolation
-- #####################################################################
-- SETUP
-- Disable versioning because we want to test `insert_single_child_version`
-- separately from `insertEntity` but the former is called inside the latter
-- when versioning is enabled.
DELETE FROM feature_config WHERE _key = "ENTITY_VERSIONING";
INSERT INTO transactions (srid,seconds,nanos,username,realm) VALUES
("SRIDbla", 1234, 2345, "me", "home"),
("SRIDblub", 2345, 3465, "me", "home"),
("SRIDblieb", 3456, 4576, "you", "home");
DELETE FROM entities WHERE name="EntityName";
CALL entityACL(@ACLID1, "{acl1}");
CALL insertEntity("EntityName", "EntityDesc", "RECORDTYPE", "{acl1}");
SELECT id INTO @EntityID FROM entities WHERE name="EntityName";
-- TEST insert_single_child_version
SELECT count(*) INTO @x FROM entity_version;
SELECT tap.eq(@x, 0, "no versions there yet");
CALL insert_single_child_version(@EntityID, "hashbla", "versionbla", NULL, "SRIDbla");
SELECT tap.eq(_ipparent, NULL, "no parent for the first version")
FROM entity_version WHERE version="versionbla" AND _is_head IS TRUE;
SELECT tap.eq(_ipparent, NULL, "no parent for the first version")
FROM entity_version WHERE version="versionbla" AND _is_head IS FALSE;
-- add a second version
SELECT tap.eq(count(*), 1, "one version there yet")
FROM entity_version WHERE _is_head IS FALSE;
CALL insert_single_child_version(@EntityID, "hashblub", "versionblub", "versionbla", "SRIDblub");
SELECT _ipparent INTO @x from entity_version WHERE version="versionblub" AND _is_head IS TRUE;
SELECT tap.eq(@x, 1, "the original entity is the parent");
-- test error: parent does not exist
SELECT count(DISTINCT version) INTO @x FROM entity_version;
SELECT tap.eq(@x, 2, "two version there yet");
CALL tap._assert_throws(concat("CALL insert_single_child_version(", @EntityID, ', "hashblieb", "versionblieb", "non-existing-parent", "SRIDBlieb")'), "non existing parent throws");
SELECT tap.eq(count(DISTINCT version), 2, "still two version there")
FROM entity_version;
-- TEST get_primary_parent_version
SELECT tap.eq(get_primary_parent_version(@EntityID, "versionblub"), "versionbla", "returns correct parent for versionblub");
SELECT tap.eq(get_primary_parent_version(@EntityID, "versionbla"), NULL, "versionbla has no parent");
-- TEST delete_all_entity_versions
SELECT count(*) INTO @x FROM entity_version;
SELECT tap.ok(@x > 0, "several versions in the table");
CALL delete_all_entity_versions(@EntityID);
SELECT count(*) INTO @x FROM entity_version;
SELECT tap.eq(@x, 0, "no versions there any more");
-- TEARDOWN clean up a litte