Skip to content

Bug to install Apex Mocks with Script #515

@taboadavictor

Description

@taboadavictor

Describe the bug
When activating the multi-currency feature in a Salesforce environment, the installation or validation of the fflib-apex-common library fails due to errors in tests related to object selection and handling of currency fields (CurrencyIsoCode). The fflib_SObjectSelectorTest tests show assertion failures, indicating that the inclusion or exclusion of the CurrencyIsoCode field in SOQL queries and field selections is not as expected by the library in a multi-currency environment.

To Reproduce

(Please provide a public github repo with a full SFDX project that demonstrates the problem. If the repro case can be followed with a single example Apex class against a scratch org with just the fflib-apex-common and fflib-apex-mocks project deployed into it, you don't need to provide a github repo)

Steps to reproduce the behavior:

1.Create a scratch org with multi-currency functionality enabled.

2.Deploy the fflib-apex-common library to the scratch org.

3.Run the Apex tests for the fflib-apex-common library.

4.Observe the failures in the fflib_SObjectSelectorTest tests.

Expected behavior
The fflib-apex-common library should be installed, and all its tests should pass successfully, even in Salesforce environments with multi-currency functionality enabled. The handling of the CurrencyIsoCode field in SOQL queries and field selections should be consistent and not cause assertion failures.

Screenshots and text of error observed

Test Failures [4]
• fflib_SObjectSelectorTest.toSOQL_When_GreatGreatGrandchildRelationships_Expect_WelformedSOQL
message: System.AssertException: Assertion Failed: Expected: SELECT name, id, annualrevenue, accountnumber, (SELECT id, contractnumber, (SELECT name, id, amount, closedate, (SELECT id, name, (SELECT id, subject FROM Tasks ORDER BY Subject ASC NULLS FIRST ) FROM ListEmails ORDER BY Name ASC NULLS FIRST ) FROM Opportunities ORDER BY Name ASC NULLS FIRST ) FROM Contracts ORDER BY ContractNumber ASC NULLS FIRST ) FROM Account WITH USER_MODE ORDER BY Name ASC NULLS FIRST , Actual: SELECT name, id, annualrevenue, accountnumber, currencyisocode, (SELECT id, contractnumber, currencyisocode, (SELECT name, id, amount, closedate, currencyisocode, (SELECT id, name, currencyisocode, (SELECT id, subject, currencyisocode FROM Tasks ORDER BY Subject ASC NULLS F
stacktrace:
Class.fflib_SObjectSelectorTest.toSOQL_When_GreatGreatGrandchildRelationships_Expect_WelformedSOQL: line 843, column 1

• fflib_SObjectSelectorTest.toSOQL_When_PolymorphicSelect_Expect_RelatedType
message: System.AssertException: Assertion Failed: Expected: {CommentBody, CurrencyIsoCode, Id, Parent.CurrencyIsoCode, Parent.Id, Parent.Owner.CurrencyIsoCode, Parent.Owner.Id, Parent.Owner.UserRoleId, Parent.OwnerId}, Actual: {CommentBody, Id, Parent.CurrencyIsoCode, Parent.Id, Parent.Owner.CurrencyIsoCode, Parent.Owner.Id, Parent.Owner.UserRoleId, Parent.OwnerId}
stacktrace:
Class.fflib_SObjectSelectorTest.toSOQL_When_PolymorphicSelect_Expect_RelatedType: line 737, column 1

• fflib_SObjectSelectorTest.toSOQL_When_PolymorphicSelectInMulticurrency_Expect_RelatedType
message: System.AssertException: Assertion Failed: Expected: {CommentBody, CurrencyIsoCode, Id, Parent.CurrencyIsoCode, Parent.Id, Parent.Owner.Id, Parent.OwnerId}, Actual: {CommentBody, Id, Parent.CurrencyIsoCode, Parent.Id, Parent.Owner.Id, Parent.OwnerId}
stacktrace:
Class.fflib_SObjectSelectorTest.toSOQL_When_PolymorphicSelectInMulticurrency_Expect_RelatedType: line 772, column 1

• fflib_SObjectSelectorTest.toSOQL_When_SystemModePolymorphicSelect_Expect_RelatedType
message: System.AssertException: Assertion Failed: Expected: SELECT id, commentbody, currencyisocode, parent.ownerid, parent.id, parent.currencyisocode, parent.owner.userroleid, parent.owner.id, parent.owner.currencyisocode FROM CaseComment WITH SYSTEM_MODE ORDER BY CreatedDate ASC NULLS FIRST , Actual: SELECT id, commentbody, parent.ownerid, parent.id, parent.currencyisocode, parent.owner.userroleid, parent.owner.id, parent.owner.currencyisocode FROM CaseComment WITH SYSTEM_MODE ORDER BY CreatedDate ASC NULLS FIRST
stacktrace:
Class.fflib_SObjectSelectorTest.toSOQL_When_SystemModePolymorphicSelect_Expect_RelatedType: line 812, column 1

Version
Did you try to reproduce the problem against the latest fflib-apex-common code?
Yes, the problem was observed with the latest version of fflib-apex-common.

Script to install FFLIB:
import fs from 'fs';
import childProcess from 'child_process';
import path from 'path';

const REPOS = [
/{
git: 'https://github.com/apex-enterprise-patterns/fflib-apex-mocks',
source: 'fflib-apex-mocks',
deployPath: 'sfdx-source',
}
,
/
{
git: 'https://github.com/apex-enterprise-patterns/fflib-apex-common',
source: 'fflib-apex-common',
deployPath: 'sfdx-source',
},/*
{
git: 'https://github.com/apex-enterprise-patterns/force-di',
source: 'force-di',
deployPath: 'force-di',
},
{
git: 'https://github.com/apex-enterprise-patterns/at4dx',
source: 'at4dx',
deployPath: 'sfdx-source',
},
*/
];

const execute = async (command, options = {}) => {
return new Promise((resolve, reject) => {
try {
console.log(Executing: ${command});
childProcess.execSync(command, { stdio: 'inherit', ...options });
resolve();
} catch (error) {
console.error(Error executing command: ${command});
reject(error);
}
});
};

const deployFflib = async (orgAlias) => {
const projectName = 'fflib-project';
const projectPath = path.join(process.cwd(), projectName);

console.log(\n--- Creating SFDX Project: ${projectName} ---);
if (fs.existsSync(projectPath)) {
console.warn(\x1b[33m%s\x1b[0m , Project directory ${projectName} already exists. Skipping creation.);
} else {
await execute(sfdx force:project:create --projectname ${projectName} --template empty --outputdir .);
}

console.log(\n--- Cloning fflib repositories into ${projectName} ---);
await Promise.all(
REPOS.map(async (item) => {
const { source, git } = item;
const repoPath = path.join(projectPath, source);
if (fs.existsSync(repoPath)) {
console.warn(\x1b[33m%s\x1b[0m , ${source} already exists in ${projectName}. Skipping clone.);
} else {
console.warn(\x1b[32m%s\x1b[0m , Cloning ${source} from ${git});
await execute(git clone ${git} ${repoPath});
}
})
);

console.log(\n--- Deploying fflib metadata to org: ${orgAlias} ---);
await Promise.all(
REPOS.map(async ({ source, deployPath }) => {
const metadataPath = path.join(source, deployPath);
console.warn(\x1b[32m%s\x1b[0m , \nDeploying metadata from ${metadataPath} to org.);
return execute(
sf project deploy start -d "./${metadataPath}" -o ${orgAlias},
{ cwd: projectPath } // Execute command in the project directory
);
})
);
console.log(\nSuccessfully installed fflib into org ${orgAlias}\n);
};

const getArgs = () =>
process.argv.slice(2, process.argv.length).reduce((acc, arg, key) => {
if (arg[0] === '-') {
const flags = arg.slice(1, arg.length).split('');
flags.forEach((flag) => {
acc[flag] = process.argv[key + 3];
});
}
return acc;
}, {});

const args = getArgs();
if (!args.e) {
console.error(
'\x1b[31m%s\x1b[0m ',
'Please provide org alias via the -e flag.'
);
} else {
deployFflib(args.e);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions