Skip to content

Commit

Permalink
fix: better organize test-utils.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestoteo committed Nov 5, 2024
1 parent ddeeabe commit b34b070
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
16 changes: 5 additions & 11 deletions test/stock-out-feature.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@ const { mockConfigs } = require('./mocks/mocks');
const { updateStockOut } = require('../src/features/stock-out');
const {
setDirToprojectConfig,
revertBackToProjectHome
revertBackToProjectHome,
cleanUp
} = require('./test-utils');

describe('updateStockOut', () => {
const workingDir = process.cwd();
const createdAppFormFiles = ['stock_out.properties.json', 'stock_out.xlsx'];


beforeEach(() => {
setDirToprojectConfig();
});

afterEach(() => {
cleanUp(workingDir, createdAppFormFiles);
jest.clearAllMocks();
revertBackToProjectHome(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.
Expand Down Expand Up @@ -73,14 +76,5 @@ describe('updateStockOut', () => {
]
});

// 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);
}
});
}

});
});
7 changes: 6 additions & 1 deletion test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ const revertBackToProjectHome = (projectHome) =>{
const cleanUp = (workingDir, fileNames) => {
const processDir = path.join(workingDir,'test/project-config/');
for(const formFile of fileNames){
fs.unlinkSync(path.join(processDir, 'forms', 'app', formFile));
const filePath = path.join(processDir, 'forms', 'app', formFile);
fs.stat(filePath, (error) => {
if (!error) {
fs.unlinkSync(filePath);
}
});
}

// Removing the stock monitoring init file and stock count file
Expand Down

0 comments on commit b34b070

Please sign in to comment.