Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kieckhafer
Copy link
Member

Resolves #5653
Impact: minor
Type: feature|refactor

Issue

getPaymentMethodConfigByName was used across many plugins

Solution

For the sake of keeping our plugins contained, we are adding this method, getPaymentMethodConfigByName to the context to use instead of importing from the payments package directly.

Breaking changes

Any custom code which uses getPaymentMethodConfigByName by direct import will need to update to use the context.queries.getPaymentMethodConfigByName instead

Testing

  1. Start the app
  2. See you can create an order

@kieckhafer kieckhafer requested a review from aldeed October 4, 2019 22:01
@kieckhafer
Copy link
Member Author

@aldeed Is there a way to do rewire with mockContext? I need to update the tests.

Signed-off-by: Erik Kieckhafer <[email protected]>
Copy link
Contributor

@aldeed aldeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kieckhafer Instead of using rewire you'd just mock the function on context now. Something like

mockContext.queries.getPaymentMethodConfigByName = jest.fn().mockName("getPaymentMethodConfigByName").mockImplementation(() => ({
    functions: {
      listRefunds: async () => [{
        _id: "refundId",
        type: "refund",
        amount: 19.99,
        currency: "usd"
      }]
    }
  }));

One other comment, too.

@@ -0,0 +1,14 @@
const paymentMethods = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be import { paymentMethods } from "../registration.js"; because the function that sets them into this list is in that file.

@kieckhafer
Copy link
Member Author

@aldeed updated to use the mockContext in tests now, ready for another look.

@aldeed aldeed merged commit d631656 into develop Oct 7, 2019
@aldeed aldeed deleted the refactor-kieckhafer-move-getPaymentMethodConfigByName-to-context branch October 7, 2019 20:50
@willopez willopez mentioned this pull request Oct 9, 2019
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

Successfully merging this pull request may close these issues.

3 participants