api-in-app-purchase-spec.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict'
  2. const assert = require('assert')
  3. const {remote} = require('electron')
  4. describe('inAppPurchase module', function () {
  5. if (process.platform !== 'darwin') return
  6. this.timeout(3 * 60 * 1000)
  7. const {inAppPurchase} = remote
  8. it('canMakePayments() does not throw', () => {
  9. inAppPurchase.canMakePayments()
  10. })
  11. it('finishAllTransactions() does not throw', () => {
  12. inAppPurchase.finishAllTransactions()
  13. })
  14. it('finishTransactionByDate() does not throw', () => {
  15. inAppPurchase.finishTransactionByDate(new Date().toISOString())
  16. })
  17. it('getReceiptURL() returns receipt URL', () => {
  18. assert.ok(inAppPurchase.getReceiptURL().endsWith('_MASReceipt/receipt'))
  19. })
  20. it('purchaseProduct() fails when buying invalid product', (done) => {
  21. inAppPurchase.purchaseProduct('non-exist', 1, (success) => {
  22. assert.ok(!success)
  23. done()
  24. })
  25. })
  26. it('purchaseProduct() accepts optional arguments', (done) => {
  27. inAppPurchase.purchaseProduct('non-exist', () => {
  28. inAppPurchase.purchaseProduct('non-exist', 1)
  29. done()
  30. })
  31. })
  32. it('getProducts() returns an empty list when getting invalid product', (done) => {
  33. inAppPurchase.getProducts(['non-exist'], (products) => {
  34. assert.ok(products.length === 0)
  35. done()
  36. })
  37. })
  38. })