Skip to content

Commit

Permalink
Support four types of json comparisons: compatible-structure, exact-s…
Browse files Browse the repository at this point in the history
…tructure, compatible and exact
  • Loading branch information
knuthelv committed Dec 23, 2022
1 parent 9accba7 commit fb35098
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions src/compareJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,39 +216,39 @@ function isJsonStructureCompatible(expected, actual) {
: isCompatibleObjects(expected, actual, false, false)
}

function isJsonStructureExact(expected, actual) {
return Array.isArray(expected)
? isCompatibleArrays(expected, actual, false, true)
: isCompatibleObjects(expected, actual, false, true)
}

function isJsonCompatible(expected, actual) {
return Array.isArray(expected)
? isCompatibleArrays(expected, actual, true, false)
: isCompatibleObjects(expected, actual, true, false)
}

function isJsonStructureExact(expected, actual) {
return Array.isArray(expected)
? isCompatibleArrays(expected, actual, false, true)
: isCompatibleObjects(expected, actual, false, true)
}

function isJsonIdentical(expected, actual) {
return Array.isArray(expected)
? isCompatibleArrays(expected, actual, true, true)
: isCompatibleObjects(expected, actual, true, true)
}

export const COMPARISON = {
STRUCTURE: 'structure',
EXACT_STRUCTURE: 'exact-structure',
COMPATIBLE_STRUCTURE: 'compatible-structure',
COMPATIBLE: 'compatible',
EXACT_STRUCTURE: 'exact-structure',
EXACT: 'exact'
}

export function compareJson(expected, actual, comparison) {
switch (comparison.toLowerCase()) {
case COMPARISON.STRUCTURE:
case COMPARISON.COMPATIBLE_STRUCTURE:
return isJsonStructureCompatible(expected, actual)
case COMPARISON.EXACT_STRUCTURE:
return isJsonStructureExact(expected, actual)
case COMPARISON.COMPATIBLE:
return isJsonCompatible(expected, actual)
case COMPARISON.EXACT_STRUCTURE:
return isJsonStructureExact(expected, actual)
case COMPARISON.EXACT:
return isJsonIdentical(expected, actual)
default:
Expand Down
2 changes: 1 addition & 1 deletion src/execute-black-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function executeInteraction(interactionWithConfig) {
export function executeBlackBox(interactions, index) {
const executeNext = interactionData => {
const data = {
[interactionData.name + '-' + index]: interactionData
[interactionData.name + '-' + (index + 1)]: interactionData
}

if (interactionData.status === FAILURE) {
Expand Down

0 comments on commit fb35098

Please sign in to comment.