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

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