From 0eb339c3a482cab5ac323d9cd89e0db7d3bf8809 Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Thu, 18 Nov 2021 13:54:28 +0000 Subject: [PATCH] permission-node: more visible condition transform in mapCriteria test Signed-off-by: Mike Lewis --- .../src/integration/util.test.ts | 43 ++++++------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/plugins/permission-node/src/integration/util.test.ts b/plugins/permission-node/src/integration/util.test.ts index 93f51d8275..72e87b2a7b 100644 --- a/plugins/permission-node/src/integration/util.test.ts +++ b/plugins/permission-node/src/integration/util.test.ts @@ -25,21 +25,21 @@ describe('integration utils', () => { criteria: PermissionCriteria; expectedResult: { applyConditions: boolean; - mapConditions: PermissionCriteria<{ query: string; params: unknown[] }>; + mapConditions: PermissionCriteria; }; }[] = [ { criteria: { rule: 'test-rule-1', params: [] }, expectedResult: { applyConditions: true, - mapConditions: { query: 'test-rule-1', params: [] }, + mapConditions: 'test-rule-1', }, }, { criteria: { rule: 'test-rule-2', params: [] }, expectedResult: { applyConditions: false, - mapConditions: { query: 'test-rule-2', params: [] }, + mapConditions: 'test-rule-2', }, }, { @@ -52,10 +52,7 @@ describe('integration utils', () => { expectedResult: { applyConditions: true, mapConditions: { - anyOf: [ - { query: 'test-rule-1', params: ['a', 'b'] }, - { query: 'test-rule-2', params: ['c', 'd'] }, - ], + anyOf: ['test-rule-1:a,b', 'test-rule-2:c,d'], }, }, }, @@ -69,10 +66,7 @@ describe('integration utils', () => { expectedResult: { applyConditions: false, mapConditions: { - allOf: [ - { query: 'test-rule-1', params: ['e', 'f'] }, - { query: 'test-rule-2', params: ['g', 'h'] }, - ], + allOf: ['test-rule-1:e,f', 'test-rule-2:g,h'], }, }, }, @@ -83,7 +77,7 @@ describe('integration utils', () => { expectedResult: { applyConditions: true, mapConditions: { - not: { query: 'test-rule-2', params: ['i'] }, + not: 'test-rule-2:i', }, }, }, @@ -111,17 +105,11 @@ describe('integration utils', () => { mapConditions: { allOf: [ { - anyOf: [ - { query: 'test-rule-1', params: ['j'] }, - { query: 'test-rule-2', params: ['k'] }, - ], + anyOf: ['test-rule-1:j', 'test-rule-2:k'], }, { not: { - allOf: [ - { query: 'test-rule-1', params: ['l'] }, - { query: 'test-rule-2', params: ['m'] }, - ], + allOf: ['test-rule-1:l', 'test-rule-2:m'], }, }, ], @@ -152,17 +140,11 @@ describe('integration utils', () => { mapConditions: { allOf: [ { - anyOf: [ - { query: 'test-rule-1', params: ['j'] }, - { query: 'test-rule-2', params: ['k'] }, - ], + anyOf: ['test-rule-1:j', 'test-rule-2:k'], }, { not: { - allOf: [ - { query: 'test-rule-1', params: ['l'] }, - { not: { query: 'test-rule-2', params: ['m'] } }, - ], + allOf: ['test-rule-1:l', { not: 'test-rule-2:m' }], }, }, ], @@ -194,7 +176,10 @@ describe('integration utils', () => { }); describe('mapConditions', () => { - const mapFn = jest.fn(({ rule, params }) => ({ query: rule, params })); + const mapFn = jest.fn( + ({ rule, params }) => + `${rule}${params.length ? `:${params.join(',')}` : ''}`, + ); it('invokes mapFn to transform conditions', () => { mapConditions({ rule: 'test-rule-1', params: ['foo', 'bar'] }, mapFn);