Skip to content

Commit

Permalink
Verify that root paths work within $or
Browse files Browse the repository at this point in the history
  • Loading branch information
kjellmorten committed Dec 13, 2023
1 parent f697a75 commit 7bcb90c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/tests/if.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,36 @@ test('should support $or - matching', async (t) => {
t.deepEqual(ret, expected)
})

test('should support $or - matching with root', async (t) => {
const def = [
'content',
{
$if: {
$or: [
{ $transform: 'compare', path: 'section', match: 'news' },
{ $transform: 'compare', path: '^^.acceptAll', match: true },
],
},
then: { title: 'heading' },
else: { title: 'title' },
},
]
const data = {
acceptAll: true,
content: {
heading: 'The heading',
title: 'The title',
section: 'news',
archived: false,
},
}
const expected = { title: 'The heading' }

const ret = await mapTransform(def)(data)

t.deepEqual(ret, expected)
})

test('should support $or - not matching', async (t) => {
const def = [
'content',
Expand Down
13 changes: 13 additions & 0 deletions src/transformers/logical.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ test('should force values to boolean -- going forward', async (t) => {
t.true(ret)
})

test('should do a logical OR on the given paths -- using the root', async (t) => {
const stateWithRoot = { ...state, context: [{ acceptAll: true }] }
const path = ['^^.acceptAll', 'visible', 'meta.published', 'public']
const data = { visible: false, meta: { published: false }, public: false }

const ret = await logical({ path, operator: 'OR' })(options)(
data,
stateWithRoot,
)

t.true(ret)
})

// Tests -- reverse

test('should set all paths to the given boolean value', async (t) => {
Expand Down

0 comments on commit 7bcb90c

Please sign in to comment.