function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kunal Purohit 4Kunal Purohit 4 

How to write Test class for following web service?

Hello team, Plz help me for writing test class for code given below.
@RestResource(urlMapping='/Projects/*')
global class GetProjectsFromTeamWork {
    @HttpPost
    global static void doPost() {
        RestRequest req = RestContext.request;
        String jsonresponse = req.requestBody.toString();
        system.debug('jsonresponse=='+jsonresponse);
        
        wrapperOfProject proj = (wrapperOfProject)JSON.deserialize(jsonresponse, wrapperOfProject.class);
        Contact contactRefference = new Contact(UserId__c = proj.Project.ownerId);
        List<Account> accList = [Select id From Account Where CompanyId__c = :proj.Project.companyId];
        system.debug('accList==='+accList);
        List<Opportunity> oppList = [Select id from Opportunity Where AccountId = :accList[0].id];
        System.debug('oppList==='+oppList);
        TW_Project__c projectObj = new TW_Project__c();
        projectObj.Name = proj.Project.name;
        projectObj.TW_Description__c = proj.Project.description;
        projectObj.TW_Opportunity__c = oppList[0].id;
        projectObj.ProjectId__c = proj.Project.id;
        projectObj.TW_Project_Manager__c = contactRefference.id;
        insert projectObj;
    }
    
    public class wrapperOfProject{
        public eventCreator eventCreator;
        public Project project;
    }
    
   	public class EventCreator {
		public Integer id;
		public String firstName;
		public String lastName;
		public String avatar;
	}
    
    public class Project {
		public String id;
		public String name;
		public String description;
		public String status;
		public Object startDate;
		public Object endDate;
		public List<Tags> tags;
		public String ownerId;
		public String companyId;
		public String categoryId;
		public String dateCreated;
	}
    
    public class Tags {
	}
}
SwethaSwetha (Salesforce Developers) 
HI Kunal,
The link https://developer.salesforce.com/forums/?id=9060G0000005PPvQAM should help you get started. Happy to help incase you are stuck at any specific step.

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you