vadymmarkov / Malibu

:surfer: Malibu is a networking library built on promises

Home Page:https://vadymmarkov.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Testing multi-request flows and MockProvider

codeOfRobin opened this issue · comments

commented

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? 🤔

commented

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.

commented

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