Skip to content

Commit

Permalink
Update convertAssertionPriority usage
Browse files Browse the repository at this point in the history
  • Loading branch information
howard-e committed Feb 6, 2024
1 parent af9a5b0 commit 3d1fbcb
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const convertAssertionPriority = require('../helpers/convertAssertionPriority');
const convertAssertionPriority = require('../../util/convertAssertionPriority');

const assertionResultsResolver = (scenarioResult, { priority }) => {
if (!priority) return scenarioResult.assertionResults;
Expand Down
7 changes: 0 additions & 7 deletions server/resolvers/helpers/convertAssertionPriority.js

This file was deleted.

14 changes: 5 additions & 9 deletions server/scripts/import-tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
const deepPickEqual = require('../../util/deepPickEqual');
const { hashTests } = require('../../util/aria');
const convertDateToString = require('../../util/convertDateToString');
const convertAssertionPriority = require('../../util/convertAssertionPriority');

const args = require('minimist')(process.argv.slice(2), {
alias: {
Expand Down Expand Up @@ -475,15 +476,10 @@ const getTests = ({
assertion.assertionId
)
.map(({ priority: assertionPriority }) => {
let priority = '';
if (assertionPriority === 0)
priority = 'EXCLUDE';
if (assertionPriority === 1)
priority = 'MUST';
if (assertionPriority === 2)
priority = 'SHOULD';
if (assertionPriority === 3)
priority = 'MAY';
let priority =
convertAssertionPriority(
assertionPriority
);

return {
priority,
Expand Down
23 changes: 23 additions & 0 deletions server/util/convertAssertionPriority.js
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;
55 changes: 55 additions & 0 deletions server/util/convertAssertionPriority.test.js
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);
});
});
2 changes: 1 addition & 1 deletion server/util/getMetrics.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const convertAssertionPriority = require('../resolvers/helpers/convertAssertionPriority');
const convertAssertionPriority = require('./convertAssertionPriority');

const sum = arr => arr.reduce((total, item) => total + item, 0);

Expand Down

0 comments on commit 3d1fbcb

Please sign in to comment.