Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
afzal-tag opened this issue Sep 29, 2021 · 4 comments
Open

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

afzal-tag opened this issue Sep 29, 2021 · 4 comments

Comments

@afzal-tag
Copy link

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
Copy link

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
Copy link

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

@Gulshan-Doorgah
Copy link

Gulshan-Doorgah commented Nov 30, 2021

@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
Copy link

Gulshan-Doorgah commented Nov 30, 2021

@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;
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants