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

feat: unit test and integration test for stock supply activities #68

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion src/features/stock-discrepancy.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,5 +478,9 @@ async function updateStockDiscrepancy(configs) {
}

module.exports = {
updateStockDiscrepancy
updateStockDiscrepancy,
getSummaries,
getItemRows,
getExportCalculations,
getAdditionalDoc
};
4 changes: 4 additions & 0 deletions src/features/stock-received.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,8 @@ async function updateStockConfirmation(configs, messages) {

module.exports = {
updateStockConfirmation,
getItemRows,
addStockConfirmCalculation,
addStockConfirmSummaries,
getLabelColumns
};
125 changes: 120 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 All @@ -504,4 +615,8 @@ async function getStockSupplyConfigs({
module.exports = {
updateStockSupply,
getStockSupplyConfigs,
addStockSupplyCalculation,
getItemRows,
getAdditionalDoc,
addStockSupplySummaries
};
125 changes: 102 additions & 23 deletions test/mocks/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
},
},
},
stockOutMockConfigs: {
stockMonitoringConfigs: {
features: {
stock_out: {
form_name: 'stock_out',
Expand All @@ -16,6 +16,63 @@ module.exports = {
fr: 'Titre du Stock'
},
},
stock_return: {
form_name: 'stock_return',
title: {
en: 'Stock Return',
fr: 'Retour de Stock'
},
confirmation: {
form_name: 'stock_returned',
title: {
en: 'Stock Returned',
fr: 'Stock Retourné'
},
}
},
stock_order: {
actors: [
{
contact_type: 'c62_chw',
role: 'chw',
place_type: 'c60_chw_site'
}
],
form_name: 'stock_order',
title: {
en: 'Stock Order',
fr: 'Commande de Stock'
},
stock_supply: {
form_name: 'stock_order_supply',
title: {
en: 'Stock Order Supply',
fr: 'Livraison de Commande de Stock'
}
}
},
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: {
Expand Down Expand Up @@ -71,8 +128,7 @@ module.exports = {
useItemCategory: true,
defaultLanguage: 'fr',
},

stockOutScenario: {
stockMonitoringScenario: {
initScenario: [
'init',
'2_levels',
Expand Down Expand Up @@ -104,15 +160,6 @@ module.exports = {
'by_user',
0,
],
addStockOutFeatureScenario: [
'add', 'feature', 'stock_out', 'stock_out', 'item_danger_qty', ['Stock Out', 'Stock Out']
],
productsScenario: [
'paracetamol_at_hand___set',
'paracetamol_at_hand___unit',
'paracetamol_required___set',
'paracetamol_required___unit'
],
invalidCommandInitScenario: [
'test',
'2_levels',
Expand Down Expand Up @@ -144,15 +191,46 @@ module.exports = {
'by_user',
0,
],
invalidAddStockOutFeatureScenario: [
invalidFeatureCommandScenario: [
'minus', 'data', 'stock_out', 'stock_out', 'item_danger_qty', ['Stock Out', 'Stock Out']
],
},

stockSupplyScenario: {
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',
stockOutScenario: {
addStockOutFeatureScenario: [
'add', 'feature', 'stock_out', 'stock_out', 'item_danger_qty', ['Stock Out', 'Stock Out']
],
productsScenario: [
'paracetamol_at_hand___set',
'paracetamol_at_hand___unit',
'paracetamol_required___set',
'paracetamol_required___unit'
],
invalidCommandInitScenario: [
'test',
'2_levels',
'c62_chw',
'chw',
Expand Down Expand Up @@ -180,8 +258,15 @@ module.exports = {
15,
15,
'by_user',
0
0,
],
invalidAddStockOutFeatureScenario: [
'minus', 'data', 'stock_out', 'stock_out', 'item_danger_qty', ['Stock Out', 'Stock Out']
],

},

stockCountScenario: {
productCategoryScenario: [
'malaria'
],
Expand All @@ -194,9 +279,3 @@ module.exports = {

}
};






6 changes: 3 additions & 3 deletions test/stock-count.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { spawnSync } = require('child_process');
const path = require('path');
const fs = require('fs-extra');

const { stockCountScenario, stockOutScenario } = require('./mocks/mocks');
const { stockMonitoringScenario, stockCountScenario, stockOutScenario } = require('./mocks/mocks');
const {
setDirToprojectConfig,
revertBackToProjectHome,
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('Create and update stock_count.xlsx and properties files', () => {

afterEach(async() => {
await resetTranslationMessages(process.cwd());
cleanUp(workingDir, createdAppFormFiles);
await cleanUp(workingDir, createdAppFormFiles);
revertBackToProjectHome(workingDir);
});

Expand Down Expand Up @@ -85,7 +85,7 @@ describe('Create and update stock_count.xlsx and properties files', () => {
expect(fs.existsSync(path.join(processDir, 'forms', 'app', createdAppFormFile))).toBe(false);
}

const childProcess = spawnSync('../../main.js', stockCountScenario.initScenario);
const childProcess = spawnSync('../../main.js', stockMonitoringScenario.initScenario);

if (childProcess.error) {
throw childProcess.error;
Expand Down
Loading