infinitered / ProMotion-iap

In-app purchases for ProMotion!
19 stars 7 forks source link

Lacking test and well tested app #3

Open ivanacostarubio opened 9 years ago

ivanacostarubio commented 9 years ago

Hello @jamonholmgren!

When creating Helu I struggled to test the integration points with Apple. In a effort to learn how to test this type of code better, I forked this repo and commented the key pieces of code to make In App Purchases ( https://github.com/ivanacostarubio/ProMotion-iap/commit/43476410008d94da46b0ad7ce3519696b65a3361). After that last commit, the library is not able to make in app purchases, yet none of the tests are red.

What is the proper way to test the integration with apple?

If a library can't make IAP, but all the tests are green is it well tested?

jamonholmgren commented 9 years ago

Hi @ivanacostarubio !

If a library can't make IAP, but all the tests are green is it well tested?

Very true. There are a lot of things that are mocked since we're not able to make real requests to Apple. In the future, I'd like to figure out how to do proper integration tests -- I have some ideas, but @kevinvangelder and I built this in one evening, so I think you've found some holes in our tests. :)

jamonholmgren commented 9 years ago

It would be fun to pair on this, @ivanacostarubio. Let me know if you want to Screenhero some day on it.

ivanacostarubio commented 9 years ago

Hey James!

When I read in your blog post that Helu's tests were lacking and this library was "well tested", I came here to learn how to do it. Now I realized those comments were unfair and propaganda. :smile:

jamonholmgren commented 9 years ago

Hey @ivanacostarubio, I'm sorry I came across that way! I certainly didn't intend to be unfair to Helu or to you. I apologize for that.

Helu was a great inspiration for my work. I seriously considered helping to flesh out the tests and fix the bugs that we found. My reasons for building my own were many, but essentially once I made a list of the things I'd need to update (for API purposes and stability purposes) it was long enough that I thought building my own would help in a couple ways. One, I would understand what was happening better if I built it from scratch (and avoid bugs, hopefully), and two, I could provide a more "ProMotion-like" API for the ProMotion ecosystem.

Again, I apologize for coming across unfair in my blog post. It wasn't my intention at all. I'll consider how I could re-write that portion of the blog post to avoid that connotation.

jamonholmgren commented 9 years ago

I updated this sentence:

But Helu has fallen out of date, contains some difficult to track down bugs, and the tests are lacking. Plus, the API, while simple enough, isn't quite "ProMotion-like".

to

But Helu hasn't been updated in a while and I ran into a difficult to track down bug that I had to work around. Plus, the API, while simple enough, isn't quite "ProMotion-like".

ivanacostarubio commented 9 years ago

You are the man @jamonholmgren :heart_eyes:. Thank you for showing empathy when dealing with me. I got the lack of test comment as a personal thing because I put a lot of time to "try to get it right".

It is totally understandable you want a library with an API you like and enjoy working with.

Getting back to business... when testing the integrations with Apple I created a few mock classes and initialized instance variables at certain points so that I could check if an Apple method was called. Not sure if this was the right approach, but I got red tests when certain things were not called.

I tried using one of the mocking gem for RubyMotion, but could not get it to work properly.

The mock classes are:


class Transaction
  def payment
    self
  end

  def productIdentifier
  end
end

class FakeQueue

  attr_accessor :added_observer, :payment_sent, :restoring

 def self.instance
    Dispatch.once{ @instance ||= new }
    @instance
  end

  def addTransactionObserver(object)
    @added_observer = true
  end

  def addPayment(product)
    @payment_sent = true
  end

  def finishTransaction(transaction)
  end

  def restoreCompletedTransactions
    @restoring = true
  end
end

class SKPaymentQueue
  def self.defaultQueue
    FakeQueue.instance
  end
end

class SKPayment
  def self.paymentWithProductIdentifier(id)
  end
end

class HeluQueue

  class Transaction
    def payment
      HeluQueue::Payment.new
    end
  end

  class Payment
    def productIdentifier
      "ibw"
    end
  end

  def transactions
    [HeluQueue::Transaction.new]
  end
end
jamonholmgren commented 9 years ago

Very cool, I definitely want to explore this. It would be fun to pair on it sometime and see if we could build out the tests on both gems to be what we need them to be. Let's stay in touch on this!