-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: feedback from PR review and add new test cases
- Loading branch information
1 parent
077bd3d
commit 9349743
Showing
8 changed files
with
179 additions
and
831 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,4 +323,5 @@ async function getStockOutConfigs({ | |
module.exports = { | ||
getStockOutConfigs, | ||
updateStockOut, | ||
getItemRows | ||
}; |
340 changes: 0 additions & 340 deletions
340
test/project-config/translations/messages-en.properties
Large diffs are not rendered by default.
Oops, something went wrong.
475 changes: 0 additions & 475 deletions
475
test/project-config/translations/messages-fr.properties
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
const { | ||
stockOutMockConfigs, | ||
mockConfigsWithNoFeauture | ||
} = require('./mocks/mocks'); | ||
|
||
const { | ||
getItemRows, | ||
getStockOutConfigs | ||
} = require('../src/features/stock-out'); | ||
|
||
const { | ||
setDirToprojectConfig, | ||
revertBackToProjectHome, | ||
writeTranslationMessages, | ||
resetTranslationMessages | ||
} = require('./test-utils'); | ||
|
||
const { getTranslations } = require('../src/common'); | ||
|
||
describe('Testing functions in Stock out feature file', () => { | ||
const processInitialArgv = process.argv; // Save the original argv | ||
const workingDir = process.cwd(); | ||
const enMessage = 'cht-stock-monitoring-workflow.stock_out.tasks.stock_out = Stock out\ncht-stock-monitoring-workflow.stock_out.message.stock_at_hand = Stock at hand: {{qty}}\ncht-stock-monitoring-workflow.stock_out.message.stock_required = Stock required: {{qty}}\ncht-stock-monitoring-workflow.stock_out.message.summary_header = Summary\ncht-stock-monitoring-workflow.stock_out.message.submit_note = {{name}} has low stock of the following items\ncht-stock-monitoring-workflow.stock_out.message.summary_note = Stock out\ncht-stock-monitoring-workflow.items.paracetamol.label = Paracetamol\n'; | ||
const frMessage = 'cht-stock-monitoring-workflow.stock_out.tasks.stock_out = Stock épuisé\ncht-stock-monitoring-workflow.stock_out.message.stock_at_hand = Stock actuel: {{qty}}\ncht-stock-monitoring-workflow.stock_out.message.stock_required = Stock nécessaire: {{qty}}\ncht-stock-monitoring-workflow.stock_out.message.summary_header = Résumé\ncht-stock-monitoring-workflow.stock_out.message.submit_note = {{name}} a épuisé son stock des éléments suivants:\ncht-stock-monitoring-workflow.stock_out.message.summary_note = Stock épuisé\ncht-stock-monitoring-workflow.items.paracetamol.label = Paracetamole\n'; | ||
|
||
beforeEach(async () => { | ||
setDirToprojectConfig(); | ||
await writeTranslationMessages(frMessage, enMessage, process.cwd()); | ||
}); | ||
|
||
afterEach(async() => { | ||
jest.clearAllMocks(); | ||
await resetTranslationMessages(process.cwd()); | ||
revertBackToProjectHome(workingDir); | ||
process.argv = processInitialArgv; // Restore the original argv after each test | ||
}); | ||
|
||
/** Testing getItemRows function */ | ||
// Testing get item row function out config generation with no or wrong item config and params | ||
it('This should throw error and should not generate rows with empty header, messages, languages(fr, en) and items to be added ', async () => { | ||
|
||
const header = []; | ||
const messages = {}; | ||
const items = [{}]; | ||
|
||
expect(() => getItemRows(header, stockOutMockConfigs.languages, messages, items)).toThrow(TypeError); | ||
|
||
}); | ||
|
||
// Testing get item row function out config generation with correct item config and params | ||
it('This should return rows with header, messages, languages(fr, en) and items to be added ', async () => { | ||
|
||
const header = [ | ||
'type', | ||
'name', | ||
'required', | ||
'relevant', | ||
'appearance', | ||
'constraint', | ||
'constraint_message', | ||
'calculation', | ||
'default', | ||
'label::en', | ||
'label::fr', | ||
'hint:en', | ||
'hint:fr' | ||
]; | ||
|
||
const messages = getTranslations(); | ||
const items = Object.values(stockOutMockConfigs.items); | ||
|
||
const row = getItemRows(header, stockOutMockConfigs.languages, messages, items); | ||
expect(row).not.toEqual([]); | ||
expect(row.length).toBe(items.length); | ||
expect(row[0].length).toBe(7); | ||
const rowData = row[0][0]; | ||
expect(rowData.length).toBe(13); | ||
expect(rowData[0]).toEqual('note'); | ||
expect(rowData[1]).toContain(items[0].name); | ||
|
||
}); | ||
|
||
/** Testing getStockOutConfigs function */ | ||
// Testing stock out config generation with correct item config | ||
it('This should return stock out configurations based the item config provided ', async () => { | ||
process.argv = ['node', '', '','', '' ,'stock_out', 'item_danger_qty', 'Stock Out, Rupture de Stock']; | ||
const configs = { | ||
form_name: 'stock_out', | ||
formular: 'item_danger_qty', | ||
title: { en: 'Stock Out', fr: ' Rupture de Stock' } | ||
}; | ||
const featureConfigs = await getStockOutConfigs(stockOutMockConfigs); | ||
expect(featureConfigs).toEqual(configs); | ||
|
||
}); | ||
|
||
// Testing stock out config not generating with no or wrong item config | ||
it('This should throw error for xform configurations with no or wrong item config', async () => { | ||
await expect(getStockOutConfigs(mockConfigsWithNoFeauture)).rejects.toThrow(Error); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters