Skip to content
32 changes: 13 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
sudo: true
node_js: "7"
os: osx
node_js: '8'
cache: false

cache:
directories:
- node_modules

before_script:
- export URL=https://developer.salesforce.com/media/salesforce-cli/sfdx-linux-amd64.tar.xz
before_install:
- export SFDX_AUTOUPDATE_DISABLE=false
- export SFDX_USE_GENERIC_UNIX_KEYCHAIN=true
- export SFDX_DOMAIN_RETRY=300
- export SFDX_DISABLE_APP_HUB=true
- export SFDX_LOG_LEVEL=DEBUG
- export SFDX_ALIAS=servier-ci-$TRAVIS_BUILD_NUMBER
- mkdir sfdx
- wget -qO- $URL | tar xJ -C sfdx --strip-components 1
- "./sfdx/install"
- export PATH=./sfdx/$(pwd):$PATH
- export SFDX_IMPROVED_CODE_COVERAGE=true
- npm i -g sfdx-cli
- sfdx update
- sfdx --version
- sfdx plugins --core
- npm install apexcov coveralls -g
- echo force://$CLIENT_ID:$CLIENT_SECRET:$REFRESH_TOKEN@$INSTANCE_URL > .sfdx-url
- sfdx force:auth:sfdxurl:store --setdefaultdevhubusername --sfdxurlfile ./.sfdx-url --setalias DefaultOrg
- openssl aes-256-cbc -K $encrypted_79a2f6093848_key -iv $encrypted_79a2f6093848_iv -in assets/server.key.enc -out assets/server.key -d
- sfdx force:auth:jwt:grant --clientid $CONSUMERKEY --jwtkeyfile assets/server.key --username $USERNAME --setdefaultdevhubusername -a DevHub
- echo y | sfdx plugins:install @mavens/sfdx-commands

script:
- sfdx force:org:create --setdefaultusername --definitionfile scratchdef.json --setalias ci
- sfdx force:source:push
- sfdx force:org:create -v DevHub -s -f scratchdef.json -a ciorg
- sfdx force:org:display -u ciorg
- sfdx force:source:push -u ciorg
- mkdir coverage
- sfdx force:apex:test:run --codecoverage --testlevel=RunLocalTests --resultformat=human --outputdir=coverage
- sfdx force:apex:test:run -u ciorg --codecoverage --testlevel=RunLocalTests --resultformat=human --outputdir=coverage
- sfdx mavens:ci:lcov
- sfdx force:org:delete --noprompt
- sfdx force:org:delete -u ciorg -p
- cat ./coverage/lcov.info | coveralls
Binary file added assets/server.key.enc
Binary file not shown.
15 changes: 15 additions & 0 deletions force-app/main/default/classes/Q.cls
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ public class Q {
return cond;
}

/*
* Instantiate a DateLiteral object
*/
public static QDateLiteral dateLiteral(QDateLiteral.Value literal) {
return dateLiteral(literal, null);
}

/*
* Instantiate a DateLiteral object
*/
public static QDateLiteral dateLiteral(QDateLiteral.Value literal, Integer value) {
QDateLiteral dateLiteral = new QDateLiteral(literal, value);
return dateLiteral;
}

/**
* Add an OrderBy statement
*/
Expand Down
4 changes: 3 additions & 1 deletion force-app/main/default/classes/QCondition.cls
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public class QCondition implements QICondition {
} else if (val instanceof Date) {
String dateString = String.valueOf(val);
return dateString.substring(0, dateString.indexOf(' '));
} else {
} else if (val instanceof QDateLiteral) {
return ((QDateLiteral)val).buildLiteral();
}else {
return val;
}
}
Expand Down
8 changes: 8 additions & 0 deletions force-app/main/default/classes/QConditionTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,12 @@ private class QConditionTest {
System.assertEquals('Name != null', segment);
}

@isTest
static void testDateLiteral() {
String segment = new QCondition('CreatedDate').equalsTo(Q.dateLiteral(QDateLiteral.Value.LAST_N_DAYS, 7)).build();
System.assertEquals('CreatedDate = LAST_N_DAYS:7', segment);

segment = new QCondition('CreatedDate').equalsTo(Q.dateLiteral(QDateLiteral.Value.YESTERDAY)).build();
System.assertEquals('CreatedDate = YESTERDAY', segment);
}
}
23 changes: 23 additions & 0 deletions force-app/main/default/classes/QDateLiteral.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Created by fehays on 4/7/2020.
*/

public without sharing class QDateLiteral {
public enum Value {
YESTERDAY,TODAY,TOMORROW,LAST_WEEK,THIS_WEEK,NEXT_WEEK,LAST_MONTH,THIS_MONTH,NEXT_MONTH,LAST_90_DAYS,
NEXT_90_DAYS,LAST_N_DAYS,NEXT_N_DAYS,NEXT_N_WEEKS,LAST_N_WEEKS,NEXT_N_MONTHS,LAST_N_MONTHS,THIS_QUARTER,
LAST_QUARTER,NEXT_QUARTER,NEXT_N_QUARTERS,LAST_N_QUARTERS,THIS_YEAR,LAST_YEAR,NEXT_YEAR,NEXT_N_YEARS,
LAST_N_YEARS,THIS_FISCAL_QUARTER,LAST_FISCAL_QUARTER,NEXT_FISCAL_QUARTER,NEXT_N_FISCAL_QUARTERS,LAST_N_FISCAL_QUARTERS,
THIS_FISCAL_YEAR,LAST_FISCAL_YEAR,NEXT_FISCAL_YEAR,NEXT_N_FISCAL_YEARS,LAST_N_FISCAL_YEARS
}
public Value literal { get; set; }
public Integer n { get; set; }

public QDateLiteral(Value literal, Integer n) {
this.literal = literal;
this.n = n;
}
public String buildLiteral() {
return (this.n != null) ? this.literal.name() + ':' + String.valueOf(this.n) : this.literal.name();
}
}
5 changes: 5 additions & 0 deletions force-app/main/default/classes/QDateLiteral.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>48.0</apiVersion>
<status>Active</status>
</ApexClass>