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

Unit tests and mocking #10

Open
simonmcl opened this issue Jul 12, 2021 · 4 comments
Open

Unit tests and mocking #10

simonmcl opened this issue Jul 12, 2021 · 4 comments
Assignees

Comments

@simonmcl
Copy link

Theres no way to pass in a URLSession into any of the Torus functions. This is how most libraries expose the ability to mock URL requests so that code can be unit tested.

Is there any other method available to mock requests that i've missed?

If not, please update the library to allow me to pass in my own URLSession so I can create my own mocks

@simonmcl
Copy link
Author

@rathishubham7

@metallicalfa2 metallicalfa2 self-assigned this Jul 15, 2021
@metallicalfa2
Copy link
Contributor

The initializer accepts a AbstractFactory, you can use this to mock the SDK APIs on the functional level. Please checkout from the master.

@simonmcl
Copy link
Author

@rathishubham7 it would be much easier for people not familiar with the code to just be able to pass in a URLSession instance. Making it so that one of your classes can be passed in, means anyone using it needs to understand the code, subclass it, spend time reading it, learn what all the functions do and how they are used, possibly battle with some critical things being private, have to keep updating it whenever anything changes

Passing in a URLSession means that I can simply make a dictionary of:

[
    URL(string: "<torusURL>"): "stub-filename.json"
]

And have a mock instance simply check for the URL and load the corresponding file if it matches.

e.g.

This allows me to mock 100% of requests being used by my library, no matter where they come from, with a single file, without having to create tonnes of mock instance classes

@simonmcl
Copy link
Author

@rathishubham7 also I needed to make all these properties public so that I could access them later inside the app, can you make that change to the main repo too: https://github.com/simonmcl/torus-direct-swift-sdk/blob/a6c7f8e4628b43f1c363c797b9ed5c07a575234c/Sources/TorusSwiftDirectSDK/Models/SubVerifierDetails.swift#L19

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