jnbt / candy_check

Check and verify in-app receipts
MIT License
125 stars 71 forks source link

Create test helpers #2

Open splattael opened 9 years ago

splattael commented 9 years ago

It would be nice to streamline testing for candy check so stubbing verification gets easier.

More info to follow.

fourcolors commented 7 years ago

I'd also like this

jnbt commented 7 years ago

Let's discuss the feature-set for this test helper:

fourcolors commented 7 years ago

So thoughts on this.

I think it should be similar to how the Ruby geocoder gem does it. I know this is a Rails example but here is how we implemented stubbing out geolocation request form that gem, its similar concept in that is using a google api service. In this case, we just have two services, apple and google.

module GeocodingHelpers
  def stub_location_lookup(locations)
    locations.each do |query, properties|
      Geocoder::Lookup::Test.add_stub(
        query,
        [properties.with_indifferent_access],
      )
    end
  end

  def stub_unknown_location_lookup(query)
    allow(Geocoder).to receive(:coordinates).with(query).and_return(nil)
  end
end

RSpec.configure do |config|
  config.before(:all) { Geocoder.configure(lookup: :test) }
  config.include GeocodingHelpers
end

For reference, the geolocator test app is here: https://github.com/alexreisner/geocoder_test

We could make some improvements I'm sure but might be worth looking at as a good starting point.

Also, I think if everything is written where dependency injection is requried ie: fetch libs etc, stubbing out a specific instance shouldn't be hard. It would be nice to be able to set up a 'test' mode which returns some stubbed objects of ReceiptStub and VerificationFailureStub

jnbt commented 7 years ago

I think this would be a step in the right direction. In detail the gem should not make assumptions about the test framework, but could be instrumented as in the given example.