Skip to content

Commit

Permalink
Added CustomTableProvider withTableOql
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Bendfelt committed Jun 16, 2021
1 parent de8add8 commit 045605e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/providers/custom-table/match-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class MatchBuilder {
this.globalObjectType = globalObjectType;
this.linkFieldNameForRow = linkFieldNameForRow;
this.mandatoryOql = {};
this.tableOql;
this.optionalMatches = [];
}

Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
32 changes: 31 additions & 1 deletion test/providers/providers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 045605e

Please sign in to comment.