Skip to content

Commit

Permalink
feat: unit test and integration test for stock supply activities
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestoteo committed Nov 6, 2024
1 parent d956af7 commit edd4443
Show file tree
Hide file tree
Showing 13 changed files with 734 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
"SwitchCase": 1
}
]
},
"globals": {
"jest": true
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"scripts": {
"cz": "cz",
"test": "jest",
"test": "jest --testTimeout=25000 --runInBand",
"semantic-release": "semantic-release",
"prepare": "husky"
},
Expand Down
10 changes: 9 additions & 1 deletion src/add-feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ async function selectFeature(configs) {
choices: remainingFeatures.map((ft) => ({
name: FEATURES[ft],
value: ft,
}))
})),
when: function (answers){
const argv = process.argv;
if (!argv[4]){
return true;
}
answers.name = argv[4];
return false;
}
}
]);

Expand Down
121 changes: 116 additions & 5 deletions src/features/stock-supply.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,19 +448,54 @@ async function getStockSupplyConfigs({
type: 'input',
name: 'form_name',
message: 'Enter stock supply form ID',
default: 'stock_supply'
default: 'stock_supply',
when: function(answers){
const argv = process.argv;
if (!argv[4]){
return true;
}
answers.form_name = argv[4];
return false;
}
},
...languages.map((language) => ({
type: 'input',
name: `title.${language}`,
message: `Enter stock supply form title in ${language}`,
default: 'Stock Supply'
default: 'Stock Supply',
when: function(answers){
const argv = process.argv;
if (!argv[5]){
return true;
}
const answer = {
title: {
'en':argv[5].split(',')[0],
'fr':argv[5].split(',')[1],
}
};
Object.assign(answers, answer);
return false;
}
})),
{
type: 'confirm',
name: 'confirm_supply.active',
message: 'Activate supply confirmation',
default: false,
when: function(answers){
const argv = process.argv;
if (!argv[6]){
return true;
}
const answer = {
confirm_supply: {
active: argv[6]
}
};
Object.assign(answers, answer);
return false;
}
}
]);

