api-in-app-purchase-spec.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { expect } from 'chai'
  2. import { inAppPurchase } from 'electron'
  3. describe('inAppPurchase module', function () {
  4. if (process.platform !== 'darwin') return
  5. this.timeout(3 * 60 * 1000)
  6. it('canMakePayments() does not throw', () => {
  7. expect(() => {
  8. inAppPurchase.canMakePayments()
  9. }).to.not.throw()
  10. })
  11. it('finishAllTransactions() does not throw', () => {
  12. expect(() => {
  13. inAppPurchase.finishAllTransactions()
  14. }).to.not.throw()
  15. })
  16. it('finishTransactionByDate() does not throw', () => {
  17. expect(() => {
  18. inAppPurchase.finishTransactionByDate(new Date().toISOString())
  19. }).to.not.throw()
  20. })
  21. it('getReceiptURL() returns receipt URL', () => {
  22. expect(inAppPurchase.getReceiptURL()).to.match(/_MASReceipt\/receipt$/)
  23. })
  24. // The following three tests are disabled because they hit Apple servers, and
  25. // Apple started blocking requests from AWS IPs (we think), so they fail on
  26. // CI.
  27. // TODO: find a way to mock out the server requests so we can test these APIs
  28. // without relying on a remote service.
  29. xit('purchaseProduct() fails when buying invalid product', async () => {
  30. const success = await inAppPurchase.purchaseProduct('non-exist', 1)
  31. expect(success).to.be.false('failed to purchase non-existent product')
  32. })
  33. xit('purchaseProduct() accepts optional arguments', async () => {
  34. const success = await inAppPurchase.purchaseProduct('non-exist')
  35. expect(success).to.be.false('failed to purchase non-existent product')
  36. })
  37. xit('getProducts() returns an empty list when getting invalid product', async () => {
  38. const products = await inAppPurchase.getProducts(['non-exist'])
  39. expect(products).to.be.an('array').of.length(0)
  40. })
  41. })