-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update convertAssertionPriority usage
- Loading branch information
Showing
6 changed files
with
85 additions
and
18 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 was deleted.
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,23 @@ | ||
/** | ||
* This should take any of the valid priority inputs and return the currently known string | ||
* representation of that value. | ||
* TODO: Eventually, this should only need to take 'number' types as priority once 'REQUIRED' and | ||
* 'OPTIONAL' are no longer used | ||
* | ||
* @param {number|string} priority | ||
* @returns {null|string} | ||
*/ | ||
const convertAssertionPriority = priority => { | ||
const validInputRegex = | ||
/^(0|1|2|3|EXCLUDE|REQUIRED|MUST|OPTIONAL|SHOULD|MAY)$/; | ||
|
||
if (!validInputRegex.test(priority)) return null; | ||
|
||
if (priority === 0) return 'EXCLUDE'; | ||
if (priority === 'REQUIRED' || priority === 1) return 'MUST'; | ||
if (priority === 'OPTIONAL' || priority === 2) return 'SHOULD'; | ||
if (priority === 3) return 'MAY'; | ||
return priority; | ||
}; | ||
|
||
module.exports = convertAssertionPriority; |
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,55 @@ | ||
const convertAssertionPriority = require('./convertAssertionPriority'); | ||
|
||
describe('Verify expected values are returned when calling convertAssertionPriority', () => { | ||
it('expects valid priority strings are returned for known priority inputs', () => { | ||
const excludePriorityA = convertAssertionPriority(0); | ||
const excludePriorityB = convertAssertionPriority('EXCLUDE'); | ||
|
||
const mustPriorityA = convertAssertionPriority(1); | ||
const mustPriorityB = convertAssertionPriority('REQUIRED'); | ||
const mustPriorityC = convertAssertionPriority('MUST'); | ||
|
||
const shouldPriorityA = convertAssertionPriority(2); | ||
const shouldPriorityB = convertAssertionPriority('OPTIONAL'); | ||
const shouldPriorityC = convertAssertionPriority('SHOULD'); | ||
|
||
const mayPriorityA = convertAssertionPriority(3); | ||
const mayPriorityB = convertAssertionPriority('MAY'); | ||
|
||
expect(excludePriorityA).toEqual('EXCLUDE'); | ||
expect(excludePriorityB).toEqual('EXCLUDE'); | ||
|
||
expect(mustPriorityA).toEqual('MUST'); | ||
expect(mustPriorityB).toEqual('MUST'); | ||
expect(mustPriorityC).toEqual('MUST'); | ||
|
||
expect(shouldPriorityA).toEqual('SHOULD'); | ||
expect(shouldPriorityB).toEqual('SHOULD'); | ||
expect(shouldPriorityC).toEqual('SHOULD'); | ||
|
||
expect(mayPriorityA).toEqual('MAY'); | ||
expect(mayPriorityB).toEqual('MAY'); | ||
}); | ||
|
||
it('expects null values are returned for unknown priority inputs', () => { | ||
const invalidInputA = convertAssertionPriority(-1); | ||
const invalidInputB = convertAssertionPriority(4); | ||
const invalidInputC = convertAssertionPriority(12); | ||
const invalidInputD = convertAssertionPriority('EXCLUDED'); | ||
const invalidInputE = convertAssertionPriority('RANDOM STRING'); | ||
|
||
expect(invalidInputA).not.toEqual('MUST'); | ||
expect(invalidInputA).toEqual(null); | ||
|
||
expect(invalidInputB).toEqual(null); | ||
|
||
expect(invalidInputC).not.toEqual('MUST'); | ||
expect(invalidInputC).not.toEqual('SHOULD'); | ||
expect(invalidInputC).toEqual(null); | ||
|
||
expect(invalidInputD).not.toEqual('EXCLUDE'); | ||
expect(invalidInputD).toEqual(null); | ||
|
||
expect(invalidInputE).toEqual(null); | ||
}); | ||
}); |
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