From 60ba821af7b3e626ba33ce048e237a76a5b3463b Mon Sep 17 00:00:00 2001 From: xbgmsharp Date: Sun, 22 Jun 2025 10:42:33 +0200 Subject: [PATCH] Update tests, add stays_ext unit tests --- tests/sql/stays_ext.sql | 47 ++++++++++++++++++++++++++++++++++ tests/sql/stays_ext.sql.output | 37 ++++++++++++++++++++++++++ tests/tests.sh | 13 ++++++++++ 3 files changed, 97 insertions(+) create mode 100644 tests/sql/stays_ext.sql create mode 100644 tests/sql/stays_ext.sql.output diff --git a/tests/sql/stays_ext.sql b/tests/sql/stays_ext.sql new file mode 100644 index 0000000..978f384 --- /dev/null +++ b/tests/sql/stays_ext.sql @@ -0,0 +1,47 @@ +--------------------------------------------------------------------------- +-- Listing +-- + +-- List current database +select current_database(); + +-- connect to the DB +\c signalk + +-- output display format +\x on + +SELECT count(*) as count_eq_0 FROM api.stays_ext m; + +SELECT v.vessel_id as "vessel_id" FROM auth.vessels v WHERE v.owner_email = 'demo+kapla@openplotter.cloud' \gset +--\echo :"vessel_id" +SELECT set_config('vessel.id', :'vessel_id', false) IS NOT NULL as vessel_id; + +-- user_role +SET ROLE user_role; + +\echo 'api.stays details' +SELECT vessel_id IS NOT NULL AS vessel_id_not_null, m.name IS NOT NULL AS name_not_null FROM api.stays AS m WHERE active IS False ORDER BY m.name ASC; + +-- Upsert image on stays_ext table +\echo 'api.stays_ext set image/image_b64' +INSERT INTO api.stays_ext (vessel_id, stay_id, image_b64) + VALUES (current_setting('vessel.id', false), 1, 'iVBORw0KGgoAAAANSUhEUgAAAMgAAAAyCAIAAACWMwO2AAABNklEQVR4nO3bwY6CMBiF0XYy7//KzIKk6VBjiMMNk59zVljRIH6WsrBv29bgal93HwA1CYsIYREhLCKERYSwiBAWEcIiQlhECIsIYREhLCKERYSwiBAWEcIiQlhECIsIYREhLCK+7z6A/6j33lq75G8m') + ON CONFLICT (stay_id) DO UPDATE + SET image_b64 = EXCLUDED.image_b64; + +-- Ensure image_updated_at on metadata_ext table is updated by trigger +\echo 'api.stays_ext get image_updated_at' +SELECT image_b64 IS NULL AS image_b64_is_null,image IS NOT NULL AS image_not_null,image_updated_at IS NOT NULL AS image_updated_at_not_null FROM api.metadata_ext; --WHERE vessel_id = current_setting('vessel.id', false); + +-- vessel_role +SET ROLE vessel_role; + +\echo 'api.stays_ext' +SELECT vessel_id IS NOT NULL AS vessel_id_not_null, stay_id FROM api.stays_ext; + +-- api_anonymous +SET ROLE api_anonymous; + +\echo 'api_anonymous get stays image' +SELECT api.stays_image(current_setting('vessel.id', false), 1) IS NOT NULL AS stays_image_not_null; diff --git a/tests/sql/stays_ext.sql.output b/tests/sql/stays_ext.sql.output new file mode 100644 index 0000000..46b1c7f --- /dev/null +++ b/tests/sql/stays_ext.sql.output @@ -0,0 +1,37 @@ + current_database +------------------ + signalk +(1 row) + +You are now connected to database "signalk" as user "username". +Expanded display is on. +-[ RECORD 1 ]- +count_eq_0 | 0 + +-[ RECORD 1 ] +vessel_id | t + +SET +api.stays details +-[ RECORD 1 ]------+-- +vessel_id_not_null | t +name_not_null | t +-[ RECORD 2 ]------+-- +vessel_id_not_null | t +name_not_null | t + +api.stays_ext set image/image_b64 +INSERT 0 1 +api.stays_ext get image_updated_at +-[ RECORD 1 ]-------------+-- +image_b64_is_null | f +image_not_null | t +image_updated_at_not_null | t + +SET +api.stays_ext +SET +api_anonymous get stays image +-[ RECORD 1 ]--------+-- +stays_image_not_null | t + diff --git a/tests/tests.sh b/tests/tests.sh index b063bb6..b04af41 100644 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -139,6 +139,19 @@ else exit fi +# Stays extended unit tests +psql ${PGSAIL_DB_URI} < sql/stays_ext.sql > output/stays_ext.sql.output +diff sql/stays_ext.sql.output output/stays_ext.sql.output > /dev/null +#diff -u sql/stays_ext.sql.output output/stays_ext.sql.output | wc -l +#echo 0 +if [ $? -eq 0 ]; then + echo OK +else + echo SQL stays_ext.sql FAILED + diff -u sql/stays_ext.sql.output output/stays_ext.sql.output + exit 1 +fi + # Summary unit tests psql ${PGSAIL_DB_URI} < sql/summary.sql > output/summary.sql.output diff sql/summary.sql.output output/summary.sql.output > /dev/null