I'm writing a unit test to evaluate if a case was successfully assigned to a queue. Unfortunately, the SOQL query I'm using to get the case owner type is returning "null". I've validated that the owner is being set successfully, so I'm not sure why I can't retrieve the owner type. How can I access the case owner type in the SOQL query so that I can evaluate it in the System.assert line (2nd to last line)?
Here's my code:
@isTest static void insertByPartner() {
//tests that the partner is added to any cases that they create.
Case[] cases = TestClassUtils.getCases(1);
List<Database.SaveResult> results = new List<Database.SaveResult>();
User partnerTestUser = createPartnerUser();
Test.startTest();
System.runAs(partnerTestUser) {
results = Database.insert(cases, false);
}
Test.stopTest();
Set<ID> caseIdSet = new Set<ID>();
for(Database.SaveResult sr : results) {
System.assert(sr.isSuccess());
caseIdSet.add(sr.getId());
}
List<Case> queueCasesList = [SELECT Id, OwnerId, Owner.Type FROM Case WHERE Id IN :caseIdSet AND Owner.Type = 'Queue'];
for(Case newCase : queueCasesList) {
System.debug('The case owner is: '+ newCase.OwnerId);
System.debug('The case owner type is: ' + newCase.Owner.Type);
}
System.debug('Cases owned by queue when inserted by a partner user = ' + queueCasesList.size());
System.assert(queueCasesList.size() == 1);
}