-
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: review feedback and added unit test stock out
- Loading branch information
1 parent
c9a7dc6
commit 69f6cb9
Showing
7 changed files
with
239 additions
and
855 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
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
339 changes: 7 additions & 332 deletions
339
test/project-config/translations/messages-en.properties
Large diffs are not rendered by default.
Oops, something went wrong.
474 changes: 7 additions & 467 deletions
474
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
const ExcelJS = require('exceljs'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { mockConfigs } = require('./mocks/mocks'); | ||
const { updateStockOut } = require('../src/features/stock-out'); | ||
const { | ||
setDirToprojectConfig, | ||
} = require('./test-utils'); | ||
|
||
describe('updateStockOut', () => { | ||
const workingDir = process.cwd(); | ||
|
||
beforeEach(() => { | ||
setDirToprojectConfig(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
process.chdir(workingDir); | ||
}); | ||
|
||
it('should update the stock out form with correct values', async () => { | ||
const createdAppFormFiles = ['stock_out.properties.json', 'stock_out.xlsx']; | ||
const processDir = process.cwd(); | ||
|
||
// Check that stock out xlsx and properties files exist. | ||
for(const createdAppFormFile of createdAppFormFiles){ | ||
expect(fs.existsSync(path.join(processDir, 'forms', 'app', createdAppFormFile))).toBe(false); | ||
} | ||
// Call the function updateStockOut and check that the stock_out files are generated | ||
await updateStockOut(mockConfigs); | ||
|
||
for(const createdAppFormFile of createdAppFormFiles){ | ||
expect(fs.existsSync(path.join(processDir, 'forms', 'app', createdAppFormFile))).toBe(true); | ||
} | ||
|
||
// Check that stock out files content are correctly written. | ||
const formPath = path.join(processDir, 'forms', 'app', 'stock_out.xlsx'); | ||
const workbook = new ExcelJS.Workbook(); | ||
await workbook.xlsx.readFile(formPath); | ||
const spy = jest.spyOn(workbook, 'getWorksheet'); | ||
const surveyWorkSheet = workbook.getWorksheet('survey'); | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
const settingWorkSheet = workbook.getWorksheet('settings'); | ||
expect(spy).toHaveBeenCalledTimes(2); | ||
expect(surveyWorkSheet).not.toEqual([]); | ||
expect(settingWorkSheet).not.toEqual([]); | ||
|
||
|
||
const propertiesFileContent = fs.readFileSync( | ||
path.join(processDir, 'forms', 'app', 'stock_out.properties.json'), | ||
{encoding: 'utf-8'} | ||
); | ||
|
||
expect(JSON.parse(propertiesFileContent)).toEqual({ | ||
'context': { | ||
'expression': 'user.parent.contact_type === \'c50_supervision_area\'', | ||
'person': false, | ||
'place': false | ||
}, | ||
'icon': 'icon-healthcare-medicine', | ||
'title': [ | ||
{ | ||
'content': 'Stock Out Title', | ||
'locale': 'en' | ||
}, | ||
{ | ||
'content': 'Titre du Stock', | ||
'locale': 'fr' | ||
} | ||
] | ||
}); | ||
|
||
// Delete generated stock out files | ||
for(const createdAppFormFile of createdAppFormFiles){ | ||
fs.stat(path.join(processDir, 'forms', 'app', createdAppFormFile), (error) => { | ||
if (!error) { | ||
expect(fs.unlinkSync(path.join(processDir, 'forms', 'app', createdAppFormFile))).toBe(undefined); | ||
} | ||
}); | ||
} | ||
|
||
}); | ||
}); |
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