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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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', async () => {
  31. const success = await inAppPurchase.purchaseProduct('non-exist', 1)
  32. expect(success).to.be.false()
  33. })
  34. // TODO(codebytere): remove when promisification is complete
  35. it('purchaseProduct() fails when buying invalid product (callback)', done => {
  36. inAppPurchase.purchaseProduct('non-exist', 1, success => {
  37. expect(success).to.be.false()
  38. done()
  39. })
  40. })
  41. it('purchaseProduct() accepts optional arguments', async () => {
  42. const success = await inAppPurchase.purchaseProduct('non-exist')
  43. expect(success).to.be.false()
  44. })
  45. // TODO(codebytere): remove when promisification is complete
  46. it('purchaseProduct() accepts optional arguments (callback)', done => {
  47. inAppPurchase.purchaseProduct('non-exist', success => {
  48. expect(success).to.be.false()
  49. done()
  50. })
  51. })
  52. it('getProducts() returns an empty list when getting invalid product', async () => {
  53. const products = await inAppPurchase.getProducts(['non-exist'])
  54. expect(products).to.be.an('array').of.length(0)
  55. })
  56. // TODO(codebytere): remove when promisification is complete
  57. it('getProducts() returns an empty list when getting invalid product (callback)', done => {
  58. inAppPurchase.getProducts(['non-exist'], products => {
  59. expect(products).to.be.an('array').of.length(0)
  60. done()
  61. })
  62. })
  63. })