Skip to content
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

add unit and integration test for stock order #66

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
"semantic-release": "semantic-release",
"prepare": "husky"
},
Expand Down
12 changes: 11 additions & 1 deletion src/add-feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,17 @@ 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
69 changes: 69 additions & 0 deletions src/features/stock-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,16 @@ const getStockOrderConfigs = async ({
value: actor,
};
}),
when: function(answers){
const argv = process.argv;
if (!argv[5]){
return true;
}

answers.actors = eval(argv[5]);

return false;
}
},
{
type: 'input',
Expand All @@ -406,6 +416,16 @@ const getStockOrderConfigs = async ({
return 'Please enter a valid form ID';
}
return true;
},
when: function(answers){
const argv = process.argv;
if (!argv[6]){
return true;
}

answers.form_name = argv[6];

return false;
}
},
...languages.map((language) => ({
Expand All @@ -418,6 +438,22 @@ const getStockOrderConfigs = async ({
return `Please enter a valid form title in ${language}`;
}
return true;
},
when: function(answers){
const argv = process.argv;
if (!argv[7]){
return true;
}

const answer = {
title:{
'en': argv[7].split(',')[0],
'fr': argv[7].split(',')[1]
}
};

Object.assign(answers, answer);
return false;
}
})),
{
Expand All @@ -430,6 +466,21 @@ const getStockOrderConfigs = async ({
return 'Please enter a valid form ID';
}
return true;
},
when: function(answers){
const argv = process.argv;
if (!argv[10]){
return true;
}

const answer = {
stock_supply:{
form_name: argv[10]
}
};

Object.assign(answers, answer);
return false;
}
},
...languages.map((language) => ({
Expand All @@ -442,6 +493,24 @@ const getStockOrderConfigs = async ({
return `Please enter a valid form title in ${language}`;
}
return true;
},
when: function(answers){
const argv = process.argv;
if (!argv[9]){
return true;
}

const answer = {
stock_supply:{
title: {
'en': argv[9].split(',')[0],
'fr': argv[9].split(',')[1]
}
}
};

Object.assign(answers, answer);
return false;
}
}))
]);
Expand Down
116 changes: 111 additions & 5 deletions src/features/stock-supply.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,19 +448,59 @@ 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[11]){
return true;
}

answers.form_name = argv[11];
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[12]){
return true;
}

const answer = {
title: {
'en': argv[12].split(',')[0],
'fr': argv[12].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[13]){
return true;
}

const answer = {
confirm_supply:{
active: argv[13]
}
};

Object.assign(answers, answer);
return false;
}
}
]);

Expand All @@ -470,25 +510,91 @@ 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[14]){
return true;
}

const answer = {
confirm_supply:{
form_name: argv[14]
}
};

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[15]){
return true;
}

const answer = {
confirm_supply:{
title: {
'en': argv[15].split(',')[0],
'fr': argv[15].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[16]){
return true;
}

const answer = {
discrepancy:{
form_name: argv[16]
}
};

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[17]){
return true;
}

const answer = {
discrepancy: {
title: {
'en': argv[17].split(',')[0],
'fr': argv[17].split(',')[1]
}
}
};

Object.assign(answers, answer);
return false;
}
}))
]);
confirmationConfigs['confirm_supply'].active = true;
Expand Down
90 changes: 89 additions & 1 deletion test/mocks/mocks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {

stockCountScenario: {
initScenario: [
'init',
Expand Down Expand Up @@ -41,7 +42,94 @@ module.exports = {
'paracetamol___count'
]

}
},

stockOrderScenario: {
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
],
addStockOrderFeatureScenario: [
'add',
'feature',
'stock_order',
'[{contact_type: \'c62_chw\', role: \'chw\', place_type: \'c60_chw_site\' },{contact_type: \'c52_supervisor\',role: \'supervisor\',place_type: \'c50_supervision_area\'}]',
'stock_order',
'Stock Order',
['Stock Order', 'Stock Order'],
['Stock Order Supply', 'Stock Order Supply'],
'stock_order_supply',
'stock_supply',
['Stock Supply', 'Stock Supply'],
true,
'stock_received',
['Stock Received', 'Stock Received'],
'stock_discrepancy_resolution',
['Stock Discrepancy Resolution', 'Stock Discrepancy Resolution']
],
productCategoryScenario: [
'malaria'
],

productsScenario: [
'paracetamol___set',
'paracetamol___unit',
'paracetamol',
'paracetamol___count'
],

stockOrderScenario: [
'___paracetamol',
'paracetamol_before',
'paracetamol___current___set',
'paracetamol___current___unit',
'paracetamol___set',
'paracetamol___unit',
'paracetamol_order_qty',
'paracetamol___after___set',
'paracetamol___after___unit',
'paracetamol_after_note',
'paracetamol___count',
'paracetamol_after'
],
stockSupplyProductsScenario: [
'malaria_items_selected',
'___paracetamol',
'paracetamol___set',
'paracetamol___unit',
'supply_paracetamol',
'paracetamol___count'
]

},

};


Expand Down
Loading
Loading