diff --git a/lib/providers/custom-table/match-builder.js b/lib/providers/custom-table/match-builder.js index d950b82..3c8c02c 100644 --- a/lib/providers/custom-table/match-builder.js +++ b/lib/providers/custom-table/match-builder.js @@ -6,6 +6,7 @@ class MatchBuilder { this.globalObjectType = globalObjectType; this.linkFieldNameForRow = linkFieldNameForRow; this.mandatoryOql = {}; + this.tableOql; this.optionalMatches = []; } @@ -14,6 +15,11 @@ class MatchBuilder { return this; } + withTableOql(tableOql) { + this.tableOql = tableOql; + return this; + } + optionalMatch(optionalMatchOql, matchColumn) { this.optionalMatches.push(`${optionalMatchOql},${matchColumn}`); return this; @@ -45,7 +51,7 @@ function retrieveTableInstances(moduleDigest) { .getCustomObjectDesignWorkflowFeature(this.globalObjectType) .businessStatusField[0]; const apiVersion = moduleDigest.getCustomObjectDesignApiVersion(this.globalObjectType); - const topLevelOql = `${businessStatusField} = 'Active'`; + const topLevelOql = this.tableOql || `${businessStatusField} = 'Active'`; const queryResult = this.bridge.newQuery(this.globalObjectType, apiVersion) .setOQL(topLevelOql) .execute(); diff --git a/test/providers/providers.spec.js b/test/providers/providers.spec.js index 07edf69..ee000ba 100644 --- a/test/providers/providers.spec.js +++ b/test/providers/providers.spec.js @@ -24,6 +24,20 @@ const seed = { 'columnC': 'AAAAAA' }] } + }], + 'Status = \'Complete\'': [{ + 'testEntries': { + 'field1 = \'fieldValue\'': [{ + 'columnA': 'value1', + 'columnB': 'value1', + 'columnC': 'value1' + }], + 'field1 = \'fieldValue\'columnA =\'valueX\',columnA:columnC =\'ZZZZZZ\',columnC': [{ + 'columnA': 'valueX', + 'columnB': 'value1', + 'columnC': 'AAAAAA' + }] + } }] }, 'NumberingPool': { @@ -119,7 +133,23 @@ describe('providers', () => { }]); done(); }); - it('returns empty when no match is found', (done) => { + it('can override the standard provider table oql', (done) => { + const overrideTableOqlLookup = lProviders.getCustomTableProvider() + .matchLookup('$testTableQ1', 'testEntries') + .withOql("field1 = 'fieldValue'") + .withTableOql("Status = 'Complete'") + .optionalMatch("columnA ='valueX'", "columnA") + .optionalMatch("columnC ='ZZZZZZ'", "columnC") + .execute(); + expect(overrideTableOqlLookup.length).to.equal(1); + expect(overrideTableOqlLookup).to.deep.equal([{ + 'columnA': 'valueX', + 'columnB': 'value1', + 'columnC': 'AAAAAA' + }]); + done(); + }); + it('returns error when no match is found', (done) => { const lookup = () => { lProviders.getCustomTableProvider() .matchLookup('$testTableQ2', 'testEntries')