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)
|
|
|
|
|
2018-01-10 06:21:53 +00:00
|
|
|
it('canMakePayments() does not throw', () => {
|
2018-06-18 16:50:37 +00:00
|
|
|
expect(() => {
|
|
|
|
inAppPurchase.canMakePayments()
|
|
|
|
}).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
|
|
|
|
// Apple started blocking requests from AWS IPs (we think), so they fail on
|
|
|
|
// CI.
|
|
|
|
// TODO: find a way to mock out the server requests so we can test these APIs
|
|
|
|
// without relying on a remote service.
|
|
|
|
xit('purchaseProduct() fails when buying invalid product', async () => {
|
2019-03-13 20:56:01 +00:00
|
|
|
const success = await inAppPurchase.purchaseProduct('non-exist', 1)
|
2019-07-15 08:28:55 +00:00
|
|
|
expect(success).to.be.false('failed to purchase non-existent product')
|
2019-03-13 20:56:01 +00:00
|
|
|
})
|
|
|
|
|
2019-07-03 22:41:37 +00:00
|
|
|
xit('purchaseProduct() accepts optional arguments', async () => {
|
2019-03-13 20:56:01 +00:00
|
|
|
const success = await inAppPurchase.purchaseProduct('non-exist')
|
2019-07-15 08:28:55 +00:00
|
|
|
expect(success).to.be.false('failed to purchase non-existent product')
|
2019-03-13 20:56:01 +00:00
|
|
|
})
|
|
|
|
|
2019-07-03 22:41:37 +00:00
|
|
|
xit('getProducts() returns an empty list when getting invalid product', async () => {
|
2019-03-13 20:56:01 +00:00
|
|
|
const products = await inAppPurchase.getProducts(['non-exist'])
|
|
|
|
expect(products).to.be.an('array').of.length(0)
|
|
|
|
})
|
2018-01-10 06:21:53 +00:00
|
|
|
})
|