Expand All @@ -470,25 +505,101 @@ async function getStockSupplyConfigs({
type: 'input',
name: 'confirm_supply.form_name',
message: 'Enter supply confirmation ID',
default: 'stock_received'
default: 'stock_received',
when: function(answers){
const argv = process.argv;
if (!argv[7]){
return true;
}
const answer = {
confirm_supply: {
form_name: argv[7]
}
};

Object.assign(answers, answer);
return false;
}
},
...languages.map((language) => ({
type: 'input',
name: `confirm_supply.title.${language}`,
message: `Enter supply confirmation form title in ${language}`,
default: 'Stock Received'
default: 'Stock Received',
when: function(answers){
const argv = process.argv;
if (!argv[8]){
return true;
}
const answer = {
confirm_supply: {
title: {
'en':argv[8].split(',')[0],
'fr':argv[8].split(',')[1],
}
}
};

Object.assign(answers, answer);
return false;
}
})),
{
type: 'input',
name: 'discrepancy.form_name',
message: 'Enter discrepancy resolution form ID',
default: 'stock_discrepancy_resolution',
when: function(answers){
const argv = process.argv;
if (!argv[9]){
return true;
}
const answer = {
discrepancy: {
form_name: argv[9]
}
};

Object.assign(answers, answer);
return false;
}
},
...languages.map((language) => ({
type: 'input',
name: `discrepancy.title.${language}`,
message: `Enter discrepancy resolution form title in ${language}`,
default: 'Stock Discrepancy Resolution'
default: 'Stock Discrepancy Resolution',
when: function(answers){
const argv = process.argv;
if (!argv[10]){
return true;
}

const answer = {
form_name: argv[4],
title: {
'en': argv[5].split(',')[0],
'fr': argv[5].split(',')[1],
},
discrepancy: {
form_name: argv[9],
title: {
'en':argv[10].split(',')[0],
'fr':argv[10].split(',')[1],
},
},
confirm_supply: {
form_name: argv[7],
title: {
'en':argv[8].split(',')[0],
'fr':argv[8].split(',')[1],
},
active: argv[6]
}
};
Object.assign(answers, answer);
return false;
}
}))
]);
confirmationConfigs['confirm_supply'].active = true;
Expand Down
140 changes: 140 additions & 0 deletions test/mocks/mocks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,144 @@
module.exports = {
mockConfigsWithNoFeauture: {
features: {
no_feature: {
form_name: 'no_form'
},
},
},
stockSupplyConfig: {
features: {
stock_supply: {
form_name: 'stock_supply',
title: {
en: 'Stock Supply',
fr: 'Livraison de Stock'
},
confirm_supply: {
form_name: 'stock_received',
title: {
en: 'Stock Received',
fr: 'Réception de Stock'
},
active: true
},
discrepancy: {
form_name: 'stock_discrepancy_resolution',
title: {
en: 'Stock Discrepancy Resolution',
fr: 'Résolution de conflits'
}
}
},
},
levels: {
1: {
contact_type: 'c62_chw',
role: 'chw',
place_type: 'c62_chw_site'
},
2: {
contact_type: 'c52_supervisor',
role: 'supervisor',
place_type: 'c50_supervision_area'
},
},
languages: ['en', 'fr'],
items: {
paracetamol: {
name: 'paracetamol',
label: {
en: 'Paracetamol',
fr: 'Paracetamole'
},
isInSet: true,
set: {
label: {
en: 'Box of 8',
fr: 'Boite de 8'
},
count: 8
},
unit: {
label: {
en: 'Tablet',
fr: 'Comprimes'
}
},
warning_total: '20',
danger_total: '15',
max_total: '50',
category: 'malaria'
}
},
categories: {
malaria: {
name: 'malaria',
label: {
fr: 'Malaria'
},
description: {
fr: 'Malaria'
}
}
},
useItemCategory: true,
defaultLanguage: 'fr',
},
stockSupplyScenario: {
initScenario: [
'init',
'2_levels',
'c62_chw',
'chw',
'c52_supervisor',
'supervisor',
'Y',
'stock_count',
'[{contact_type: \'c62_chw\', role: \'chw\', place_type: \'c60_chw_site\' },{contact_type: \'c52_supervisor\',role: \'supervisor\',place_type: \'c50_supervision_area\'}]',
'action',
'end_of_week',
['Stock count', 'Stock count'],
'patient_assessment_under_5',
'Y',
'now()',
'malaria',
['Category', 'Categorie'],
['Category', 'Categorie'],
'paracetamol',
['Paracetamol', 'Paracetamole'],
'Y',
['Box of 8', 'Boite de 8'],
8,
['Tablet', 'Comprimes'],
20,
15,
15,
'by_user',
0
],
addStockSupplyFeature: [
'add',
'feature',
'stock_supply',
['Stock Supply', 'Livraison de Stock'],
true,
'stock_received',
['Stock Received', 'Réception de Stock'],
'stock_discrepancy_resolution',
['Stock Discrepancy Resolution', 'Résolution de conflits']
],
productCategoryScenario: [
'malaria'
],
productsScenario: [
'paracetamol___set',
'paracetamol___unit',
'paracetamol',
'paracetamol___count'
]

},
stockCountScenario: {
initScenario: [
'init',
Expand Down
18 changes: 18 additions & 0 deletions test/project-config/translations/messages-en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,21 @@ contact.child.mother.indicator.potable.water = Number of households with access
contact.child.mother.indicator.cash.transfert = Number of households that have benefited from cash transfers
contact.child.mother.indicator.sexual.mutilation = Number of children with sexual mutilations
contact.child.mother.indicator.malnutrition = Number of children aged 6-59 months having been screened for malnutrition in a household

cht-stock-monitoring-workflow.stock_supply.discrepancy.summary_header = Results/Summary page
cht-stock-monitoring-workflow.stock_supply.discrepancy.submit_note = <h4 style="text-align:center;">Be sure you Submit to complete this action.</h4>
cht-stock-monitoring-workflow.stock_supply.discrepancy.summary_note = Discrepancy resolution<i class="fa fa-list-ul"></i>
cht-stock-monitoring-workflow.stock_supply.discrepancy.quantity_issued = Quantity issued: {{qty}}
cht-stock-monitoring-workflow.stock_supply.discrepancy.quantity_confirmed = Quantity confirmed: {{qty}}
cht-stock-monitoring-workflow.stock_supply.discrepancy.quantity_final = What is the final quantity ?

cht-stock-monitoring-workflow.stock_supply.page_1.header = Select item to supply
cht-stock-monitoring-workflow.stock_supply.forms.select_category = Select the category of what you want to return
cht-stock-monitoring-workflow.stock_supply.page_1.select_input = Select
cht-stock-monitoring-workflow.stock_supply.page_1.select_input_hint = Select all items to supply
cht-stock-monitoring-workflow.stock_supply.tasks.reception-confirmation = Stock received
cht-stock-monitoring-workflow.stock_supply.confirmation.item_received_confirmation_question = Did you received {{qty_unit}}
cht-stock-monitoring-workflow.stock_supply.confirmation.summary_note = Stock items you received.<i class="fa fa-list-ul"></i>
cht-stock-monitoring-workflow.stock_supply.label.confirm_qty = Confirm quantities
cht-stock-monitoring-workflow.stock_supply.message.set_unit_constraint_message = Should be in the form x/y for x {{set_label}} and y {{unit_label}}
cht-stock-monitoring-workflow.stock_supply.message.unit_quantity_hint = Add the quantity: {{quantity}} {{unit_label}}
19 changes: 19 additions & 0 deletions test/project-config/translations/messages-fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,22 @@ contact.child.mother.indicator.potable.water = Nombre de ménage qui a accès à
contact.child.mother.indicator.cash.transfert = Nombre de ménage qui recoit un cash transfert
contact.child.mother.indicator.sexual.mutilation = Nombre d'enfant fille ayant subi une mutilation sexuelle
contact.child.mother.indicator.malnutrition = Nombre d\'enfant de 6-59 mois ayant ete depiste de la malnutrition dans un menage
cht-stock-monitoring-workflow.stock_supply.item.stock_on_hand = Stock actuel
cht-stock-monitoring-workflow.stock_supply.item.quantity_of = Quantité de
cht-stock-monitoring-workflow.stock_supply.summary_header = Page Résultats
cht-stock-monitoring-workflow.stock_supply.submit_note = <h4 style="text-align:center;">Assurez vous de soumettre pour enregistrer cette action.</h4>
cht-stock-monitoring-workflow.stock_supply.summary_note = Stock livré.<i class="fa fa-list-ul"></i>
cht-stock-monitoring-workflow.stock_supply.confirmation.item_received_question = Avez-vous reçu {{qty}} {{unit}} de {{item}}
cht-stock-monitoring-workflow.stock_supply.choices.yes_no.yes = Oui
cht-stock-monitoring-workflow.stock_supply.choices.yes_no.no = Non
cht-stock-monitoring-workflow.stock_supply.discrepancy.summary_header = Page Résultats
cht-stock-monitoring-workflow.stock_supply.discrepancy.submit_note = <h4 style="text-align:center;">Assurez-vous de soumettre pour compléter cette action.</h4>
cht-stock-monitoring-workflow.stock_supply.discrepancy.summary_note = Résolution de conflits<i class="fa fa-list-ul"></i>
cht-stock-monitoring-workflow.stock_supply.discrepancy.quantity_issued = Quantité envoyée : {{qty}}
cht-stock-monitoring-workflow.stock_supply.discrepancy.quantity_confirmed = Quantité confirmée : {{qty}}
cht-stock-monitoring-workflow.stock_supply.discrepancy.quantity_final = Quelle est la quantité finale ?
cht-stock-monitoring-workflow.stock_supply.message.set_unit_constraint_message = Doit étre sous la forme x/y pour x {{set_label}} et y {{unit_label}}
cht-stock-monitoring-workflow.stock_supply.message.unit_quantity_hint = Ajouter quantité : {{quantity}} {{unit_label}}
cht-stock-monitoring-workflow.stock_supply.confirmation.item_received_confirmation_question = Avez-vous reçu {{qty_unit}}
Loading

0 comments on commit edd4443

Please sign in to comment.