[react-sdk][react-native-sdk (expo)] recommendation for integration testing mocks

Hey folks. I'm wondering if you Kinde team provides any recommendation on how to setup a mock KindeProvider for React SDK or for React Native SDK? I don't really know the implementation details and I'm wondering what's the best way to go about this endeavor. For example, on one of my personal projects were the Authorization is made in-house, I use MSW to intercept login/logout requests and return responses that the HTTP Clients can handle just as if they would real HTTP requests. Which thus leads for the application to be in auth or anonymous modes. This works well for me and gives high level of confidence on some more complex integration tests, but is only possible because I know all the details. Using Kinde SDK on the other hand makes this a bit more complex as I don't know all the endpoints that can be called by the SDK and the exact shape of all responses. I wonder if using a simple provider that exposes a bunch of jest.fn() functions would be the best option for me. The downside here is that performing a successful login won't actually reflect on the test state, making integration tests a bit shallow. We could argue I could test login via E2E using playwright (react) and detox (react-native) instead. Leaving integration tests only for "fully" authenticated or not authenticated at all tests. Do you have an existing example of your own mock providers?
4 Replies
onderay
onderay5mo ago
Thanks for providing the details about how you are blocked; I am going to get one of the team who is very familiar with those SDKs to jump in. Are both of your questions related to you setting up end to end testing?
Francisco "Klogan" Barros
Hey Hey, not really. Integration tests for jest; In the mean time I came to the conclusion that I might as well just mock the return type of useKindeAuth hook on React on certain unit and integration tests; That should be the easiest for me. However, would still appreciate an insider opinion. For E2E tests I'm using playwright for the web application and debox for the mobile application, so, I'm basically testing against real live browser/device applications and won't be using any mocked data. I will have a test user in Kinde for this purpose. The thing is, playwright and detox tests take time, so I won't be covering "all" cases in E2E.
Daniel_Kinde
Daniel_Kinde5mo ago
Hi @Francisco "Klogan" Barros What exactly are you wanting to test? I would say it really depends on which methods you're wanting to test from the KindeSDK. Really I would suggest mocking the SDK and handing the various roles, permissions and feature flags combinations coming back from the helped methods of the SDK, but this really depends on what you're testing. There should be little need to hit Kinde during your tests as this could limit your testing range, its much better to mock the outputs and check that your application is handling them accordingly. Keen to hear you thoughts on what we could do here to help, would providing a toolset which mocks responses from our KindeSDK help i.e. MockPermissionGranted('somePermission') or MockPermissionDenied('somePermission')
Francisco "Klogan" Barros
Hey a toolset would be amazing, but a toolset would probably not be in your best interest on the long run because of the maintainability overhead (unless you already have such toolset being used internally, in which case it would be great for you share such utilities). However with so many languages plus testing tools within them it could grow complex real fast. Certainly such toolset would not be a do once and forget. It probably require ongoing updates. An alternative, would be to write up some documentation on how you would mock authentication and authorization, on a handful of your most used SDKs. Dunno, if React is one of them, but I can assume so. Example documentation section Testing your { React, React Native, Vue, Angular } UI user access with Kinde.
Want results from more Discord servers?
Add your server