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

Testing multi-request flows and MockProvider #114

Open
codeOfRobin opened this issue Feb 9, 2019 · 2 comments
Open

Testing multi-request flows and MockProvider #114

codeOfRobin opened this issue Feb 9, 2019 · 2 comments

Comments

@codeOfRobin
Copy link

codeOfRobin commented Feb 9, 2019

Hi!

I'm trying to test a flow where access tokens are refreshed(similar to #42 ), and I'm using a MockProvider instead of making actual network requests (imagine making a MockProvider where if a request is made with the old token, it'll return a "failed" json and if the request is made with a new token, you get the "success" json). However, since the request in the MockProvider closure doesn't contain any information about the middleware, authentication etc, I can't check what token the request is made with.

Any suggestions on how I can write a test for this? 🤔

@codeOfRobin
Copy link
Author

I have a few (late night thoughts) on how this could be fixed.

We could replace the MockProvider<> in the init with an enum:

enum ResponseOverride<T> {
  case mockProvider(MockProvider<T>)
  case urlSession(URLSession)
}

and pass an instance of ResponseOverride in the init.

Another approach we could take here is turn toURLRequest to a Promise<URLRequest> and actually ensure that the middleware, preProcessRequest etc are called in the right order.

These are my 2 ideas for now. Totally open to suggestions/better ways to solve this problem.

@codeOfRobin
Copy link
Author

Made a simple change that solves this problem for now: #115

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

1 participant