You need to sign in to do that
Don't have an account?
Anonymous Developer
Test Class Dilemma
public with sharing class AS_customTopbarNotification{
@AuraEnabled
public static Boolean getMessages(String communityId) {
ConnectApi.FeedElementPage unread = ConnectApi.ChatterFeeds.getFeedElementsFromFeed(communityId, ConnectApi.FeedType.DirectMessages);
Boolean hasUnread = false;
for (ConnectApi.FeedElement feedEl : unread.elements) {
if (!feedEl.capabilities.readBy.isReadByMe) {
hasUnread = true;
break;
}
}
System.debug('hasUnread ' + hasUnread);
return hasUnread;
}
}
Can anyone make a test class out of this code?
Thanks in advance.
@AuraEnabled
public static Boolean getMessages(String communityId) {
ConnectApi.FeedElementPage unread = ConnectApi.ChatterFeeds.getFeedElementsFromFeed(communityId, ConnectApi.FeedType.DirectMessages);
Boolean hasUnread = false;
for (ConnectApi.FeedElement feedEl : unread.elements) {
if (!feedEl.capabilities.readBy.isReadByMe) {
hasUnread = true;
break;
}
}
System.debug('hasUnread ' + hasUnread);
return hasUnread;
}
}
Can anyone make a test class out of this code?
Thanks in advance.
Please follow below code:
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
All Answers
Please follow below code:
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
https://salesforce.stackexchange.com/questions/244788/how-do-i-write-an-apex-unit-test
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines
If you face any specific issue while attempting do post that here.
Thanks!
Good day thank you for taking the time to write the code but sad to say it is not the code that I was expecting or wanted, nevertheless due to the time you put in on it ill just mark it as the best answer. What I was looking for was the code coverage in my class if you could be so kind to answer it would be much appreciated. Thanks in advance.
Here's my test class atm:
@isTest
public class AS_customNotificationTestClass {
@testSetup static void testData() {
String communityId = [SELECT Id FROM Network][0].Id;
ConnectApi.FeedElementPage testPage = new ConnectApi.FeedElementPage();
List<ConnectApi.FeedItem> testEl = new List<ConnectApi.FeedItem>();
ConnectApi.FeedItem feedItem1 = new ConnectApi.FeedItem();
ConnectApi.FeedItem feedItem2 = new ConnectApi.FeedItem();
ConnectApi.DirectMessageCapability dM1 = new ConnectApi.DirectMessageCapability();
dM1.subject = 'Test 1';
ConnectApi.ReadByCapability readby1 = new ConnectApi.ReadByCapability();
readby1.isReadByMe = true;
ConnectApi.FeedElementCapabilities capability1 = new ConnectApi.FeedElementCapabilities();
capability1.readBy = readby1;
capability1.directMessage = dM1;
feedItem1.capabilities = capability1;
ConnectApi.DirectMessageCapability dM2 = new ConnectApi.DirectMessageCapability();
dM2.subject = 'Test 2';
ConnectApi.ReadByCapability readby2 = new ConnectApi.ReadByCapability();
readby2.isReadByMe = false;
ConnectApi.FeedElementCapabilities capability2 = new ConnectApi.FeedElementCapabilities();
capability2.readBy = readby2;
capability2.directMessage = dM2;
feedItem1.capabilities = capability2;
testEl.add(feedItem1);
testEl.add(feedItem2);
testPage.elements = testEl;
ConnectApi.ChatterFeeds.setTestGetFeedElementsFromFeed(null, ConnectApi.FeedType.DirectMessages, testPage);
}
@isTest
static void doTest(){
String communityId = [SELECT Id FROM Network][0].Id;
Test.startTest();
System.assertNotEquals(null, AS_customTopbarNotification.getInbox(null));
Test.stopTest();
}
}
I have no idea how to proceed I am stuck.