forcedotcom / b2b-commerce-on-lightning-quickstart

Creative Commons Zero v1.0 Universal
175 stars 207 forks source link

Please provide Test Class for the StripeAdapter.cls Class #48

Open afzal-tag opened 3 years ago

afzal-tag commented 3 years ago

Thanks a lot for sharing the StripeAdapter.cls in here https://github.com/forcedotcom/b2b-commerce-on-lightning-quickstart/tree/master/examples/checkout/payment-gateway-integration/Stripe/classes

StripeAdapter Class is a good starting point. However, its incomplete without the test class. It would be useful for the Apex unit tests to be included. We are currently stuck without the test class. And am sure there are other people facing the same problem.

Please get the Test Class included.

Thanks

github-actions[bot] commented 3 years ago

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

Gulshan-Doorgah commented 2 years ago

@afzal-tag did you manage to do the test class? Can you share please?

Gulshan-Doorgah commented 2 years ago

@IsTest private class B2B_StripeAdapter_TEST { @isTest static void testCreateAuthResponse() { Test.setMock(HttpCalloutMock.class, new B2B_StripeAdapter_MOCK());

    B2B_StripeAdapter adapter = new B2B_StripeAdapter();
    commercepayments.AuthorizationRequest authRequest = new commercepayments.AuthorizationRequest(100);
    authRequest.currencyIsoCode = 'EUR';
    authRequest.additionalData = new Map <String, String>{
        'token' => 'testToken'
    };
    commercepayments.paymentGatewayContext gatewayContext = new commercepayments.paymentGatewayContext(authRequest, commercepayments.RequestType.Authorize);

    commercepayments.GatewayResponse response = adapter.processRequest(gatewayContext);
}

@isTest static void testCreateTokenizeResponse() {
    Test.setMock(HttpCalloutMock.class, new B2B_StripeAdapter_MOCK());

    Test.startTest();
    B2B_StripeAdapter adapter = new B2B_StripeAdapter();
    commercepayments.PaymentMethodTokenizationRequest paymentRequest = new commercepayments.PaymentMethodTokenizationRequest('paymentGatewayId');
    commercepayments.CardPaymentMethodRequest cardPaymentMethodRequest = new commercepayments.CardPaymentMethodRequest(commercepayments.CardCategory.CreditCard);
    paymentRequest.address = new commercepayments.AddressRequest('street', 'city', 'state', 'country', 'postalCode');
    paymentRequest.cardPaymentMethod = cardPaymentMethodRequest;
    paymentRequest.cardPaymentMethod.cardHolderName = 'TEST CARDHOLDER NAME';
    commercepayments.paymentGatewayContext gatewayContext = new commercepayments.paymentGatewayContext(paymentRequest, commercepayments.RequestType.Tokenize);

    commercepayments.GatewayResponse response = adapter.processRequest(gatewayContext);
    Test.stopTest();
}

// coverage for B2B_StripeValidationException
@isTest static void testToStripeCurrencyUnitsException() {
    try{
        B2B_StripeAdapter.toStripeCurrencyUnits('test', 100);
    }catch(Exception e){

    }
}

}

Gulshan-Doorgah commented 2 years ago

@isTest global class B2B_StripeAdapter_MOCK implements HttpCalloutMock{ global HTTPResponse respond(HTTPRequest req) { System.debug(req.getEndpoint()); // Create a fake response HttpResponse res = new HttpResponse(); res.setHeader('Content-Type', 'application/json'); if(req.getEndpoint().contains('charges')){ res.setBody('{"amount": 10000}'); }else if(req.getEndpoint().contains('tokens')){ res.setBody('{"id": "token"}'); }

    res.setStatusCode(200);
    return res;
}

}