-
-
Save lmeerkatz/09b27c863079256b35cbe7d201e84bc5 to your computer and use it in GitHub Desktop.
Test passes when run alone; fails when run with other methods in the same class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
private class Debug_VFxTestFailure { | |
/** | |
* @description Sets up data for test methods | |
*/ | |
@TestSetup | |
static void setup() { | |
List<Account> accts = VFx_TestData.createAccounts(1); | |
insert accts; | |
VFx_TestData.insertUser('test1@VFx_VolunteerActivities_Test.test', 'Donor on Platform'); | |
// insert an activity | |
List<Volunteer_Activity__c> activities = VFx_TestData.createVolunteerEvents(accts[0], 2); | |
insert activities; | |
} | |
// this test will pass when run alone, but fail when run along with testDestroyAllowed() | |
@isTest | |
static void testSaveUpdateAllowed() { | |
User donorUser = | |
[SELECT Id FROM User WHERE Username = 'test1@VFx_VolunteerActivities_Test.test' LIMIT 1]; | |
Volunteer_Activity__c activity = [SELECT Id, Name, RecordType.DeveloperName FROM Volunteer_Activity__c LIMIT 1]; | |
Boolean exceptionCaught = false; | |
try { | |
System.runAs(donorUser) { | |
// this is actually what I want to test, but for the sake of clarity let's just do basic DML | |
//(Volunteer_Activity__c)VFx_VolunteerActivities.save(activity)); | |
upsert activity; | |
} | |
} catch (DMLException e) { | |
exceptionCaught = true; | |
System.debug('e: ' + e); | |
System.debug('e.getCause(): ' + e.getCause()); | |
System.debug('e.getStackTraceString(): ' + e.getStackTraceString()); | |
} | |
System.assertEquals(false, exceptionCaught, 'A Donor on Platform user can update a Volunteer Activity.'); | |
//System.assertEquals('Something else', activity.Name); | |
} | |
@isTest | |
static void testDestroyAllowed() { | |
User sysAdmin = VFx_TestData.getUserForProfile('System Administrator'); | |
Volunteer_Activity__c activity = [SELECT Id FROM Volunteer_Activity__c LIMIT 1]; | |
Boolean exceptionCaught = false; | |
try { | |
System.runAs(sysAdmin) { | |
// this is actually what I want to test, but for the sake of clarity let's just do basic DML | |
//VFx_VolunteerActivities.destroy(activity); | |
delete activity; | |
} | |
} catch (Exception e) { | |
exceptionCaught = true; | |
} | |
System.assertEquals(false, exceptionCaught, 'A System Adminstrator can delete a Volunteer Activity.'); | |
} | |
} |
This is the error from the test failure:
System.DmlException: Upsert failed. First exception on row 0 with id a1D8A000000Ci1XUAS; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No changes were made to the file between test runs.