Skip to content

Commit

Permalink
feat: Add tests for TPS permit migration trigger (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-fletcher-aot authored Jan 16, 2024
1 parent 995faf6 commit 21a135e
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 0 deletions.
39 changes: 39 additions & 0 deletions database/mssql/test/versions/v_12_1_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- Test that the trigger populates the ORBC_PERMIT table with
-- correct data and valid ORIGINAL_ID
SET NOCOUNT ON
INSERT INTO $(DB_NAME).tps.ORBC_TPS_MIGRATED_PERMITS(
PERMIT_TYPE,
START_DATE,
END_DATE,
ISSUED_DATE,
CLIENT_HASH,
PLATE,
VIN,
PERMIT_NUMBER,
NEW_PERMIT_NUMBER,
PERMIT_GENERATION,
SERVICE)
VALUES(
'TROS',
'20240101',
'20240201',
'20240101 12:00:00PM',
'HASH',
'TSTPLT',
'TSTVIN',
'08-100-3429',
'P0-08100342-900',
1,
'C')

SELECT COUNT(*) FROM $(DB_NAME).permit.ORBC_PERMIT
WHERE
PERMIT_NUMBER = 'P0-08100342-900'
AND
REVISION = 0
AND
PERMIT_APPROVAL_SOURCE_TYPE = 'TPS'
AND
ORIGINAL_ID = ID
AND
PERMIT_STATUS_TYPE = 'ISSUED'
28 changes: 28 additions & 0 deletions database/mssql/test/versions/v_12_2_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- Test that duplicate records are not migrated into ORBC_PERMIT
SET NOCOUNT ON
INSERT INTO $(DB_NAME).tps.ORBC_TPS_MIGRATED_PERMITS(
PERMIT_TYPE,
START_DATE,
END_DATE,
ISSUED_DATE,
CLIENT_HASH,
PLATE,
VIN,
PERMIT_NUMBER,
NEW_PERMIT_NUMBER,
PERMIT_GENERATION,
SERVICE)
VALUES(
'TROS',
'20240101',
'20240201',
'20240101 12:00:00PM',
'HASH',
'TSTPLT',
'TSTVIN',
'08-100-3429',
'P0-08100342-900',
1,
'C')

SELECT COUNT(*) FROM $(DB_NAME).permit.ORBC_PERMIT -- should be still just one, from prior test
41 changes: 41 additions & 0 deletions database/mssql/test/versions/v_12_3_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-- Test that the trigger sets the correct permit number, and
-- that the previous rev id is set correctly
SET NOCOUNT ON
INSERT INTO $(DB_NAME).tps.ORBC_TPS_MIGRATED_PERMITS(
PERMIT_TYPE,
START_DATE,
END_DATE,
ISSUED_DATE,
CLIENT_HASH,
PLATE,
VIN,
PERMIT_NUMBER,
NEW_PERMIT_NUMBER,
PERMIT_GENERATION,
SERVICE)
VALUES(
'TROS',
'20240101',
'20240201',
'20240101 12:00:00PM',
'HASH',
'TSTPLT2',
'TSTVIN',
'08-100-3429',
'P0-08100342-911-A01', -- changing the incoming permit number to test
2, -- previous revision was 1, this is next one
'C')

SELECT COUNT(*) FROM $(DB_NAME).permit.ORBC_PERMIT
WHERE
PERMIT_NUMBER = 'P0-08100342-900-A01'
AND
REVISION = 1
AND
PERMIT_APPROVAL_SOURCE_TYPE = 'TPS'
AND
ORIGINAL_ID = (SELECT ID FROM $(DB_NAME).permit.ORBC_PERMIT WHERE PERMIT_NUMBER = 'P0-08100342-900')
AND
PERMIT_STATUS_TYPE = 'ISSUED'
AND
PREVIOUS_REV_ID = (SELECT ID FROM $(DB_NAME).permit.ORBC_PERMIT WHERE PERMIT_NUMBER = 'P0-08100342-900')
11 changes: 11 additions & 0 deletions database/mssql/test/versions/v_12_4_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Test that the trigger sets previous revision to SUPERSEDED
SET NOCOUNT ON
SELECT COUNT(*) FROM $(DB_NAME).permit.ORBC_PERMIT
WHERE
PERMIT_NUMBER = 'P0-08100342-900'
AND
REVISION = 0
AND
PERMIT_APPROVAL_SOURCE_TYPE = 'TPS'
AND
PERMIT_STATUS_TYPE = 'SUPERSEDED'
37 changes: 37 additions & 0 deletions database/mssql/test/versions/v_12_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Retrieve arguments
source ${SCRIPT_DIR}/utility/getopt.sh
USAGE="-u USER -p PASS -s SERVER -d DATABASE"
parse_options "${USAGE}" ${@}

# All database tests for database version 12 are run from this shell script.
# TESTS_DIR variable set by the calling test-runner script.

TEST_12_1_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_12_1_test.sql | xargs)
if [[ $TEST_12_1_RESULT -eq 1 ]]; then
echo "Test 12.1 passed: Trigger is populating records into ORBC_PERMIT"
else
echo "******** Test 12.1 failed: Trigger not populating records into ORBC_PERMIT"
fi

TEST_12_2_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_12_2_test.sql | xargs)
if [[ $TEST_12_2_RESULT -eq 1 ]]; then
echo "Test 12.2 passed: Duplicate records not being inserted into ORBC_PERMIT"
else
echo "******** Test 12.2 failed: Duplicate records being inserted into ORBC_PERMIT"
fi

TEST_12_3_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_12_3_test.sql | xargs)
if [[ $TEST_12_3_RESULT -eq 1 ]]; then
echo "Test 12.3 passed: Permit number of amendments being adjusted correctly"
else
echo "******** Test 12.3 failed: Permit number of amendments not being adjusted correctly"
fi

TEST_12_4_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_12_4_test.sql | xargs)
if [[ $TEST_12_4_RESULT -eq 1 ]]; then
echo "Test 12.4 passed: Previous revisions correctly marked SUPERSEDED"
else
echo "******** Test 12.4 failed: Previous revisions not being marked SUPERSEDED"
fi

0 comments on commit 21a135e

Please sign in to comment.