Skip to content

Commit

Permalink
feat: stock out unit test and integration test (#69)
Browse files Browse the repository at this point in the history
* feat: stock out unit test and integration test

* feat: add no feature config available

* fix: feedback from PR review and add new test cases

* fix: review feedback and add input validation
  • Loading branch information
ernestoteo authored Nov 20, 2024
1 parent d956af7 commit bbc2375
Show file tree
Hide file tree
Showing 15 changed files with 717 additions and 945 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
}
}
11 changes: 10 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions 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 Expand Up @@ -44,7 +44,8 @@
"fs-extra": "^11.1.0",
"inquirer": "^8.2.5",
"jest-junit": "^16.0.0",
"luxon": "^3.3.0"
"luxon": "^3.3.0",
"validator": "^13.12.0"
},
"config": {
"commitizen": {
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
87 changes: 32 additions & 55 deletions src/add-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const inquirer = require('inquirer');
const utils = require('./common');
const path = require('path');
const fs = require('fs-extra');
const validator = require('validator');

/**
* Config
Expand Down Expand Up @@ -39,7 +40,7 @@ async function getItemConfig(configs) {
if (!argv[14]){
return true;
}
answers.form = argv[14];
answers.form = validator.escape(argv[14]);
return false;
}
}
Expand All @@ -63,7 +64,7 @@ async function getItemConfig(configs) {
if (!argv[15]){
return true;
}
answers.isAlwaysCurrent = argv[15];
answers.isAlwaysCurrent = validator.escape(argv[15]);
return false;
}
}
Expand All @@ -80,7 +81,7 @@ async function getItemConfig(configs) {
if (!argv[16]){
return true;
}
answers.reportedDate = argv[16];
answers.reportedDate = validator.escape(argv[16]);
return false;
}
}
Expand Down Expand Up @@ -119,7 +120,7 @@ async function getItemConfig(configs) {
if (!argv[17]){
return true;
}
answers.item = argv[17];
answers.item = validator.escape(argv[17]);
return false;
}
}]);
Expand Down Expand Up @@ -165,7 +166,7 @@ async function getItemConfig(configs) {
if (!argv[17]){
return true;
}
answers.name = argv[17];
answers.name = validator.escape(argv[17]);
return false;
}
},
Expand All @@ -178,26 +179,13 @@ async function getItemConfig(configs) {
if (!argv[18]){
return true;
}
let answer = {};
argv[18].split(',').forEach(el => {
switch(language){
case 'en':
answer = {
label: {
'en': el
}
};
break;
case 'fr':
answer = {
label: {
'fr': el
}
};
break;
const answer = {
label: {
'en': validator.escape(argv[18].split(',')[0]),
'fr': validator.escape(argv[18].split(',')[1]),
}
});
};

Object.assign(answers, answer);
return false;
}
Expand All @@ -211,23 +199,12 @@ async function getItemConfig(configs) {
if (!argv[19]){
return true;
}
let answer = {};
switch(language){
case 'en':
answer = {
description: {
'en': argv[19].split(',')[0]
}
};
break;
case 'fr':
answer = {
description: {
'fr': argv[19].split(',')[1]
}
};
break;
}
const answer = {
description: {
'en': validator.escape(argv[19].split(',')[0]),
'fr': validator.escape(argv[19].split(',')[1])
}
};

Object.assign(answers, answer);
return false;
Expand All @@ -246,7 +223,7 @@ async function getItemConfig(configs) {
if (!argv[20]){
return true;
}
answers.name = argv[20];
answers.name = validator.escape(argv[20]);
return false;
}
},
Expand All @@ -261,8 +238,8 @@ async function getItemConfig(configs) {
}
const answer = {
label: {
'en': argv[21].split(',')[0],
'fr': argv[21].split(',')[1]
'en': validator.escape(argv[21].split(',')[0]),
'fr': validator.escape(argv[21].split(',')[1])
}
};
Object.assign(answers, answer);
Expand All @@ -279,7 +256,7 @@ async function getItemConfig(configs) {
if (!argv[22]){
return true;
}
answers.isInSet = argv[22];
answers.isInSet = validator.escape(argv[22]);
return false;
}
},
Expand All @@ -299,8 +276,8 @@ async function getItemConfig(configs) {
const answer = {
set:{
label: {
'en': argv[23].split(',')[0],
'fr': argv[23].split(',')[1]
'en': validator.escape(argv[23].split(',')[0]),
'fr': validator.escape(argv[23].split(',')[1])
}
}
};
Expand All @@ -319,7 +296,7 @@ async function getItemConfig(configs) {
return true;
}

answers.set.count = argv[24];
answers.set.count = validator.escape(argv[24]);
return false;
}
},
Expand All @@ -339,8 +316,8 @@ async function getItemConfig(configs) {
const answer = {
unit:{
label: {
'en': argv[25].split(',')[0],
'fr': argv[25].split(',')[1]
'en': validator.escape(argv[25].split(',')[0]),
'fr': validator.escape(argv[25].split(',')[1])
}
}
};
Expand All @@ -358,7 +335,7 @@ async function getItemConfig(configs) {
if (!argv[26]){
return true;
}
answers.warning_total = argv[26];
answers.warning_total = validator.escape(argv[26]);
return false;
}
},
Expand All @@ -371,7 +348,7 @@ async function getItemConfig(configs) {
if (!argv[27]){
return true;
}
answers.danger_total = argv[27];
answers.danger_total = validator.escape(argv[27]);
return false;
}
},
Expand All @@ -385,7 +362,7 @@ async function getItemConfig(configs) {
if (!argv[28]){
return true;
}
answers.max_total = argv[28];
answers.max_total = validator.escape(argv[28]);
return false;
}
}
Expand Down Expand Up @@ -416,7 +393,7 @@ async function getItemConfig(configs) {
if (!argv[29]){
return true;
}
answers.deduction_type = argv[29];
answers.deduction_type = validator.escape(argv[29]);
return false;
}
}
Expand All @@ -432,7 +409,7 @@ async function getItemConfig(configs) {
if (!argv[30]){
return true;
}
answers.formular = argv[30];
answers.formular = validator.escape(argv[30]);
return false;
}
}
Expand Down
37 changes: 35 additions & 2 deletions src/features/stock-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const path = require('path');
const fs = require('fs-extra');
const ExcelJS = require('exceljs');
const inquirer = require('inquirer');
const validator = require('validator');

const { getNoLabelsColums, getTranslations, getRowWithValueAtPosition, getNumberOfSteps, buildRowValues, getSheetGroupBeginEnd,
getItemCount
} = require('../common');
Expand Down Expand Up @@ -263,7 +265,15 @@ async function getStockOutConfigs({
type: 'input',
name: 'form_name',
message: 'Enter stock out form ID',
default: 'stock_out'
default: 'stock_out',
when: function (answers){
const argv = process.argv;
if (!argv[5]){
return true;
}
answers.form_name = validator.escape(argv[5]);
return false;
}
},
{
type: 'list',
Expand All @@ -279,12 +289,34 @@ async function getStockOutConfigs({
value: 'weekly_qty'
}
],
when: function (answers){
const argv = process.argv;
if (!argv[6]){
return true;
}
answers.formular = validator.escape(argv[6]);
return false;
}
},
...languages.map((language) => ({
type: 'input',
name: `title.${language}`,
message: `Enter stock out form title in ${language}`,
default: 'Stock Out'
default: 'Stock Out',
when: function (answers){
const argv = process.argv;
if (!argv[7]){
return true;
}
const answer = {
title:{
'en': validator.escape(argv[7].split(',')[0]),
'fr': validator.escape(argv[7].split(',')[1])
}
};
Object.assign(answers, answer);
return false;
}
}))
]);
return configs;
Expand All @@ -293,4 +325,5 @@ async function getStockOutConfigs({
module.exports = {
getStockOutConfigs,
updateStockOut,
getItemRows
};
Loading

0 comments on commit bbc2375

Please sign in to comment.