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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { expect } from 'chai';
  2. import { inAppPurchase } from 'electron/main';
  3. import { ifdescribe } from './lib/spec-helpers';
  4. describe('inAppPurchase module', function () {
  5. if (process.platform !== 'darwin') return;
  6. this.timeout(3 * 60 * 1000);
  7. it('canMakePayments() returns a boolean', () => {
  8. const canMakePayments = inAppPurchase.canMakePayments();
  9. expect(canMakePayments).to.be.a('boolean');
  10. });
  11. it('restoreCompletedTransactions() does not throw', () => {
  12. expect(() => {
  13. inAppPurchase.restoreCompletedTransactions();
  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. expect(inAppPurchase.getReceiptURL()).to.match(/_MASReceipt\/receipt$/);
  28. });
  29. // This fails on x64 in CI - likely owing to some weirdness with the machines.
  30. // We should look into fixing it there but at least run it on arm6 machines.
  31. ifdescribe(process.arch !== 'x64')('handles product purchases', () => {
  32. it('purchaseProduct() fails when buying invalid product', async () => {
  33. const success = await inAppPurchase.purchaseProduct('non-exist');
  34. expect(success).to.be.false('failed to purchase non-existent product');
  35. });
  36. it('purchaseProduct() accepts optional (Integer) argument', async () => {
  37. const success = await inAppPurchase.purchaseProduct('non-exist', 1);
  38. expect(success).to.be.false('failed to purchase non-existent product');
  39. });
  40. it('purchaseProduct() accepts optional (Object) argument', async () => {
  41. const success = await inAppPurchase.purchaseProduct('non-exist', { quantity: 1, username: 'username' });
  42. expect(success).to.be.false('failed to purchase non-existent product');
  43. });
  44. it('getProducts() returns an empty list when getting invalid product', async () => {
  45. const products = await inAppPurchase.getProducts(['non-exist']);
  46. expect(products).to.be.an('array').of.length(0);
  47. });
  48. });
  49. });