2019-07-15 08:28:55 +00:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import { inAppPurchase } from 'electron'
|
2018-01-10 06:21:53 +00:00
|
|
|
|
2018-03-22 13:47:29 +00:00
|
|
|
describe('inAppPurchase module', function () {
|
2018-01-10 06:21:53 +00:00
|
|
|
if (process.platform !== 'darwin') return
|
|
|
|
|
2018-03-22 13:47:29 +00:00
|
|
|
this.timeout(3 * 60 * 1000)
|
|
|
|
|
2019-12-17 15:07:11 +00:00
|
|
|
it('canMakePayments() returns a boolean', () => {
|
|
|
|
const canMakePayments = inAppPurchase.canMakePayments()
|
|
|
|
expect(canMakePayments).to.be.a('boolean')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('restoreCompletedTransactions() does not throw', () => {
|
2018-06-18 16:50:37 +00:00
|
|
|
expect(() => {
|
2019-12-17 15:07:11 +00:00
|
|
|
inAppPurchase.restoreCompletedTransactions()
|
2018-06-18 16:50:37 +00:00
|
|
|
}).to.not.throw()
|
2018-01-10 06:21:53 +00:00
|
|
|
})
|
|
|
|
|
2018-04-05 06:33:13 +00:00
|
|
|
it('finishAllTransactions() does not throw', () => {
|
2018-06-18 16:50:37 +00:00
|
|
|
expect(() => {
|
|
|
|
inAppPurchase.finishAllTransactions()
|
|
|
|
}).to.not.throw()
|
2018-04-05 06:33:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('finishTransactionByDate() does not throw', () => {
|
2018-06-18 16:50:37 +00:00
|
|
|
expect(() => {
|
|
|
|
inAppPurchase.finishTransactionByDate(new Date().toISOString())
|
|
|
|
}).to.not.throw()
|
2018-04-05 06:33:13 +00:00
|
|
|
})
|
|
|
|
|
2018-01-10 06:21:53 +00:00
|
|
|
it('getReceiptURL() returns receipt URL', () => {
|
2019-07-15 08:28:55 +00:00
|
|
|
expect(inAppPurchase.getReceiptURL()).to.match(/_MASReceipt\/receipt$/)
|
2018-01-10 06:21:53 +00:00
|
|
|
})
|
|
|
|
|
2019-07-03 22:41:37 +00:00
|
|
|
// The following three tests are disabled because they hit Apple servers, and
|
2019-12-17 15:07:11 +00:00
|
|
|
// Apple started blocking requests from AWS IPs (we think), so they fail on CI.
|
2019-07-03 22:41:37 +00:00
|
|
|
// TODO: find a way to mock out the server requests so we can test these APIs
|
|
|
|
// without relying on a remote service.
|
2019-12-17 15:07:11 +00:00
|
|
|
xdescribe('handles product purchases', () => {
|
|
|
|
it('purchaseProduct() fails when buying invalid product', async () => {
|
|
|
|
const success = await inAppPurchase.purchaseProduct('non-exist', 1)
|
|
|
|
expect(success).to.be.false('failed to purchase non-existent product')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('purchaseProduct() accepts optional arguments', async () => {
|
|
|
|
const success = await inAppPurchase.purchaseProduct('non-exist')
|
|
|
|
expect(success).to.be.false('failed to purchase non-existent product')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('getProducts() returns an empty list when getting invalid product', async () => {
|
|
|
|
const products = await inAppPurchase.getProducts(['non-exist'])
|
|
|
|
expect(products).to.be.an('array').of.length(0)
|
|
|
|
})
|
2019-03-13 20:56:01 +00:00
|
|
|
})
|
2018-01-10 06:21:53 +00:00
|
|
|
})
|