question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add ability to inject stubbed payloads into sampleNotifications

See original GitHub issue

I use the sampleNotifications function in the WebhookTestingGateway https://developers.braintreepayments.com/guides/webhooks/testing-go-live/node, which are great, but I’ve noticed that the subjectXmlForSubscription contains no data, which makes it difficult to test for specific scenarios.

https://github.com/braintree/braintree_node/blob/master/lib/braintree/webhook_testing_gateway.js#L251

What would be excellent, is if there was an option to inject stub payloads into the sampleNotification method. They could either be xml, or even go a step further allow injection of a javascript object, which would then need to be converted into xml.

This would mean a developer could easily set up a suite of unit test for specific scenarios and would be a massive help when integrating.

e.g. instead of

const sampleNotification = gateway.webhookTesting.sampleNotification(
  braintree.WebhookNotification.Kind.SubscriptionWentPastDue,
  "myId"
);

Something like:

const stubbedPayload = {
    kind: 'subscription_created',
    timestamp: '2017-03-14T15:47:33Z',
    subject: {
      subscription: {
        billingPeriodEndDate: '2017-03-21',
        billingPeriodStartDate: '2017-03-14',
        paidThroughDate: '2017-03-21',
        price: '19.99',
        status: 'Trialing',
        trialPeriod: true,
        transactions: [
          {
            currencyIsoCode: 'USD',
            customer: { id: 'my-user-id' }
          }
        ]
      }
    }
};
const sampleNotification = gateway.webhookTesting.sampleNotification(
  braintree.WebhookNotification.Kind.SubscriptionWentActive,
  stubbedPayload
);

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jthegeduscommented, Sep 4, 2017

I initially implemented it that way, but quickly found that using the Braintree production webhook responses would throw errors because of the attributes after the <subject> element. EG:

{
   timestamp:dateFormat(new Date(), dateFormat.masks.isoUtcDateTime, true),
   kind:WebhookNotification.Kind.SubscriptionChargedSuccessfully,
   subject:{
      subscription:{
         id:'mySubscription',
         transactions:[
            {
               status:'submitted_for_settlement',
               amount:'49.99'
            }
         ],
         addOns:[ ],
         discounts:[ ]
      }
   },
   subscription:{
      id:'mySubscription',
      transactions:[
         {
            status:'submitted_for_settlement',
            amount:'49.99',
            creditCard:{
               maskedNumber:'undefined******undefined',
               expirationDate:'undefined/undefined'
            },
            paypalAccount:{ },
            coinbaseAccount:{ },
            applePayCard:{ },
            androidPayCard:{ },
            disbursementDetails:{ },
            visaCheckoutCard:{ },
            masterpassCard:{ }
         }
      ],
      addOns:[ ],
      discounts:[ ]
   }
};

The accounts information is separated into this second part and it’s not clear without running the webhooks what the true response format will be (as the testing ones are not complete).

Feedback from the Braintree team will help clarify what’s necessary and maybe it’ll change back to the split method. Time will tell.

0reactions
crookedneighborcommented, Jan 8, 2018

We’re not going to add this feature at this time. (See https://github.com/braintree/braintree_node/pull/111#issuecomment-356122013)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inject Stub Collaborators In Globally Stubbed Class Using ...
I am calling render but specifying a template (not a controller or view), so it is directly rendering the GSP. Even if it...
Read more >
Stubbing and Mocking in Java with the Spock Testing ...
Learn how to create true Java unit tests by mocking all external dependencies in your unit tests with the Spock testing framework.
Read more >
Returning stubbed HTTP responses to specific requests
A core feature of WireMock is the ability to return canned HTTP responses for requests matching criteria. These are described in detail in...
Read more >
9 Testing RIB
The stubbed implementation has been written to insert the payload to a database once inject has been called. Injectors.xml has been configured to...
Read more >
Use Mocks and Stub Objects Unit | Salesforce Trailhead
In this unit, we create and use an HttpMock and a custom stub object. ... This ability to inject the return value into...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found