-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(input check): set input defaults appropriately
Checks and sets the input to the corresponding type/format required for successful execution. Moved the checks into its own function for handling.
- Loading branch information
1 parent
6e4999b
commit 67e112a
Showing
6 changed files
with
59 additions
and
22 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { describe, test, expect } from 'vitest'; | ||
|
||
import { setInquirerDefaults } from '../utils/setInquirerDefaults'; | ||
|
||
/** | ||
* To test setInquirerDefaults() | ||
* Input: configParam (Object) | ||
* Output: configParam (Object) | ||
*/ | ||
describe('setInquirerDefaults', () => { | ||
// Dummy data | ||
const testConfigParam = { | ||
outputFormat: ['JSON'], | ||
msLevel: '1 2', | ||
}; | ||
|
||
// Tests | ||
test('configure configParam appropriately', async () => { | ||
const configParam = await setInquirerDefaults(testConfigParam); | ||
|
||
expect(configParam.outputFormat).toStrictEqual('JSON'); | ||
expect(configParam.msLevel).toStrictEqual([1, 2]); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Set the configuration parameters based on Inquirer input. | ||
* @param {Object} configParam Configuration parameters received from the Inquirer prompts | ||
* @returns {Promise<Object>} A promise that resolves with an object containing the configuration parameters in the required format for execution. | ||
*/ | ||
export async function setInquirerDefaults(configParam) { | ||
// Set output format as a string instead on an array | ||
configParam.outputFormat = configParam.outputFormat[0]; | ||
|
||
// Set MS level as a number array instead of a string | ||
if (configParam.msLevel) { | ||
configParam.msLevel = configParam.msLevel.split(' ').map(Number); | ||
} | ||
return configParam; | ||
} |
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