-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit tests #172
Draft
GOmare
wants to merge
2
commits into
openmrs:main
Choose a base branch
from
GOmare:unit-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Unit tests #172
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...esources/_core/database/mysql/dimensions/dim_agegroup/test/sp_mamba_dim_agegroup_test.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- $BEGIN | ||
|
||
CALL sp_mamba_dim_agegroup_test_create(); | ||
CALL sp_mamba_dim_agegroup_test_insert(); | ||
|
||
-- $END |
68 changes: 68 additions & 0 deletions
68
...s/_core/database/mysql/dimensions/dim_agegroup/test/sp_mamba_dim_agegroup_test_create.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
-- $BEGIN | ||
-- ------------------------------------------------------------------------------------- | ||
-- Unit Test for sp_mamba_dim_agegroup_create procedure | ||
-- ------------------------------------------------------------------------------------- | ||
|
||
DROP PROCEDURE IF EXISTS test_sp_mamba_dim_agegroup_create; | ||
|
||
DELIMITER // | ||
|
||
CREATE PROCEDURE test_sp_mamba_dim_agegroup_create() | ||
BEGIN | ||
-- Step 1: Variables for test results | ||
DECLARE failed_message VARCHAR(255) DEFAULT ''; | ||
DECLARE test_failed INT DEFAULT 0; | ||
|
||
-- Step 2: Clean up any existing table before running the test | ||
DROP TABLE IF EXISTS mamba_dim_agegroup; | ||
|
||
-- Step 3: Call the sp_mamba_dim_agegroup_create procedure to create the table | ||
BEGIN | ||
DECLARE EXIT HANDLER FOR SQLEXCEPTION | ||
BEGIN | ||
SET test_failed = 1; | ||
SET failed_message = 'Failed to create mamba_dim_agegroup table via sp_mamba_dim_agegroup_create.'; | ||
END; | ||
|
||
-- Call the stored procedure to create the table | ||
CALL sp_mamba_dim_agegroup_create(); | ||
END; | ||
|
||
-- Step 4: Validate the creation of the table | ||
IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_agegroup') THEN | ||
SET test_failed = 1; | ||
SET failed_message = 'Table mamba_dim_agegroup was not created by sp_mamba_dim_agegroup_create.'; | ||
END IF; | ||
|
||
-- Step 5: Validate the structure of the created table | ||
DECLARE expected_columns VARCHAR(255) DEFAULT 'id, age, datim_agegroup, datim_age_val, normal_agegroup, normal_age_val'; | ||
DECLARE actual_columns VARCHAR(255); | ||
|
||
SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns | ||
FROM information_schema.columns | ||
WHERE table_name = 'mamba_dim_agegroup'; | ||
|
||
-- Check if the actual columns match the expected columns | ||
IF actual_columns != expected_columns THEN | ||
SET test_failed = 1; | ||
SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); | ||
END IF; | ||
|
||
-- Step 6: Return result | ||
IF test_failed = 1 THEN | ||
SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; | ||
ELSE | ||
SELECT 'Unit Test Passed: mamba_dim_agegroup table created successfully via sp_mamba_dim_agegroup_create with the correct structure.' AS result; | ||
END IF; | ||
END // | ||
|
||
DELIMITER ; | ||
|
||
-- Run the unit test | ||
CALL test_sp_mamba_dim_agegroup_create(); | ||
|
||
-- Clean up after the test | ||
DROP PROCEDURE IF EXISTS test_sp_mamba_dim_agegroup_create; | ||
|
||
|
||
-- $END |
72 changes: 72 additions & 0 deletions
72
...s/_core/database/mysql/dimensions/dim_agegroup/test/sp_mamba_dim_agegroup_test_insert.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
-- $BEGIN | ||
-- ------------------------------------------------------------------------------------- | ||
-- Unit Test for sp_mamba_dim_agegroup_insert procedure | ||
-- ------------------------------------------------------------------------------------- | ||
|
||
DROP PROCEDURE IF EXISTS test_sp_mamba_dim_agegroup_insert; | ||
|
||
DELIMITER // | ||
|
||
CREATE PROCEDURE test_sp_mamba_dim_agegroup_insert() | ||
BEGIN | ||
-- Step 1: Variables for test results | ||
DECLARE test_failed INT DEFAULT 0; | ||
DECLARE failed_message VARCHAR(255) DEFAULT ''; | ||
|
||
-- Step 2: Clean up existing data in the table before running the test | ||
DELETE FROM mamba_dim_agegroup; | ||
|
||
-- Step 3: Insert test data into the source table (if necessary) | ||
-- Assuming the source table has already existing data and no new data is inserted here | ||
-- (If source data needs setup, do it here by inserting test data) | ||
|
||
-- Step 4: Call the sp_mamba_dim_agegroup_insert procedure to insert the data | ||
BEGIN | ||
DECLARE EXIT HANDLER FOR SQLEXCEPTION | ||
BEGIN | ||
SET test_failed = 1; | ||
SET failed_message = 'Failed to insert data into mamba_dim_agegroup via sp_mamba_dim_agegroup_insert.'; | ||
END; | ||
|
||
-- Call the stored procedure to insert data | ||
CALL sp_mamba_dim_agegroup_insert(); | ||
END; | ||
|
||
-- Step 5: Validate that data has been inserted into the mamba_dim_agegroup table | ||
DECLARE row_count INT; | ||
|
||
SELECT COUNT(*) INTO row_count FROM mamba_dim_agegroup; | ||
|
||
-- Check if data has been inserted | ||
IF row_count = 0 THEN | ||
SET test_failed = 1; | ||
SET failed_message = 'No data was inserted into the mamba_dim_agegroup table.'; | ||
END IF; | ||
|
||
-- Step 6: Optionally, validate some specific values in the inserted rows (e.g., check a specific age group) | ||
DECLARE test_agegroup VARCHAR(50); | ||
SELECT datim_agegroup INTO test_agegroup FROM mamba_dim_agegroup LIMIT 1; | ||
|
||
IF test_agegroup IS NULL THEN | ||
SET test_failed = 1; | ||
SET failed_message = 'Data in mamba_dim_agegroup is not as expected.'; | ||
END IF; | ||
|
||
-- Step 7: Return result | ||
IF test_failed = 1 THEN | ||
SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; | ||
ELSE | ||
SELECT 'Unit Test Passed: Data successfully inserted into mamba_dim_agegroup via sp_mamba_dim_agegroup_insert.' AS result; | ||
END IF; | ||
END // | ||
|
||
DELIMITER ; | ||
|
||
-- Run the unit test | ||
CALL test_sp_mamba_dim_agegroup_insert(); | ||
|
||
-- Clean up after the test | ||
DROP PROCEDURE IF EXISTS test_sp_mamba_dim_agegroup_insert; | ||
|
||
|
||
-- $END |
5 changes: 5 additions & 0 deletions
5
.../resources/_core/database/mysql/dimensions/dim_concept/test/sp_mamba_dim_concept_test.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- $BEGIN | ||
CALL sp_mamba_dim_concept_test_create; | ||
CALL sp_mamba_dim_concept_test_insert(); | ||
|
||
-- $END |
64 changes: 64 additions & 0 deletions
64
...ces/_core/database/mysql/dimensions/dim_concept/test/sp_mamba_dim_concept_test_create.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
-- ------------------------------------------------------------------------------------- | ||
-- Unit Test for sp_mamba_dim_concept_create | ||
-- ------------------------------------------------------------------------------------- | ||
|
||
DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_create; | ||
|
||
DELIMITER // | ||
|
||
CREATE PROCEDURE test_sp_mamba_dim_concept_create() | ||
BEGIN | ||
-- Step 1: Variables for test results | ||
DECLARE failed_message VARCHAR(255) DEFAULT ''; | ||
DECLARE test_failed INT DEFAULT 0; | ||
|
||
-- Step 2: Clean up any existing table before running the test | ||
DROP TABLE IF EXISTS mamba_dim_concept; | ||
|
||
-- Step 3: Execute the procedure to be tested | ||
BEGIN | ||
DECLARE EXIT HANDLER FOR SQLEXCEPTION | ||
BEGIN | ||
SET test_failed = 1; | ||
SET failed_message = 'Procedure sp_mamba_dim_concept_create failed to execute.'; | ||
END; | ||
|
||
-- Call the procedure to create the table | ||
CALL sp_mamba_dim_concept_create(); | ||
END; | ||
|
||
-- Step 4: Validate the creation of the table | ||
IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_concept') THEN | ||
SET test_failed = 1; | ||
SET failed_message = 'Table mamba_dim_concept was not created.'; | ||
END IF; | ||
|
||
-- Step 5: Validate the structure of the created table | ||
DECLARE expected_columns VARCHAR(255) DEFAULT 'concept_id, name, description, date_created, date_retired, retired, retire_reason, retired_by, incremental_record'; | ||
DECLARE actual_columns VARCHAR(255); | ||
|
||
SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns | ||
FROM information_schema.columns | ||
WHERE table_name = 'mamba_dim_concept'; | ||
|
||
-- Check if the actual columns match expected columns | ||
IF actual_columns != expected_columns THEN | ||
SET test_failed = 1; | ||
SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); | ||
END IF; | ||
|
||
-- Step 6: Return result | ||
IF test_failed = 1 THEN | ||
SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; | ||
ELSE | ||
SELECT 'Unit Test Passed: sp_mamba_dim_concept_create executed successfully and table created.' AS result; | ||
END IF; | ||
END // | ||
|
||
DELIMITER ; | ||
|
||
-- Run the unit test | ||
CALL test_sp_mamba_dim_concept_create(); | ||
|
||
-- Clean up after the test | ||
DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_create; |
62 changes: 62 additions & 0 deletions
62
...ces/_core/database/mysql/dimensions/dim_concept/test/sp_mamba_dim_concept_test_insert.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
-- ------------------------------------------------------------------------------------- | ||
-- Unit Test for sp_mamba_dim_concept_insert | ||
-- ------------------------------------------------------------------------------------- | ||
|
||
DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_insert; | ||
|
||
DELIMITER // | ||
|
||
CREATE PROCEDURE test_sp_mamba_dim_concept_insert() | ||
BEGIN | ||
-- Step 1: Variables for test results | ||
DECLARE failed_message VARCHAR(255) DEFAULT ''; | ||
DECLARE test_failed INT DEFAULT 0; | ||
|
||
-- Step 2: Clear relevant test data in the target table for isolation | ||
TRUNCATE TABLE mamba_dim_concept; | ||
|
||
-- Step 3: Ensure the ETL settings table (_mamba_etl_user_settings) has relevant locales | ||
DELETE FROM _mamba_etl_user_settings WHERE concepts_locale IN ('en', 'fr'); | ||
INSERT INTO _mamba_etl_user_settings (concepts_locale) VALUES ('en'), ('fr'); | ||
|
||
-- Step 4: Execute the procedure to be tested | ||
BEGIN | ||
DECLARE EXIT HANDLER FOR SQLEXCEPTION | ||
BEGIN | ||
SET test_failed = 1; | ||
SET failed_message = 'Procedure sp_mamba_dim_concept_insert failed.'; | ||
END; | ||
|
||
-- Call the procedure to insert data | ||
CALL sp_mamba_dim_concept_insert(); | ||
END; | ||
|
||
-- Step 5: Validate the data inserted into `mamba_dim_concept` | ||
-- Assuming existing source data matches the criteria for insert | ||
IF NOT EXISTS (SELECT * FROM mamba_dim_concept WHERE concept_id IN (SELECT concept_id FROM openmrs.concept WHERE voided = 0) LIMIT 1) THEN | ||
SET test_failed = 1; | ||
SET failed_message = 'No expected rows found in mamba_dim_concept after insert.'; | ||
END IF; | ||
|
||
-- Check if there are duplicate entries for existing concepts | ||
IF (SELECT COUNT(*) FROM mamba_dim_concept WHERE concept_id IN (SELECT concept_id FROM openmrs.concept WHERE voided = 0)) > | ||
(SELECT COUNT(*) FROM openmrs.concept WHERE voided = 0) THEN | ||
SET test_failed = 1; | ||
SET failed_message = 'Unexpected duplicate entries found in mamba_dim_concept.'; | ||
END IF; | ||
|
||
-- Step 6: Return result | ||
IF test_failed = 1 THEN | ||
SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; | ||
ELSE | ||
SELECT 'Unit Test Passed: sp_mamba_dim_concept_insert executed successfully.' AS result; | ||
END IF; | ||
END // | ||
|
||
DELIMITER ; | ||
|
||
-- Run the unit test | ||
CALL test_sp_mamba_dim_concept_insert(); | ||
|
||
-- Clean up after the test | ||
DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_insert; |
5 changes: 5 additions & 0 deletions
5
...re/database/mysql/dimensions/dim_concept_answer/test/sp_mamba_dim_concept_answer_test.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- $BEGIN | ||
CALL sp_mamba_dim_concept_answer_test_create(); | ||
CALL sp_mamba_dim_concept_answer_test_insert(); | ||
|
||
-- $END |
68 changes: 68 additions & 0 deletions
68
...base/mysql/dimensions/dim_concept_answer/test/sp_mamba_dim_concept_answer_test_create.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
-- $BEGIN | ||
-- ------------------------------------------------------------------------------------- | ||
-- Unit Test for sp_mamba_dim_concept_answer_create procedure | ||
-- ------------------------------------------------------------------------------------- | ||
|
||
DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_answer_create; | ||
|
||
DELIMITER // | ||
|
||
CREATE PROCEDURE test_sp_mamba_dim_concept_answer_create() | ||
BEGIN | ||
-- Step 1: Variables for test results | ||
DECLARE failed_message VARCHAR(255) DEFAULT ''; | ||
DECLARE test_failed INT DEFAULT 0; | ||
|
||
-- Step 2: Clean up any existing table before running the test | ||
DROP TABLE IF EXISTS mamba_dim_concept_answer; | ||
|
||
-- Step 3: Call the sp_mamba_dim_concept_answer_create procedure to create the table | ||
BEGIN | ||
DECLARE EXIT HANDLER FOR SQLEXCEPTION | ||
BEGIN | ||
SET test_failed = 1; | ||
SET failed_message = 'Failed to create mamba_dim_concept_answer table via sp_mamba_dim_concept_answer_create.'; | ||
END; | ||
|
||
-- Call the stored procedure to create the table | ||
CALL sp_mamba_dim_concept_answer_create(); | ||
END; | ||
|
||
-- Step 4: Validate the creation of the table | ||
IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_concept_answer') THEN | ||
SET test_failed = 1; | ||
SET failed_message = 'Table mamba_dim_concept_answer was not created by sp_mamba_dim_concept_answer_create.'; | ||
END IF; | ||
|
||
-- Step 5: Validate the structure of the created table | ||
DECLARE expected_columns VARCHAR(255) DEFAULT 'concept_answer_id, concept_id, answer_concept, answer_drug, incremental_record'; | ||
DECLARE actual_columns VARCHAR(255); | ||
|
||
SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns | ||
FROM information_schema.columns | ||
WHERE table_name = 'mamba_dim_concept_answer'; | ||
|
||
-- Check if the actual columns match the expected columns | ||
IF actual_columns != expected_columns THEN | ||
SET test_failed = 1; | ||
SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); | ||
END IF; | ||
|
||
-- Step 6: Return result | ||
IF test_failed = 1 THEN | ||
SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; | ||
ELSE | ||
SELECT 'Unit Test Passed: mamba_dim_concept_answer table created successfully via sp_mamba_dim_concept_answer_create with the correct structure.' AS result; | ||
END IF; | ||
END // | ||
|
||
DELIMITER ; | ||
|
||
-- Run the unit test | ||
CALL test_sp_mamba_dim_concept_answer_create(); | ||
|
||
-- Clean up after the test | ||
DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_answer_create; | ||
|
||
|
||
-- $END |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GOmare can we please run through this together