From c19b8eab53ebf1316cfad49d98b1ac4701a1fc9c Mon Sep 17 00:00:00 2001 From: mbayopanda Date: Fri, 30 Apr 2021 15:47:22 +0100 Subject: [PATCH 1/2] Fix the period for the test --- test/end-to-end/stock/stock.aggregate_consumption.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/end-to-end/stock/stock.aggregate_consumption.js b/test/end-to-end/stock/stock.aggregate_consumption.js index 2496b8e864..b2eb3191d4 100644 --- a/test/end-to-end/stock/stock.aggregate_consumption.js +++ b/test/end-to-end/stock/stock.aggregate_consumption.js @@ -293,7 +293,7 @@ function StockAggregateConsumptionTests() { it(`Prevent negative stock quantities when Aggregate Consumption greater than the quantity available on current depot ${DEPOT_TERTIAIRE}`, async () => { - const getMovementDate = moment(new Date(), 'YYYY-MM-DD').subtract(90, 'days'); + const getMovementDate = moment(new Date(), 'YYYY-MM-DD').subtract(80, 'days'); const getMovementMonth = moment(getMovementDate).month(); const getMovementYear = moment(getMovementDate).year(); From 27a7d473bde069c7dcaf51d641ac27f898e2a0c5 Mon Sep 17 00:00:00 2001 From: mbayopanda Date: Wed, 5 May 2021 07:26:07 +0100 Subject: [PATCH 2/2] fix integration tests for stock --- sh/build-stock-database.sh | 41 ++++++++++++++++--------------- test/data/service-stock.sql | 42 +++++++++++++++++++++----------- test/integration-stock/depots.js | 28 ++++++++++----------- 3 files changed, 64 insertions(+), 47 deletions(-) diff --git a/sh/build-stock-database.sh b/sh/build-stock-database.sh index a793a7ed40..173c724d13 100755 --- a/sh/build-stock-database.sh +++ b/sh/build-stock-database.sh @@ -21,45 +21,48 @@ if [ "$1" == "debug" ]; then fout=/dev/tty fi -echo "Building database: $DB_USER,$DB_PASS,$DB_HOST,$DB_NAME'" +# default database port +DB_PORT=${DB_PORT:-3306} + +echo "Building database: $DB_USER,$DB_PASS,$DB_HOST,$DB_PORT,$DB_NAME'" # build the test database -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST -e "DROP DATABASE IF EXISTS $DB_NAME ;" || { echo 'failed to drop DB' ; exit 1; } -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST -e "CREATE DATABASE $DB_NAME CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" || { echo 'failed to create DB' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" -e "DROP DATABASE IF EXISTS $DB_NAME ;" || { echo 'failed to drop DB' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" -e "CREATE DATABASE $DB_NAME CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" || { echo 'failed to create DB' ; exit 1; } echo "[build] database schema" -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME < server/models/schema.sql || { echo 'failed to build DB schema' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" < server/models/schema.sql || { echo 'failed to build DB schema' ; exit 1; } echo "[build] functions" -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME < server/models/functions.sql || { echo 'failed to import functions into DB' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" < server/models/functions.sql || { echo 'failed to import functions into DB' ; exit 1; } echo "[build] procedures" -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME < server/models/procedures.sql || { echo 'failed to import procedures into DB 1/2' ; exit 1; } -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME < server/models/admin.sql || { echo 'failed to import procedures into DB 2/2' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" < server/models/procedures.sql || { echo 'failed to import procedures into DB 1/2' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" < server/models/admin.sql || { echo 'failed to import procedures into DB 2/2' ; exit 1; } echo "[build] triggers" -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME < server/models/triggers.sql || { echo 'failed to import triggers into DB' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" < server/models/triggers.sql || { echo 'failed to import triggers into DB' ; exit 1; } echo "[build] default data" -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME < server/models/icd10.sql || { echo 'failed to import default data into DB 1/2' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" < server/models/icd10.sql || { echo 'failed to import default data into DB 1/2' ; exit 1; } -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME < server/models/bhima.sql || { echo 'failed to import default data into DB 2/2' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" < server/models/bhima.sql || { echo 'failed to import default data into DB 2/2' ; exit 1; } echo "[build] stock test data" -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME < test/data/enterprise.sql || { echo 'failed to import test data into DB 1/5' ; exit 1; } -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME < test/data/accounts.sql || { echo 'failed to import test data into DB 2/5' ; exit 1; } -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME < test/data/inventories.sql || { echo 'failed to import test data into DB 3/5' ; exit 1; } -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME < test/data/core.sql || { echo 'failed to import test data into DB 4/5' ; exit 1; } -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME < test/data/service-stock.sql || { echo 'failed to import test data into DB 5/5' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" < test/data/enterprise.sql || { echo 'failed to import test data into DB 1/5' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" < test/data/accounts.sql || { echo 'failed to import test data into DB 2/5' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" < test/data/inventories.sql || { echo 'failed to import test data into DB 3/5' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" < test/data/core.sql || { echo 'failed to import test data into DB 4/5' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" < test/data/service-stock.sql || { echo 'failed to import test data into DB 5/5' ; exit 1; } echo "[build] recomputing mappings" -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME -e "Call zRecomputeEntityMap();" || { echo 'failed to recompute mappings 1/2' ; exit 1; } -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME -e "Call zRecomputeDocumentMap();" || { echo 'failed to recompute mappings 2/2' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" -e "Call zRecomputeEntityMap();" || { echo 'failed to recompute mappings 1/2' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" -e "Call zRecomputeDocumentMap();" || { echo 'failed to recompute mappings 2/2' ; exit 1; } echo "[build] recalculating period totals" -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME -e "Call zRecalculatePeriodTotals();" || { echo 'failed to recalculate period totals' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" -e "Call zRecalculatePeriodTotals();" || { echo 'failed to recalculate period totals' ; exit 1; } echo "[build] recalulcating stock_movement_status" -mysql -u $DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME -e "CALL zRecomputeStockMovementStatus();" || { echo 'failed to recalculate stock movement status' ; exit 1; } +mysql -u "$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -P"$DB_PORT" "$DB_NAME" -e "CALL zRecomputeStockMovementStatus();" || { echo 'failed to recalculate stock movement status' ; exit 1; } echo "[/build]" diff --git a/test/data/service-stock.sql b/test/data/service-stock.sql index 9c386d6fde..09ed71f7c4 100644 --- a/test/data/service-stock.sql +++ b/test/data/service-stock.sql @@ -41,21 +41,35 @@ INSERT INTO depot_permission (user_id, depot_uuid) VALUES -- just after one year ago -SET @one_year_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 12 MONTH), INTERVAL (3000*RAND()) SECOND); -SET @eleven_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 11 MONTH), INTERVAL (3000*RAND()) SECOND); -SET @ten_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 10 MONTH), INTERVAL (3000*RAND()) SECOND); -SET @nine_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 9 MONTH), INTERVAL (3000*RAND()) SECOND); -SET @eight_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 8 MONTH), INTERVAL (3000*RAND()) SECOND); -SET @seven_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 7 MONTH), INTERVAL (3000*RAND()) SECOND); -SET @six_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 6 MONTH), INTERVAL (3000*RAND()) SECOND); -SET @five_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 5 MONTH), INTERVAL (3000*RAND()) SECOND); -SET @four_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 4 MONTH), INTERVAL (3000*RAND()) SECOND); -SET @three_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 3 MONTH), INTERVAL (3000*RAND()) SECOND); -SET @two_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 2 MONTH), INTERVAL (3000*RAND()) SECOND); -SET @one_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 1 MONTH), INTERVAL (3000*RAND()) SECOND); +-- SET @one_year_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 12 MONTH), INTERVAL (3000*RAND()) SECOND); +-- SET @eleven_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 11 MONTH), INTERVAL (3000*RAND()) SECOND); +-- SET @ten_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 10 MONTH), INTERVAL (3000*RAND()) SECOND); +-- SET @nine_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 9 MONTH), INTERVAL (3000*RAND()) SECOND); +-- SET @eight_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 8 MONTH), INTERVAL (3000*RAND()) SECOND); +-- SET @seven_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 7 MONTH), INTERVAL (3000*RAND()) SECOND); +-- SET @six_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 6 MONTH), INTERVAL (3000*RAND()) SECOND); +-- SET @five_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 5 MONTH), INTERVAL (3000*RAND()) SECOND); +-- SET @four_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 4 MONTH), INTERVAL (3000*RAND()) SECOND); +-- SET @three_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 3 MONTH), INTERVAL (3000*RAND()) SECOND); +-- SET @two_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 2 MONTH), INTERVAL (3000*RAND()) SECOND); +-- SET @one_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 1 MONTH), INTERVAL (3000*RAND()) SECOND); + +-- Compute all these times based on 30.5 days per month (rounding up) +SET @one_year_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 366 DAY), INTERVAL (3000*RAND()) SECOND); +SET @eleven_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 336 DAY), INTERVAL (3000*RAND()) SECOND); +SET @ten_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 305 DAY), INTERVAL (3000*RAND()) SECOND); +SET @nine_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 275 DAY), INTERVAL (3000*RAND()) SECOND); +SET @eight_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 244 DAY), INTERVAL (3000*RAND()) SECOND); +SET @seven_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 214 DAY), INTERVAL (3000*RAND()) SECOND); +SET @six_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 183 DAY), INTERVAL (3000*RAND()) SECOND); +SET @five_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 153 DAY), INTERVAL (3000*RAND()) SECOND); +SET @four_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 122 DAY), INTERVAL (3000*RAND()) SECOND); +SET @three_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 92 DAY), INTERVAL (3000*RAND()) SECOND); +SET @two_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 61 DAY), INTERVAL (3000*RAND()) SECOND); +SET @one_months_ago = DATE_ADD(DATE_SUB(NOW(), INTERVAL 31 DAY), INTERVAL (3000*RAND()) SECOND); -- two years and some into the future -SET @expiration_date = DATE_ADD(DATE_ADD(NOW(), INTERVAL 24 MONTH), INTERVAL (100000 *RAND()) SECOND); +SET @expiration_date = DATE_ADD(DATE_ADD(NOW(), INTERVAL 732 DAY), INTERVAL (100000 *RAND()) SECOND); DELIMITER $$ CREATE FUNCTION GetPeriodId(period_date DATETIME) @@ -68,7 +82,7 @@ DELIMITER ; INSERT INTO `lot` (`uuid`, `label`, `quantity`, `unit_cost`, `description`, `expiration_date`, `inventory_uuid`, `is_assigned`) VALUES (0x3CAA76C5748041F5A55600D48B770B9D,'QUININE-C-XXX',100,9.4000,NULL,@expiration_date,0x6D93ED88393211EBA0B954E1AD7439C7,0), - (0x6AA623AAA6EF4ECAB811E398D37C110D,'AMP-C-ZZZ',60,3.1800,NULL,'2021-12-30',0x6D920858393211EBA0B954E1AD7439C7,0), + (0x6AA623AAA6EF4ECAB811E398D37C110D,'AMP-C-ZZZ',60,3.1800,NULL,@expiration_date,0x6D920858393211EBA0B954E1AD7439C7,0), (0x6E8A11992E8641758727F73A3648A1B8,'AMP-A-ZZZ',120,3.1800,NULL,@expiration_date,0x6D920858393211EBA0B954E1AD7439C7,0), (0x8E8D1F39D57348689800EB8EA707E813,'OXY-A-YYYY',10000,7.0600,NULL,@expiration_date,0x6D93A100393211EBA0B954E1AD7439C7,0), (0x971F7AC3FF604A649773CE9539871A07,'QUININE-B-XXX',500,9.4000,NULL,@expiration_date,0x6D93ED88393211EBA0B954E1AD7439C7,0), diff --git a/test/integration-stock/depots.js b/test/integration-stock/depots.js index 20fafd39bf..a8faea5ed2 100644 --- a/test/integration-stock/depots.js +++ b/test/integration-stock/depots.js @@ -57,15 +57,15 @@ describe('(/depots) The depots API ', () => { expect(res).to.be.json; // eslint-disable-line let values = { - algo_def : 53.48, - algo_msh : 53.33, + algo_def : 48.47, + algo_msh : 48.33, sum_days : 365, sum_stock_day : 365, sum_consumption_day : 9, - sum_consumed_quantity : 640, + sum_consumed_quantity : 580, number_of_month : 12, sum_stock_out_days : 0, - head_days : 0, + head_days : 29, }; expect(res.body.algo_def, 'quinine CMM algorithm 1 is not calculated correctly').to.equal(values.algo_def); @@ -75,15 +75,15 @@ describe('(/depots) The depots API ', () => { res = await agent.get(`/depots/${principal}/inventories/${oxytocine}/cmm`); values = { - algo_def : 74.37, - algo_msh : 74.17, + algo_def : 72.28, + algo_msh : 72.08, sum_days : 365, sum_stock_day : 365, sum_consumption_day : 8, - sum_consumed_quantity : 890, + sum_consumed_quantity : 865, number_of_month : 12, sum_stock_out_days : 0, - head_days : 0, + head_days : 60, }; expect(res.body.algo_def, 'oxytocine CMM algorithm 1 is not calculated correctly').to.equal(values.algo_def); @@ -92,15 +92,15 @@ describe('(/depots) The depots API ', () => { res = await agent.get(`/depots/${principal}/inventories/${ampicilline}/cmm`); values = { - algo_def : 33.27, - algo_msh : 33.15, + algo_def : 30.16, + algo_msh : 30.05, sum_days : 365, - sum_stock_day : 275, + sum_stock_day : 273, sum_consumption_day : 8, - sum_consumed_quantity : 300, + sum_consumed_quantity : 270, number_of_month : 12, - sum_stock_out_days : 90, - head_days : 0, + sum_stock_out_days : 92, + head_days : 29, }; expect(res.body.algo_def, 'ampicilline CMM algorithm 1 is not calculated correctly').to.equal(values.algo_def);