You need to sign in to do that
Don't have an account?
zeenat mangat
please help me to improve my test class, now it is 72% in the production
Here is my apex class controller.
Below this I have created its test class.
please help me to find the problem.
@RestResource(urlMapping='/v2/addUpsell/*')
global with sharing class REST_Upsell_Controller {
@HttpPost
global static String processUpsell(String orderId, Decimal price, Decimal shipping, Decimal tax){
ChargentOrders__ChargentOrder__c order = [SELECT Id, ChargentOrders__Subtotal__c, ChargentOrders__Tax__c, ChargentOrders__Shipping__c FROM ChargentOrders__ChargentOrder__c WHERE Id = :orderId];
Decimal prc = order.ChargentOrders__Subtotal__c;
Decimal tx = order.ChargentOrders__Tax__c;
Decimal shp = order.ChargentOrders__Shipping__c;
if(tx!= null){
order.ChargentOrders__Tax__c= tx+tax;
}else{
order.ChargentOrders__Tax__c= tax;
}
if(shp!= null){
order.ChargentOrders__Shipping__c= shp+shipping;
}else{
order.ChargentOrders__Shipping__c= shipping;
}
order.ChargentOrders__Subtotal__c= prc+price;
try {
/* Update Order with Upsell Amount */
update order;
return 'added';
} catch (DmlException e) {
return 'false';
}
}
}
Test class :-
@isTest(SeeAllData=true)
public class REST_Upsell_Controller_Test {
static testMethod void testCreateNewUpsell(){
String orderId = 'a0555000000N5BnAAK';
Decimal price = 30.00;
Decimal shipping = 20.55;
Decimal tax = 12.22;
Decimal prc = 10.00;
Decimal tx = 20.22;
Decimal shp = 15.20;
Decimal txs = tx+tax;
Decimal shps = shp+shipping;
Decimal prcs = prc+price;
ChargentOrders__ChargentOrder__c oderobj = new ChargentOrders__ChargentOrder__c();
oderobj.ChargentOrders__Tax__c = txs;
oderobj.ChargentOrders__Shipping__c = shps;
oderobj.ChargentOrders__Subtotal__c = prcs;
insert oderobj;
RestRequest req = new RestRequest();
RestResponse res = new RestResponse();
req.requestURI = '/v2/addUpsell/*'; //Request URL
req.httpMethod = 'POST';//HTTP Request Type
RestContext.request = req;
RestContext.response= res;
String strResponse = REST_Upsell_Controller.processUpsell('a0555000000N5BnAAK',30.00,20.55,12.22);
System.assertEquals('added',strResponse);
}
}
Below this I have created its test class.
please help me to find the problem.
@RestResource(urlMapping='/v2/addUpsell/*')
global with sharing class REST_Upsell_Controller {
@HttpPost
global static String processUpsell(String orderId, Decimal price, Decimal shipping, Decimal tax){
ChargentOrders__ChargentOrder__c order = [SELECT Id, ChargentOrders__Subtotal__c, ChargentOrders__Tax__c, ChargentOrders__Shipping__c FROM ChargentOrders__ChargentOrder__c WHERE Id = :orderId];
Decimal prc = order.ChargentOrders__Subtotal__c;
Decimal tx = order.ChargentOrders__Tax__c;
Decimal shp = order.ChargentOrders__Shipping__c;
if(tx!= null){
order.ChargentOrders__Tax__c= tx+tax;
}else{
order.ChargentOrders__Tax__c= tax;
}
if(shp!= null){
order.ChargentOrders__Shipping__c= shp+shipping;
}else{
order.ChargentOrders__Shipping__c= shipping;
}
order.ChargentOrders__Subtotal__c= prc+price;
try {
/* Update Order with Upsell Amount */
update order;
return 'added';
} catch (DmlException e) {
return 'false';
}
}
}
Test class :-
@isTest(SeeAllData=true)
public class REST_Upsell_Controller_Test {
static testMethod void testCreateNewUpsell(){
String orderId = 'a0555000000N5BnAAK';
Decimal price = 30.00;
Decimal shipping = 20.55;
Decimal tax = 12.22;
Decimal prc = 10.00;
Decimal tx = 20.22;
Decimal shp = 15.20;
Decimal txs = tx+tax;
Decimal shps = shp+shipping;
Decimal prcs = prc+price;
ChargentOrders__ChargentOrder__c oderobj = new ChargentOrders__ChargentOrder__c();
oderobj.ChargentOrders__Tax__c = txs;
oderobj.ChargentOrders__Shipping__c = shps;
oderobj.ChargentOrders__Subtotal__c = prcs;
insert oderobj;
RestRequest req = new RestRequest();
RestResponse res = new RestResponse();
req.requestURI = '/v2/addUpsell/*'; //Request URL
req.httpMethod = 'POST';//HTTP Request Type
RestContext.request = req;
RestContext.response= res;
String strResponse = REST_Upsell_Controller.processUpsell('a0555000000N5BnAAK',30.00,20.55,12.22);
System.assertEquals('added',strResponse);
}
}
try this one...