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

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